Java Code Examples for org.eclipse.lsp4j.DidOpenTextDocumentParams#setTextDocument()

The following examples show how to use org.eclipse.lsp4j.DidOpenTextDocumentParams#setTextDocument() . 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: FileContentsTrackerTests.java    From groovy-language-server with Apache License 2.0 5 votes vote down vote up
@Test
void testDidOpen() {
	DidOpenTextDocumentParams params = new DidOpenTextDocumentParams();
	params.setTextDocument(new TextDocumentItem("file.txt", "plaintext", 1, "hello world"));
	tracker.didOpen(params);
	Assertions.assertEquals("hello world", tracker.getContents(URI.create("file.txt")));
}
 
Example 2
Source File: FileContentsTrackerTests.java    From groovy-language-server with Apache License 2.0 5 votes vote down vote up
@Test
void testDidChangeWithoutRange() {
	DidOpenTextDocumentParams openParams = new DidOpenTextDocumentParams();
	openParams.setTextDocument(new TextDocumentItem("file.txt", "plaintext", 1, "hello world"));
	tracker.didOpen(openParams);
	DidChangeTextDocumentParams changeParams = new DidChangeTextDocumentParams();
	changeParams.setTextDocument(new VersionedTextDocumentIdentifier("file.txt", 2));
	TextDocumentContentChangeEvent changeEvent = new TextDocumentContentChangeEvent();
	changeEvent.setText("hi there");
	changeParams.setContentChanges(Collections.singletonList(changeEvent));
	tracker.didChange(changeParams);
	Assertions.assertEquals("hi there", tracker.getContents(URI.create("file.txt")));
}
 
Example 3
Source File: FileContentsTrackerTests.java    From groovy-language-server with Apache License 2.0 5 votes vote down vote up
@Test
void testDidChangeWithRange() {
	DidOpenTextDocumentParams openParams = new DidOpenTextDocumentParams();
	openParams.setTextDocument(new TextDocumentItem("file.txt", "plaintext", 1, "hello world"));
	tracker.didOpen(openParams);
	DidChangeTextDocumentParams changeParams = new DidChangeTextDocumentParams();
	changeParams.setTextDocument(new VersionedTextDocumentIdentifier("file.txt", 2));
	TextDocumentContentChangeEvent changeEvent = new TextDocumentContentChangeEvent();
	changeEvent.setText(", friend");
	changeEvent.setRange(new Range(new Position(0, 5), new Position(0, 11)));
	changeEvent.setRangeLength(6);
	changeParams.setContentChanges(Collections.singletonList(changeEvent));
	tracker.didChange(changeParams);
	Assertions.assertEquals("hello, friend", tracker.getContents(URI.create("file.txt")));
}
 
Example 4
Source File: FileContentsTrackerTests.java    From groovy-language-server with Apache License 2.0 5 votes vote down vote up
@Test
void testDidChangeWithRangeMultiline() {
	DidOpenTextDocumentParams openParams = new DidOpenTextDocumentParams();
	openParams.setTextDocument(new TextDocumentItem("file.txt", "plaintext", 1, "hello\nworld"));
	tracker.didOpen(openParams);
	DidChangeTextDocumentParams changeParams = new DidChangeTextDocumentParams();
	changeParams.setTextDocument(new VersionedTextDocumentIdentifier("file.txt", 2));
	TextDocumentContentChangeEvent changeEvent = new TextDocumentContentChangeEvent();
	changeEvent.setText("affles");
	changeEvent.setRange(new Range(new Position(1, 1), new Position(1, 5)));
	changeEvent.setRangeLength(4);
	changeParams.setContentChanges(Collections.singletonList(changeEvent));
	tracker.didChange(changeParams);
	Assertions.assertEquals("hello\nwaffles", tracker.getContents(URI.create("file.txt")));
}
 
Example 5
Source File: RdfLintLanguageServerTest.java    From rdflint with MIT License 5 votes vote down vote up
@Test
public void diagnosticsOpen() throws Exception {
  RdfLintLanguageServer lsp = new RdfLintLanguageServer();
  InitializeParams initParams = new InitializeParams();
  String rootPath = this.getClass().getClassLoader().getResource("testValidatorsImpl/").getPath();
  String parentPath = rootPath + "TrimValidator/turtle_needtrim";
  initParams.setRootUri(RdfLintLanguageServer.convertFilePath2Uri(parentPath));
  lsp.initialize(initParams);

  LanguageClient client = mock(LanguageClient.class);
  lsp.connect(client);

  DidOpenTextDocumentParams openParams = new DidOpenTextDocumentParams();
  openParams.setTextDocument(new TextDocumentItem());
  openParams.getTextDocument()
      .setUri(RdfLintLanguageServer.convertFilePath2Uri(parentPath + "/needtrim.rdf"));
  openParams.getTextDocument().setText("<rdf:RDF\n"
      + "    xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n"
      + "    xmlns:schema=\"http://schema.org/\"\n"
      + "    >\n"
      + "\n"
      + "  <rdf:Description rdf:about=\"something\">\n"
      + "    <schema:familyName xml:lang=\"ja\">familyName </schema:familyName>\n"
      + "  </rdf:Description>\n"
      + "\n"
      + "</rdf:RDF>");
  lsp.didOpen(openParams);

  verify(client, times(1)).publishDiagnostics(any());
}
 
Example 6
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 7
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 8
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 9
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 10
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 11
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);
}