use of org.eclipse.lsp4j.DidChangeTextDocumentParams in project sonarlint-core by SonarSource.
the class ServerMainTest method analyzeSimpleJsFileOnChange.
@Test
public void analyzeSimpleJsFileOnChange() 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}"))));
assertThat(waitForDiagnostics(uri)).extracting("range.start.line", "range.start.character", "range.end.line", "range.end.character", "code", "source", "message", "severity").containsExactly(tuple(1, 2, 1, 15, "javascript:S1442", "sonarlint", "Remove this usage of alert(...). (javascript:S1442)", DiagnosticSeverity.Information));
}
use of org.eclipse.lsp4j.DidChangeTextDocumentParams 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.DidChangeTextDocumentParams in project eclipse.jdt.ls by eclipse.
the class CompletionHandlerTest method changeDocument.
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);
}
use of org.eclipse.lsp4j.DidChangeTextDocumentParams in project eclipse.jdt.ls by eclipse.
the class DocumentLifeCycleHandlerTest method changeDocument.
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);
}
use of org.eclipse.lsp4j.DidChangeTextDocumentParams in project sts4 by spring-projects.
the class LanguageServerHarness method changeDocument.
public synchronized TextDocumentInfo changeDocument(String uri, int start, int end, String replaceText) {
TextDocumentInfo oldDoc = documents.get(uri);
String oldContent = oldDoc.getText();
String newContent = oldContent.substring(0, start) + replaceText + oldContent.substring(end);
TextDocumentItem textDocument = setDocumentContent(uri, newContent);
DidChangeTextDocumentParams didChange = new DidChangeTextDocumentParams();
VersionedTextDocumentIdentifier version = new VersionedTextDocumentIdentifier();
version.setUri(uri);
version.setVersion(textDocument.getVersion());
didChange.setTextDocument(version);
switch(getDocumentSyncMode()) {
case None:
// nothing todo
break;
case Incremental:
{
TextDocumentContentChangeEvent change = new TextDocumentContentChangeEvent();
change.setRange(new Range(oldDoc.toPosition(start), oldDoc.toPosition(end)));
change.setRangeLength(end - start);
change.setText(replaceText);
didChange.setContentChanges(Collections.singletonList(change));
break;
}
case Full:
{
TextDocumentContentChangeEvent change = new TextDocumentContentChangeEvent();
change.setText(newContent);
didChange.setContentChanges(Collections.singletonList(change));
break;
}
default:
throw new IllegalStateException("Unkown SYNC mode: " + getDocumentSyncMode());
}
if (getServer() != null) {
getServer().getTextDocumentService().didChange(didChange);
}
return documents.get(uri);
}
Aggregations