use of org.eclipse.lsp4j.TextDocumentContentChangeEvent in project sonarlint-core by SonarSource.
the class ServerMainTest method testCodeActionRuleDescription.
@Test
public void testCodeActionRuleDescription() throws Exception {
String uri = getUri("foo.js");
VersionedTextDocumentIdentifier docId = new VersionedTextDocumentIdentifier(1);
docId.setUri(uri);
lsProxy.getTextDocumentService().didChange(new DidChangeTextDocumentParams(docId, Collections.singletonList(new TextDocumentContentChangeEvent("function foo() {\n alert('toto');\n}"))));
List<? extends Command> codeActions = lsProxy.getTextDocumentService().codeAction(new CodeActionParams(new TextDocumentIdentifier(uri), new Range(new Position(1, 4), new Position(1, 4)), new CodeActionContext(waitForDiagnostics(uri)))).get();
assertThat(codeActions).hasSize(1);
String ruleKey = (String) codeActions.get(0).getArguments().get(0);
assertThat(ruleKey).isEqualTo("javascript:S1442");
lsProxy.getWorkspaceService().executeCommand(new ExecuteCommandParams(codeActions.get(0).getCommand(), codeActions.get(0).getArguments())).get();
assertThat(client.ruleDescs).hasSize(1);
assertThat(client.ruleDescs.get(0).getKey()).isEqualTo("javascript:S1442");
assertThat(client.ruleDescs.get(0).getName()).contains("\"alert(...)\" should not be used");
assertThat(client.ruleDescs.get(0).getHtmlDescription()).contains("can be useful for debugging during development");
assertThat(client.ruleDescs.get(0).getType()).isEqualTo("VULNERABILITY");
assertThat(client.ruleDescs.get(0).getSeverity()).isEqualTo("MINOR");
}
use of org.eclipse.lsp4j.TextDocumentContentChangeEvent in project xtext-core by eclipse.
the class LanguageServerImpl method didChange.
@Override
public void didChange(final DidChangeTextDocumentParams params) {
final Function0<BuildManager.Buildable> _function = () -> {
final Function1<TextDocumentContentChangeEvent, TextEdit> _function_1 = (TextDocumentContentChangeEvent event) -> {
Range _range = event.getRange();
String _text = event.getText();
return new TextEdit(_range, _text);
};
return this.workspaceManager.didChange(this._uriExtensions.toUri(params.getTextDocument().getUri()), params.getTextDocument().getVersion(), ListExtensions.<TextDocumentContentChangeEvent, TextEdit>map(params.getContentChanges(), _function_1));
};
final Function2<CancelIndicator, BuildManager.Buildable, List<IResourceDescription.Delta>> _function_1 = (CancelIndicator cancelIndicator, BuildManager.Buildable buildable) -> {
return buildable.build(cancelIndicator);
};
this.requestManager.<BuildManager.Buildable, List<IResourceDescription.Delta>>runWrite(_function, _function_1);
}
use of org.eclipse.lsp4j.TextDocumentContentChangeEvent in project xtext-core by eclipse.
the class DocumentTest method change.
private TextDocumentContentChangeEvent change(Position startPos, Position endPos, String newText) {
TextDocumentContentChangeEvent textDocumentContentChangeEvent = new TextDocumentContentChangeEvent();
if (startPos != null) {
textDocumentContentChangeEvent.setRange(new Range(startPos, endPos));
}
textDocumentContentChangeEvent.setText(newText);
return textDocumentContentChangeEvent;
}
use of org.eclipse.lsp4j.TextDocumentContentChangeEvent in project xtext-core by eclipse.
the class OpenDocumentTest method testDidChange.
@Test
public void testDidChange() {
String model = "type Test {\n" + " NonExisting foo\n" + "}\n";
String firstFile = writeFile("MyType1.testlang", model);
initialize();
assertEquals("Couldn't resolve reference to TypeDeclaration 'NonExisting'.", Iterables.getFirst(getDiagnostics().get(firstFile), null).getMessage());
open(firstFile, model);
assertEquals("Couldn't resolve reference to TypeDeclaration 'NonExisting'.", Iterables.getFirst(getDiagnostics().get(firstFile), null).getMessage());
DidChangeTextDocumentParams didChangeTextDocumentParams = new DidChangeTextDocumentParams();
didChangeTextDocumentParams.setTextDocument(new VersionedTextDocumentIdentifier(firstFile, 2));
TextDocumentContentChangeEvent textDocumentContentChangeEvent = new TextDocumentContentChangeEvent("Test");
textDocumentContentChangeEvent.setRange(new Range(new Position(1, 4), new Position(1, 15)));
didChangeTextDocumentParams.setContentChanges(Lists.newArrayList(textDocumentContentChangeEvent));
languageServer.didChange(didChangeTextDocumentParams);
Assert.assertNull(Iterables.getFirst(getDiagnostics().get(firstFile), null));
}
use of org.eclipse.lsp4j.TextDocumentContentChangeEvent in project sts4 by spring-projects.
the class SimpleTextDocumentService method didOpen.
@Override
public void didOpen(DidOpenTextDocumentParams params) {
async.execute(() -> {
TextDocumentItem docId = params.getTextDocument();
String url = docId.getUri();
// Log.info("didOpen: "+params.getTextDocument().getUri());
LanguageId languageId = LanguageId.of(docId.getLanguageId());
int version = docId.getVersion();
if (url != null) {
String text = params.getTextDocument().getText();
TrackedDocument td = createDocument(url, languageId, version, text).open();
// Log.info("Opened "+td.getOpenCount()+" times: "+url);
TextDocument doc = td.getDocument();
TextDocumentContentChangeEvent change = new TextDocumentContentChangeEvent() {
@Override
public Range getRange() {
return null;
}
@Override
public Integer getRangeLength() {
return null;
}
@Override
public String getText() {
return text;
}
};
TextDocumentContentChange evt = new TextDocumentContentChange(doc, ImmutableList.of(change));
documentChangeListeners.fire(evt);
}
});
}
Aggregations