Search in sources :

Example 61 with Command

use of org.eclipse.lsp4j.Command in project eclipse.jdt.ls by eclipse.

the class AbstractQuickFixTest method assertCodeActionExists.

protected void assertCodeActionExists(ICompilationUnit cu, Expected expected) throws Exception {
    List<Command> codeActionCommands = evaluateCodeActions(cu);
    for (Command c : codeActionCommands) {
        String actual = evaluateCodeActionCommand(c);
        if (expected.content.equals(actual)) {
            assertEquals(expected.name, c.getTitle());
            return;
        }
    }
    String res = "";
    for (Command command : codeActionCommands) {
        if (res.length() > 0) {
            res += '\n';
        }
        res += command.getTitle();
    }
    assertEquals("Not found.", expected.name, res);
}
Also used : Command(org.eclipse.lsp4j.Command)

Example 62 with Command

use of org.eclipse.lsp4j.Command in project eclipse.jdt.ls by eclipse.

the class AbstractQuickFixTest method assertCodeActions.

protected void assertCodeActions(ICompilationUnit cu, Expected... expected) throws Exception {
    List<Command> codeActionCommands = evaluateCodeActions(cu);
    if (codeActionCommands.size() != expected.length) {
        String res = "";
        for (Command command : codeActionCommands) {
            res += " '" + command.getTitle() + "'";
        }
        assertEquals("Number of code actions: " + res, expected.length, codeActionCommands.size());
    }
    int k = 0;
    String aStr = "", eStr = "", testContent = "";
    for (Command c : codeActionCommands) {
        String actual = evaluateCodeActionCommand(c);
        Expected e = expected[k++];
        if (!e.name.equals(c.getTitle()) || !e.content.equals(actual)) {
            aStr += '\n' + c.getTitle() + '\n' + actual;
            eStr += '\n' + e.name + '\n' + e.content;
        }
        testContent += generateTest(actual, c.getTitle(), k);
    }
    if (aStr.length() > 0) {
        aStr += '\n' + testContent;
    }
    assertEquals(eStr, aStr);
}
Also used : Command(org.eclipse.lsp4j.Command)

Example 63 with Command

use of org.eclipse.lsp4j.Command in project xtext-core by eclipse.

the class CodeActionService method fixInvalidName.

private Command fixInvalidName(Diagnostic d, ICodeActionService2.Options options) {
    String string = options.getDocument().getSubstring(d.getRange());
    Command command = new Command();
    command.setCommand("my.textedit.command");
    command.setTitle("Make '" + string + "' upper case (Command)");
    WorkspaceEdit workspaceEdit = new WorkspaceEdit();
    TextEdit textEdit = new TextEdit();
    textEdit.setNewText(StringExtensions.toFirstUpper(string));
    textEdit.setRange(d.getRange());
    workspaceEdit.getChanges().put(options.getCodeActionParams().getTextDocument().getUri(), Lists.newArrayList(textEdit));
    command.setArguments(Lists.newArrayList(workspaceEdit));
    return command;
}
Also used : Command(org.eclipse.lsp4j.Command) TextEdit(org.eclipse.lsp4j.TextEdit) WorkspaceEdit(org.eclipse.lsp4j.WorkspaceEdit)

Example 64 with Command

use of org.eclipse.lsp4j.Command in project xtext-core by eclipse.

the class AbstractLanguageServerTest method _toExpectation.

protected String _toExpectation(final CodeAction it) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("title : ");
    String _title = it.getTitle();
    _builder.append(_title);
    _builder.newLineIfNotEmpty();
    _builder.append("kind : ");
    String _kind = it.getKind();
    _builder.append(_kind);
    _builder.newLineIfNotEmpty();
    _builder.append("command : ");
    Command _command = it.getCommand();
    _builder.append(_command);
    _builder.newLineIfNotEmpty();
    {
        boolean _isNullOrEmpty = IterableExtensions.isNullOrEmpty(it.getDiagnostics());
        boolean _not = (!_isNullOrEmpty);
        if (_not) {
            _builder.append("codes : ");
            final Function1<Diagnostic, Object> _function = (Diagnostic it_1) -> {
                return it_1.getCode().get();
            };
            String _join = IterableExtensions.join(ListExtensions.<Diagnostic, Object>map(it.getDiagnostics(), _function), ",");
            _builder.append(_join);
        }
    }
    _builder.newLineIfNotEmpty();
    _builder.append("edit : ");
    String _expectation = this.toExpectation(it.getEdit());
    _builder.append(_expectation);
    _builder.newLineIfNotEmpty();
    return _builder.toString();
}
Also used : Command(org.eclipse.lsp4j.Command) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) Diagnostic(org.eclipse.lsp4j.Diagnostic)

Example 65 with Command

use of org.eclipse.lsp4j.Command in project ballerina by ballerina-lang.

the class BallerinaTextDocumentService method codeAction.

@Override
public CompletableFuture<List<? extends Command>> codeAction(CodeActionParams params) {
    return CompletableFuture.supplyAsync(() -> {
        List<Command> commands = new ArrayList<>();
        String topLevelNodeType = CommonUtil.topLevelNodeTypeInLine(params.getTextDocument(), params.getRange().getStart(), documentManager);
        if (topLevelNodeType != null) {
            commands.add(CommandUtil.getDocGenerationCommand(topLevelNodeType, params.getTextDocument().getUri(), params.getRange().getStart().getLine()));
            commands.add(CommandUtil.getAllDocGenerationCommand(params.getTextDocument().getUri()));
        } else if (!params.getContext().getDiagnostics().isEmpty()) {
            params.getContext().getDiagnostics().forEach(diagnostic -> {
                commands.addAll(CommandUtil.getCommandsByDiagnostic(diagnostic, params, lSPackageCache));
            });
        }
        return commands;
    });
}
Also used : CommonUtil(org.ballerinalang.langserver.common.utils.CommonUtil) JsonObject(com.google.gson.JsonObject) RenameUtil(org.ballerinalang.langserver.rename.RenameUtil) HoverUtil(org.ballerinalang.langserver.hover.util.HoverUtil) DidChangeTextDocumentParams(org.eclipse.lsp4j.DidChangeTextDocumentParams) NodeContextKeys(org.ballerinalang.langserver.common.constants.NodeContextKeys) DidSaveTextDocumentParams(org.eclipse.lsp4j.DidSaveTextDocumentParams) TreeVisitor(org.ballerinalang.langserver.completions.TreeVisitor) LSDocument(org.ballerinalang.langserver.common.LSDocument) PublishDiagnosticsParams(org.eclipse.lsp4j.PublishDiagnosticsParams) CodeLens(org.eclipse.lsp4j.CodeLens) Map(java.util.Map) Location(org.eclipse.lsp4j.Location) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) BLangCompilationUnit(org.wso2.ballerinalang.compiler.tree.BLangCompilationUnit) URI(java.net.URI) DidCloseTextDocumentParams(org.eclipse.lsp4j.DidCloseTextDocumentParams) RenameParams(org.eclipse.lsp4j.RenameParams) Path(java.nio.file.Path) SignatureTreeVisitor(org.ballerinalang.langserver.signature.SignatureTreeVisitor) ReferenceUtil(org.ballerinalang.langserver.references.util.ReferenceUtil) TextDocumentService(org.eclipse.lsp4j.services.TextDocumentService) DiagnosticSeverity(org.eclipse.lsp4j.DiagnosticSeverity) TextDocumentPositionParams(org.eclipse.lsp4j.TextDocumentPositionParams) DiagnosticListener(org.ballerinalang.util.diagnostic.DiagnosticListener) MarkedString(org.eclipse.lsp4j.MarkedString) DocumentOnTypeFormattingParams(org.eclipse.lsp4j.DocumentOnTypeFormattingParams) CompletionItem(org.eclipse.lsp4j.CompletionItem) BLangNode(org.wso2.ballerinalang.compiler.tree.BLangNode) List(java.util.List) Command(org.eclipse.lsp4j.Command) DidOpenTextDocumentParams(org.eclipse.lsp4j.DidOpenTextDocumentParams) WorkspacePackageRepository(org.ballerinalang.langserver.workspace.repository.WorkspacePackageRepository) Optional(java.util.Optional) Debouncer(org.ballerinalang.langserver.util.Debouncer) WorkspaceDocumentManager(org.ballerinalang.langserver.workspace.WorkspaceDocumentManager) DocumentSymbolParams(org.eclipse.lsp4j.DocumentSymbolParams) WorkspaceDocumentManagerImpl(org.ballerinalang.langserver.workspace.WorkspaceDocumentManagerImpl) Diagnostic(org.eclipse.lsp4j.Diagnostic) Range(org.eclipse.lsp4j.Range) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) DocumentRangeFormattingParams(org.eclipse.lsp4j.DocumentRangeFormattingParams) Hover(org.eclipse.lsp4j.Hover) Compiler(org.wso2.ballerinalang.compiler.Compiler) SymbolInformation(org.eclipse.lsp4j.SymbolInformation) ArrayList(java.util.ArrayList) CommandUtil(org.ballerinalang.langserver.command.CommandUtil) SignatureHelpUtil(org.ballerinalang.langserver.signature.SignatureHelpUtil) PositionTreeVisitor(org.ballerinalang.langserver.common.position.PositionTreeVisitor) CodeActionParams(org.eclipse.lsp4j.CodeActionParams) TextEdit(org.eclipse.lsp4j.TextEdit) PackageRepository(org.ballerinalang.repository.PackageRepository) DocumentFormattingParams(org.eclipse.lsp4j.DocumentFormattingParams) Position(org.eclipse.lsp4j.Position) CompletionKeys(org.ballerinalang.langserver.completions.CompletionKeys) CodeLensParams(org.eclipse.lsp4j.CodeLensParams) CompletionList(org.eclipse.lsp4j.CompletionList) SymbolFindingVisitor(org.ballerinalang.langserver.symbols.SymbolFindingVisitor) CompletionItemResolver(org.ballerinalang.langserver.completions.util.CompletionItemResolver) BLangPackage(org.wso2.ballerinalang.compiler.tree.BLangPackage) DocumentHighlight(org.eclipse.lsp4j.DocumentHighlight) DefinitionUtil(org.ballerinalang.langserver.definition.util.DefinitionUtil) SignatureHelp(org.eclipse.lsp4j.SignatureHelp) LSCustomErrorStrategy(org.ballerinalang.langserver.common.LSCustomErrorStrategy) WorkspaceEdit(org.eclipse.lsp4j.WorkspaceEdit) Paths(java.nio.file.Paths) CompletionCustomErrorStrategy(org.ballerinalang.langserver.completions.CompletionCustomErrorStrategy) Collections(java.util.Collections) TopLevelResolver(org.ballerinalang.langserver.completions.resolvers.TopLevelResolver) TextDocumentFormatUtil(org.ballerinalang.langserver.format.TextDocumentFormatUtil) ReferenceParams(org.eclipse.lsp4j.ReferenceParams) CompilerContext(org.wso2.ballerinalang.compiler.util.CompilerContext) Command(org.eclipse.lsp4j.Command) ArrayList(java.util.ArrayList) MarkedString(org.eclipse.lsp4j.MarkedString)

Aggregations

Command (org.eclipse.lsp4j.Command)95 CodeAction (org.eclipse.lsp4j.CodeAction)58 Either (org.eclipse.lsp4j.jsonrpc.messages.Either)53 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)49 Test (org.junit.Test)46 Range (org.eclipse.lsp4j.Range)36 CodeActionParams (org.eclipse.lsp4j.CodeActionParams)35 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)26 CodeActionContext (org.eclipse.lsp4j.CodeActionContext)23 TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)23 List (java.util.List)22 Position (org.eclipse.lsp4j.Position)22 WorkspaceEdit (org.eclipse.lsp4j.WorkspaceEdit)21 AbstractQuickFixTest (org.eclipse.jdt.ls.core.internal.correction.AbstractQuickFixTest)17 Diagnostic (org.eclipse.lsp4j.Diagnostic)17 Arrays (java.util.Arrays)14 Collections (java.util.Collections)14 JDTUtils (org.eclipse.jdt.ls.core.internal.JDTUtils)13 CodeActionKind (org.eclipse.lsp4j.CodeActionKind)13 Optional (java.util.Optional)12