use of org.eclipse.lsp4j.TextDocumentIdentifier in project vscode-nextgenas by BowlerHatLLC.
the class ActionScriptTextDocumentService method codeAction.
/**
* Can be used to "quick fix" an error or warning.
*/
@Override
public CompletableFuture<List<? extends Command>> codeAction(CodeActionParams params) {
List<? extends Diagnostic> diagnostics = params.getContext().getDiagnostics();
TextDocumentIdentifier textDocument = params.getTextDocument();
Path path = LanguageServerUtils.getPathFromLanguageServerURI(textDocument.getUri());
if (path == null || !sourceByPath.containsKey(path)) {
return CompletableFuture.completedFuture(Collections.emptyList());
}
ArrayList<Command> commands = new ArrayList<>();
for (Diagnostic diagnostic : diagnostics) {
//I don't know why this can be null
String code = diagnostic.getCode();
if (code == null) {
continue;
}
switch(code) {
case //AccessUndefinedPropertyProblem
"1120":
{
//see if there's anything we can import
createCodeActionsForImport(diagnostic, commands);
break;
}
case //UnknownTypeProblem
"1046":
{
//see if there's anything we can import
createCodeActionsForImport(diagnostic, commands);
break;
}
case //InaccessiblePropertyReferenceProblem
"1178":
{
//see if there's anything we can import
createCodeActionsForImport(diagnostic, commands);
break;
}
case //CallUndefinedMethodProblem
"1180":
{
//see if there's anything we can import
createCodeActionsForImport(diagnostic, commands);
break;
}
}
}
return CompletableFuture.completedFuture(commands);
}
use of org.eclipse.lsp4j.TextDocumentIdentifier in project vscode-nextgenas by BowlerHatLLC.
the class ActionScriptTextDocumentService method didClose.
/**
* Called when a file is closed in Visual Studio Code. We should no longer
* store the file as a String, and we can load the contents from the file
* system.
*/
@Override
public void didClose(DidCloseTextDocumentParams params) {
TextDocumentIdentifier textDocument = params.getTextDocument();
String textDocumentUri = textDocument.getUri();
if (!textDocumentUri.endsWith(AS_EXTENSION) && !textDocumentUri.endsWith(MXML_EXTENSION)) {
return;
}
Path path = LanguageServerUtils.getPathFromLanguageServerURI(textDocumentUri);
if (path != null) {
sourceByPath.remove(path);
}
}
use of org.eclipse.lsp4j.TextDocumentIdentifier in project vscode-nextgenas by BowlerHatLLC.
the class ActionScriptTextDocumentService method documentSymbol.
/**
* Searches by name for a symbol in a specific document (not the whole
* workspace)
*/
@Override
public CompletableFuture<List<? extends SymbolInformation>> documentSymbol(DocumentSymbolParams params) {
TextDocumentIdentifier textDocument = params.getTextDocument();
Path path = LanguageServerUtils.getPathFromLanguageServerURI(textDocument.getUri());
if (path == null) {
return CompletableFuture.completedFuture(Collections.emptyList());
}
ICompilationUnit unit = getCompilationUnit(path);
if (unit == null) {
//we couldn't find a compilation unit with the specified path
return CompletableFuture.completedFuture(Collections.emptyList());
}
IASScope[] scopes;
try {
scopes = unit.getFileScopeRequest().get().getScopes();
} catch (Exception e) {
return CompletableFuture.completedFuture(Collections.emptyList());
}
List<SymbolInformation> result = new ArrayList<>();
for (IASScope scope : scopes) {
scopeToSymbols(scope, result);
}
return CompletableFuture.completedFuture(result);
}
use of org.eclipse.lsp4j.TextDocumentIdentifier in project sonarlint-core by SonarSource.
the class ServerMainTest method analyzeSimpleJsFileOnSave.
@Test
public void analyzeSimpleJsFileOnSave() throws Exception {
String uri = getUri("foo.js");
lsProxy.getTextDocumentService().didSave(new DidSaveTextDocumentParams(new TextDocumentIdentifier(uri), "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.TextDocumentIdentifier 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");
}
Aggregations