Java Code Examples for org.eclipse.lsp4j.TextDocumentItem#setLanguageId()

The following examples show how to use org.eclipse.lsp4j.TextDocumentItem#setLanguageId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DocumentContentSynchronizer.java    From intellij-quarkus with Eclipse Public License 2.0 5 votes vote down vote up
public DocumentContentSynchronizer(@Nonnull LanguageServerWrapper languageServerWrapper,
                                   @Nonnull Document document,
                                   TextDocumentSyncKind syncKind) {
    this.languageServerWrapper = languageServerWrapper;
    this.fileUri = LSPIJUtils.toUri(document);
    this.modificationStamp = new File(fileUri).lastModified();
    this.syncKind = syncKind != null ? syncKind : TextDocumentSyncKind.Full;

    this.document = document;
    // add a document buffer
    TextDocumentItem textDocument = new TextDocumentItem();
    textDocument.setUri(fileUri.toString());
    textDocument.setText(document.getText());

    List<FileType> contentTypes = LSPIJUtils.getDocumentContentTypes(this.document);

    String languageId = languageServerWrapper.getLanguageId(contentTypes.toArray(new FileType[0]));

    //TODO: determine languageId more precisely
    /*IPath fromPortableString = Path.fromPortableString(this.fileUri.getPath());
    if (languageId == null) {
        languageId = fromPortableString.getFileExtension();
        if (languageId == null) {
            languageId = fromPortableString.lastSegment();
        }
    }*/

    textDocument.setLanguageId(languageId);
    textDocument.setVersion(++version);
    didOpenFuture = languageServerWrapper.getInitializedServer()
            .thenAcceptAsync(ls -> ls.getTextDocumentService().didOpen(new DidOpenTextDocumentParams(textDocument)));
}
 
Example 2
Source File: AbstractIdeTest.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/** Opens the given file in the LSP server and waits for the triggered build to finish. */
protected void openFile(FileURI fileURI) {
	if (isOpen(fileURI)) {
		Assert.fail("trying to open a file that is already open: " + fileURI);
	}

	Path filePath = fileURI.toJavaIoFile().toPath();
	String content;
	try {
		content = Files.readString(filePath);
	} catch (IOException e) {
		throw new AssertionError("exception while reading file contents from disk", e);
	}

	TextDocumentItem textDocument = new TextDocumentItem();
	textDocument.setLanguageId(languageInfo.getLanguageName());
	textDocument.setUri(fileURI.toString());
	textDocument.setVersion(1);
	textDocument.setText(toUnixLineSeparator(content));

	DidOpenTextDocumentParams dotdp = new DidOpenTextDocumentParams();
	dotdp.setTextDocument(textDocument);

	languageServer.didOpen(dotdp);
	openFiles.put(fileURI, new OpenFileInfo(content));

	joinServerRequests();
}
 
Example 3
Source File: SyntaxServerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private TextDocumentItem getTextDocument(String uri, String content) {
	TextDocumentItem textDocument = new TextDocumentItem();
	textDocument.setLanguageId("java");
	textDocument.setText(content);
	textDocument.setUri(uri);
	textDocument.setVersion(1);
	return textDocument;
}
 
Example 4
Source File: DiagnosticsCommandTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private void openDocument(ICompilationUnit cu, String content, int version) {
	DidOpenTextDocumentParams openParms = new DidOpenTextDocumentParams();
	TextDocumentItem textDocument = new TextDocumentItem();
	textDocument.setLanguageId("java");
	textDocument.setText(content);
	textDocument.setUri(JDTUtils.toURI(cu));
	textDocument.setVersion(version);
	openParms.setTextDocument(textDocument);
	lifeCycleHandler.didOpen(openParms);
}
 
Example 5
Source File: MavenClasspathTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private void openDocument(ICompilationUnit cu, String content, int version) {
	DidOpenTextDocumentParams openParms = new DidOpenTextDocumentParams();
	TextDocumentItem textDocument = new TextDocumentItem();
	textDocument.setLanguageId("java");
	textDocument.setText(content);
	textDocument.setUri(JDTUtils.toURI(cu));
	textDocument.setVersion(version);
	openParms.setTextDocument(textDocument);
	lifeCycleHandler.didOpen(openParms);
}
 
Example 6
Source File: SemanticHighlightingTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
protected void openDocument(ICompilationUnit unit, String content, int version) {
	DidOpenTextDocumentParams openParms = new DidOpenTextDocumentParams();
	TextDocumentItem textDocument = new TextDocumentItem();
	textDocument.setLanguageId("java");
	textDocument.setText(content);
	textDocument.setUri(JDTUtils.toURI(unit));
	textDocument.setVersion(version);
	openParms.setTextDocument(textDocument);
	lifeCycleHandler.didOpen(openParms);
}
 
Example 7
Source File: DocumentLifeCycleHandlerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private void openDocument(String uri, String content, int version) {
	DidOpenTextDocumentParams openParms = new DidOpenTextDocumentParams();
	TextDocumentItem textDocument = new TextDocumentItem();
	textDocument.setLanguageId("java");
	textDocument.setText(content);
	textDocument.setUri(uri);
	textDocument.setVersion(version);
	openParms.setTextDocument(textDocument);
	lifeCycleHandler.didOpen(openParms);
}
 
Example 8
Source File: WorkspaceEventHandlerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private void openDocument(String uri, String content, int version) {
	DidOpenTextDocumentParams openParms = new DidOpenTextDocumentParams();
	TextDocumentItem textDocument = new TextDocumentItem();
	textDocument.setLanguageId("java");
	textDocument.setText(content);
	textDocument.setUri(uri);
	textDocument.setVersion(version);
	openParms.setTextDocument(textDocument);
	lifeCycleHandler.didOpen(openParms);
}