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

The following examples show how to use org.eclipse.lsp4j.DidChangeTextDocumentParams#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: CamelTextDocumentServiceTest.java    From camel-language-server with Apache License 2.0 6 votes vote down vote up
@Test
void testChangeEventUpdatesStoredText() throws Exception {
	CamelLanguageServer camelLanguageServer = initializeLanguageServer("<to uri=\"\" xmlns=\"http://camel.apache.org/schema/blueprint\"></to>\n");
	
	DidChangeTextDocumentParams changeEvent = new DidChangeTextDocumentParams();
	VersionedTextDocumentIdentifier textDocument = new VersionedTextDocumentIdentifier();
	textDocument.setUri(DUMMY_URI+".xml");
	changeEvent.setTextDocument(textDocument);
	TextDocumentContentChangeEvent contentChange = new TextDocumentContentChangeEvent("<to xmlns=\"http://camel.apache.org/schema/blueprint\" uri=\"\"></to>\n");
	changeEvent.setContentChanges(Collections.singletonList(contentChange));
	camelLanguageServer.getTextDocumentService().didChange(changeEvent);
	
	//check old position doesn't provide completion
	CompletableFuture<Either<List<CompletionItem>, CompletionList>> completionsAtOldPosition = getCompletionFor(camelLanguageServer, new Position(0, 11));
	assertThat(completionsAtOldPosition.get().getLeft()).isEmpty();
	
	//check new position provides completion
	CompletableFuture<Either<List<CompletionItem>, CompletionList>> completionsAtNewPosition = getCompletionFor(camelLanguageServer, new Position(0, 58));
	assertThat(completionsAtNewPosition.get().getLeft()).isNotEmpty();
	
}
 
Example 2
Source File: SemanticHighlightingTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
protected void changeDocument(ICompilationUnit unit, String content, int version, Range range, int length) {
	DidChangeTextDocumentParams changeParms = new DidChangeTextDocumentParams();
	VersionedTextDocumentIdentifier textDocument = new VersionedTextDocumentIdentifier();
	textDocument.setUri(JDTUtils.toURI(unit));
	textDocument.setVersion(version);
	changeParms.setTextDocument(textDocument);
	TextDocumentContentChangeEvent event = new TextDocumentContentChangeEvent();
	if (range != null) {
		event.setRange(range);
		event.setRangeLength(length);
	}
	event.setText(content);
	List<TextDocumentContentChangeEvent> contentChanges = new ArrayList<>();
	contentChanges.add(event);
	changeParms.setContentChanges(contentChanges);
	lifeCycleHandler.didChange(changeParms);
}
 
Example 3
Source File: DocumentLifeCycleHandlerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
private void changeDocument(ICompilationUnit cu, String content, int version, Range range, int length) throws JavaModelException {
	DidChangeTextDocumentParams changeParms = new DidChangeTextDocumentParams();
	VersionedTextDocumentIdentifier textDocument = new VersionedTextDocumentIdentifier();
	textDocument.setUri(JDTUtils.toURI(cu));
	textDocument.setVersion(version);
	changeParms.setTextDocument(textDocument);
	TextDocumentContentChangeEvent event = new TextDocumentContentChangeEvent();
	if (range != null) {
		event.setRange(range);
		event.setRangeLength(length);
	}
	event.setText(content);
	List<TextDocumentContentChangeEvent> contentChanges = new ArrayList<>();
	contentChanges.add(event);
	changeParms.setContentChanges(contentChanges);
	lifeCycleHandler.didChange(changeParms);
}
 
Example 4
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 5
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 6
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 7
Source File: CamelDiagnosticTest.java    From camel-language-server with Apache License 2.0 5 votes vote down vote up
@Test
void testValidationErrorUpdatedOnChange() throws Exception {
	testDiagnostic("camel-with-endpoint-error", 1, ".xml");
	
	camelLanguageServer.getTextDocumentService().getOpenedDocument(DUMMY_URI+".xml").getText();
	DidChangeTextDocumentParams params = new DidChangeTextDocumentParams();
	params.setTextDocument(new VersionedTextDocumentIdentifier(DUMMY_URI+".xml", 2));
	List<TextDocumentContentChangeEvent> contentChanges = new ArrayList<>();
	contentChanges.add(new TextDocumentContentChangeEvent("<from uri=\"timer:timerName?delay=1000\" xmlns=\"http://camel.apache.org/schema/blueprint\"></from>\n"));
	params.setContentChanges(contentChanges);
	camelLanguageServer.getTextDocumentService().didChange(params);
	
	await().timeout(AWAIT_TIMEOUT).untilAsserted(() -> assertThat(lastPublishedDiagnostics.getDiagnostics()).isEmpty());
}
 
Example 8
Source File: RdfLintLanguageServerTest.java    From rdflint with MIT License 5 votes vote down vote up
@Test
public void diagnosticsChange() 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);

  DidChangeTextDocumentParams changeParams = new DidChangeTextDocumentParams();
  changeParams.setTextDocument(new VersionedTextDocumentIdentifier());
  changeParams.getTextDocument()
      .setUri(RdfLintLanguageServer.convertFilePath2Uri(parentPath + "/needtrim.rdf"));
  List<TextDocumentContentChangeEvent> changeEvents = new LinkedList<>();
  changeParams.setContentChanges(changeEvents);
  changeEvents.add(new TextDocumentContentChangeEvent());
  changeEvents.get(0).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.didChange(changeParams);

  verify(client, times(1)).publishDiagnostics(any());
}
 
Example 9
Source File: RdfLintLanguageServerTest.java    From rdflint with MIT License 5 votes vote down vote up
@Test
public void diagnosticsChangeParseError() 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);

  DidChangeTextDocumentParams changeParams = new DidChangeTextDocumentParams();
  changeParams.setTextDocument(new VersionedTextDocumentIdentifier());
  changeParams.getTextDocument()
      .setUri(RdfLintLanguageServer.convertFilePath2Uri(parentPath + "/needtrim.rdf"));
  List<TextDocumentContentChangeEvent> changeEvents = new LinkedList<>();
  changeParams.setContentChanges(changeEvents);
  changeEvents.add(new TextDocumentContentChangeEvent());
  changeEvents.get(0).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:familyN>\n"
      + "  </rdf:Description>\n"
      + "\n"
      + "</rdf:RDF>");
  lsp.didChange(changeParams);

  verify(client, times(1)).publishDiagnostics(any());
}
 
Example 10
Source File: SemanticHighlightingTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
protected void changeDocument(ICompilationUnit unit, int version, TextDocumentContentChangeEvent event, TextDocumentContentChangeEvent... rest) {
	DidChangeTextDocumentParams changeParms = new DidChangeTextDocumentParams();
	VersionedTextDocumentIdentifier textDocument = new VersionedTextDocumentIdentifier();
	textDocument.setUri(JDTUtils.toURI(unit));
	textDocument.setVersion(version);
	changeParms.setTextDocument(textDocument);
	changeParms.setContentChanges(Lists.asList(event, rest));
	lifeCycleHandler.didChange(changeParms);
}
 
Example 11
Source File: CompletionHandlerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private void changeDocument(ICompilationUnit unit, String content, int version) throws JavaModelException {
	DidChangeTextDocumentParams changeParms = new DidChangeTextDocumentParams();
	VersionedTextDocumentIdentifier textDocument = new VersionedTextDocumentIdentifier();
	textDocument.setUri(JDTUtils.toURI(unit));
	textDocument.setVersion(version);
	changeParms.setTextDocument(textDocument);
	TextDocumentContentChangeEvent event = new TextDocumentContentChangeEvent();
	event.setText(content);
	List<TextDocumentContentChangeEvent> contentChanges = new ArrayList<>();
	contentChanges.add(event);
	changeParms.setContentChanges(contentChanges);
	lifeCycleHandler.didChange(changeParms);
}