Search in sources :

Example 66 with Command

use of org.eclipse.lsp4j.Command in project sts4 by spring-projects.

the class WebfluxHandlerCodeLensProvider method provideCodeLens.

protected void provideCodeLens(MethodDeclaration node, TextDocument document, List<CodeLens> resultAccumulator) {
    IMethodBinding methodBinding = node.resolveBinding();
    if (methodBinding != null && methodBinding.getDeclaringClass() != null && methodBinding.getMethodDeclaration() != null && methodBinding.getDeclaringClass().getBinaryName() != null && methodBinding.getMethodDeclaration().toString() != null) {
        final String handlerClass = methodBinding.getDeclaringClass().getBinaryName().trim();
        final String handlerMethod = methodBinding.getMethodDeclaration().toString().trim();
        List<SymbolAddOnInformation> handlerInfos = this.springIndexer.getAllAdditionalInformation((addon) -> {
            if (addon instanceof WebfluxHandlerInformation) {
                WebfluxHandlerInformation handlerInfo = (WebfluxHandlerInformation) addon;
                return handlerInfo.getHandlerClass() != null && handlerInfo.getHandlerClass().equals(handlerClass) && handlerInfo.getHandlerMethod() != null && handlerInfo.getHandlerMethod().equals(handlerMethod);
            }
            return false;
        });
        if (handlerInfos != null && handlerInfos.size() > 0) {
            for (Object object : handlerInfos) {
                try {
                    WebfluxHandlerInformation handlerInfo = (WebfluxHandlerInformation) object;
                    CodeLens codeLens = new CodeLens();
                    codeLens.setRange(document.toRange(node.getName().getStartPosition(), node.getName().getLength()));
                    String httpMethod = WebfluxUtils.getStringRep(handlerInfo.getHttpMethods(), string -> string);
                    String codeLensCommand = httpMethod != null ? httpMethod + " " : "";
                    codeLensCommand += handlerInfo.getPath();
                    String acceptType = WebfluxUtils.getStringRep(handlerInfo.getAcceptTypes(), WebfluxUtils::getMediaType);
                    codeLensCommand += acceptType != null ? " - Accept: " + acceptType : "";
                    String contentType = WebfluxUtils.getStringRep(handlerInfo.getContentTypes(), WebfluxUtils::getMediaType);
                    codeLensCommand += contentType != null ? " - Content-Type: " + contentType : "";
                    codeLens.setCommand(new Command(codeLensCommand, null));
                    resultAccumulator.add(codeLens);
                } catch (BadLocationException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
Also used : IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) CodeLens(org.eclipse.lsp4j.CodeLens) Command(org.eclipse.lsp4j.Command) SymbolAddOnInformation(org.springframework.ide.vscode.boot.java.handlers.SymbolAddOnInformation) BadLocationException(org.springframework.ide.vscode.commons.util.BadLocationException)

Example 67 with Command

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

the class GetRefactorEditHandler method getEditsForRefactor.

public static RefactorWorkspaceEdit getEditsForRefactor(GetRefactorEditParams params) {
    final ICompilationUnit unit = JDTUtils.resolveCompilationUnit(params.context.getTextDocument().getUri());
    if (unit == null) {
        return null;
    }
    int start = DiagnosticsHelper.getStartOffset(unit, params.context.getRange());
    int end = DiagnosticsHelper.getEndOffset(unit, params.context.getRange());
    InnovationContext context = new InnovationContext(unit, start, end - start);
    context.setASTRoot(CodeActionHandler.getASTRoot(unit));
    IProblemLocationCore[] locations = CodeActionHandler.getProblemLocationCores(unit, params.context.getContext().getDiagnostics());
    boolean problemsAtLocation = locations.length != 0;
    String positionKey = DEFAULT_POSITION_KEY;
    try {
        Map formatterOptions = params.options == null ? null : FormatterHandler.getOptions(params.options, unit);
        LinkedCorrectionProposal proposal = null;
        if (RefactorProposalUtility.EXTRACT_VARIABLE_COMMAND.equals(params.command) || RefactorProposalUtility.EXTRACT_VARIABLE_ALL_OCCURRENCE_COMMAND.equals(params.command) || RefactorProposalUtility.EXTRACT_CONSTANT_COMMAND.equals(params.command)) {
            SelectionInfo info = (params.commandArguments != null && !params.commandArguments.isEmpty()) ? JSONUtility.toModel(params.commandArguments.get(0), SelectionInfo.class) : null;
            if (info != null) {
                context = new InnovationContext(unit, info.offset, info.length);
            }
            proposal = (LinkedCorrectionProposal) getExtractVariableProposal(params.context, context, problemsAtLocation, params.command, formatterOptions);
        } else if (RefactorProposalUtility.ASSIGN_VARIABLE_COMMAND.equals(params.command)) {
            proposal = (LinkedCorrectionProposal) getAssignVariableProposal(params, context, problemsAtLocation, params.command, formatterOptions, locations);
        } else if (RefactorProposalUtility.ASSIGN_FIELD_COMMAND.equals(params.command)) {
            proposal = (LinkedCorrectionProposal) RefactorProposalUtility.getAssignFieldProposal(params.context, context, problemsAtLocation, formatterOptions, false, locations);
        } else if (RefactorProposalUtility.EXTRACT_METHOD_COMMAND.equals(params.command)) {
            SelectionInfo info = (params.commandArguments != null && !params.commandArguments.isEmpty()) ? JSONUtility.toModel(params.commandArguments.get(0), SelectionInfo.class) : null;
            if (info != null) {
                context = new InnovationContext(unit, info.offset, info.length);
            }
            proposal = (LinkedCorrectionProposal) getExtractMethodProposal(params.context, context, context.getCoveringNode(), problemsAtLocation, formatterOptions);
        } else if (RefactorProposalUtility.CONVERT_VARIABLE_TO_FIELD_COMMAND.equals(params.command)) {
            String initializeIn = (params.commandArguments != null && !params.commandArguments.isEmpty()) ? JSONUtility.toModel(params.commandArguments.get(0), String.class) : null;
            proposal = (LinkedCorrectionProposal) RefactorProposalUtility.getConvertVariableToFieldProposal(params.context, context, problemsAtLocation, formatterOptions, initializeIn, false);
        } else if (RefactorProposalUtility.EXTRACT_FIELD_COMMAND.equals(params.command)) {
            String initializeIn = (params.commandArguments != null && !params.commandArguments.isEmpty()) ? JSONUtility.toModel(params.commandArguments.get(0), String.class) : null;
            SelectionInfo info = (params.commandArguments != null && params.commandArguments.size() > 1) ? JSONUtility.toModel(params.commandArguments.get(1), SelectionInfo.class) : null;
            if (info != null) {
                context = new InnovationContext(unit, info.offset, info.length);
            }
            proposal = (LinkedCorrectionProposal) RefactorProposalUtility.getExtractFieldProposal(params.context, context, problemsAtLocation, formatterOptions, initializeIn, false);
        } else if (InvertBooleanUtility.INVERT_VARIABLE_COMMAND.equals(params.command)) {
            proposal = (LinkedCorrectionProposal) InvertBooleanUtility.getInvertVariableProposal(params.context, context, context.getCoveringNode(), false);
        } else if (RefactorProcessor.CONVERT_ANONYMOUS_CLASS_TO_NESTED_COMMAND.equals(params.command)) {
            proposal = RefactorProcessor.getConvertAnonymousToNestedProposal(params.context, context, context.getCoveringNode(), false);
            positionKey = "type_name";
        } else if (RefactorProposalUtility.INTRODUCE_PARAMETER_COMMAND.equals(params.command)) {
            // String initializeIn = (params.commandArguments != null && !params.commandArguments.isEmpty()) ? JSONUtility.toModel(params.commandArguments.get(0), String.class) : null;
            proposal = (LinkedCorrectionProposal) RefactorProposalUtility.getIntroduceParameterRefactoringProposals(params.context, context, context.getCoveringNode(), false, locations);
            positionKey = null;
            if (proposal instanceof RefactoringCorrectionProposal) {
                RefactoringCorrectionProposal rcp = (RefactoringCorrectionProposal) proposal;
                IntroduceParameterRefactoring refactoring = (IntroduceParameterRefactoring) rcp.getRefactoring();
                ParameterInfo parameterInfo = refactoring.getAddedParameterInfo();
                if (parameterInfo != null) {
                    positionKey = parameterInfo.getNewName();
                }
            }
        }
        if (proposal == null) {
            return null;
        }
        Change change = proposal.getChange();
        WorkspaceEdit edit = ChangeUtil.convertToWorkspaceEdit(change);
        LinkedProposalModelCore linkedProposalModel = proposal.getLinkedProposalModel();
        Command additionalCommand = null;
        if (linkedProposalModel != null) {
            LinkedProposalPositionGroupCore linkedPositionGroup = linkedProposalModel.getPositionGroup(positionKey, false);
            if (linkedPositionGroup == null) {
                Iterator<LinkedProposalPositionGroupCore> iter = linkedProposalModel.getPositionGroupCoreIterator();
                while (iter.hasNext()) {
                    LinkedProposalPositionGroupCore lppgc = iter.next();
                    if (lppgc.getGroupId().startsWith(positionKey)) {
                        linkedPositionGroup = lppgc;
                        break;
                    }
                }
            }
            PositionInformation highlightPosition = getFirstTrackedNodePositionBySequenceRank(linkedPositionGroup);
            if (highlightPosition != null) {
                int offset = highlightPosition.getOffset();
                int length = highlightPosition.getLength();
                RenamePosition renamePosition = new RenamePosition(JDTUtils.toURI(unit), offset, length);
                additionalCommand = new Command("Rename", RENAME_COMMAND, Arrays.asList(renamePosition));
            }
        }
        return new RefactorWorkspaceEdit(edit, additionalCommand);
    } catch (CoreException e) {
    // do nothing.
    }
    return null;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IntroduceParameterRefactoring(org.eclipse.jdt.ls.core.internal.corext.refactoring.code.IntroduceParameterRefactoring) PositionInformation(org.eclipse.jdt.internal.corext.fix.LinkedProposalPositionGroupCore.PositionInformation) LinkedProposalPositionGroupCore(org.eclipse.jdt.internal.corext.fix.LinkedProposalPositionGroupCore) WorkspaceEdit(org.eclipse.lsp4j.WorkspaceEdit) InnovationContext(org.eclipse.jdt.ls.core.internal.corrections.InnovationContext) ParameterInfo(org.eclipse.jdt.ls.core.internal.corext.refactoring.ParameterInfo) Change(org.eclipse.ltk.core.refactoring.Change) RefactoringCorrectionProposal(org.eclipse.jdt.ls.core.internal.corrections.proposals.RefactoringCorrectionProposal) LinkedProposalModelCore(org.eclipse.jdt.internal.corext.fix.LinkedProposalModelCore) IProblemLocationCore(org.eclipse.jdt.internal.ui.text.correction.IProblemLocationCore) SelectionInfo(org.eclipse.jdt.ls.core.internal.handlers.InferSelectionHandler.SelectionInfo) CoreException(org.eclipse.core.runtime.CoreException) Command(org.eclipse.lsp4j.Command) LinkedCorrectionProposal(org.eclipse.jdt.ls.core.internal.corrections.proposals.LinkedCorrectionProposal) Map(java.util.Map)

Example 68 with Command

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

the class CodeActionHandler method getCodeActionCommands.

public List<Either<Command, CodeAction>> getCodeActionCommands(CodeActionParams params, IProgressMonitor monitor) {
    if (monitor.isCanceled()) {
        return Collections.emptyList();
    }
    final ICompilationUnit unit = JDTUtils.resolveCompilationUnit(params.getTextDocument().getUri());
    if (unit == null || monitor.isCanceled()) {
        return Collections.emptyList();
    }
    Map<String, Object> formattingOptions = ConfigurationHandler.getFormattingOptions(params.getTextDocument().getUri());
    if (formattingOptions != null && !formattingOptions.isEmpty()) {
        Object tabSizeValue = formattingOptions.get(Preferences.JAVA_CONFIGURATION_TABSIZE);
        Object insertSpacesValue = formattingOptions.get(Preferences.JAVA_CONFIGURATION_INSERTSPACES);
        Map<String, String> customOptions = new HashMap<>();
        if (tabSizeValue != null) {
            try {
                int tabSize = Integer.parseInt(String.valueOf(tabSizeValue));
                if (tabSize > 0) {
                    customOptions.put(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, Integer.toString(tabSize));
                }
            } catch (Exception ex) {
            // do nothing
            }
        }
        if (insertSpacesValue != null) {
            boolean insertSpaces = Boolean.parseBoolean(String.valueOf(insertSpacesValue));
            customOptions.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, insertSpaces ? JavaCore.SPACE : JavaCore.TAB);
        }
        if (!customOptions.isEmpty()) {
            unit.setOptions(customOptions);
        }
    }
    CompilationUnit astRoot = getASTRoot(unit, monitor);
    if (astRoot == null || monitor.isCanceled()) {
        return Collections.emptyList();
    }
    int start = DiagnosticsHelper.getStartOffset(unit, params.getRange());
    int end = DiagnosticsHelper.getEndOffset(unit, params.getRange());
    InnovationContext context = new InnovationContext(unit, start, end - start);
    context.setASTRoot(astRoot);
    List<Diagnostic> diagnostics = params.getContext().getDiagnostics().stream().filter((d) -> {
        return JavaLanguageServerPlugin.SERVER_SOURCE_ID.equals(d.getSource());
    }).collect(Collectors.toList());
    IProblemLocationCore[] locations = getProblemLocationCores(unit, diagnostics);
    if (monitor.isCanceled()) {
        return Collections.emptyList();
    }
    List<String> codeActionKinds = new ArrayList<>();
    if (params.getContext().getOnly() != null && !params.getContext().getOnly().isEmpty()) {
        codeActionKinds.addAll(params.getContext().getOnly());
    } else {
        List<String> defaultCodeActionKinds = Arrays.asList(CodeActionKind.QuickFix, CodeActionKind.Refactor, JavaCodeActionKind.QUICK_ASSIST, CodeActionKind.Source);
        codeActionKinds.addAll(defaultCodeActionKinds);
    }
    List<Either<Command, CodeAction>> codeActions = new ArrayList<>();
    List<ChangeCorrectionProposal> proposals = new ArrayList<>();
    ChangeCorrectionProposalComparator comparator = new ChangeCorrectionProposalComparator();
    if (containsKind(codeActionKinds, CodeActionKind.QuickFix)) {
        try {
            codeActions.addAll(nonProjectFixProcessor.getCorrections(params, context, locations));
            List<ChangeCorrectionProposal> quickfixProposals = this.quickFixProcessor.getCorrections(context, locations);
            quickfixProposals.sort(comparator);
            proposals.addAll(quickfixProposals);
        } catch (CoreException e) {
            JavaLanguageServerPlugin.logException("Problem resolving quick fix code actions", e);
        }
    }
    if (monitor.isCanceled()) {
        return Collections.emptyList();
    }
    if (containsKind(codeActionKinds, CodeActionKind.Refactor)) {
        try {
            List<ChangeCorrectionProposal> refactorProposals = this.refactorProcessor.getProposals(params, context, locations);
            refactorProposals.sort(comparator);
            proposals.addAll(refactorProposals);
        } catch (CoreException e) {
            JavaLanguageServerPlugin.logException("Problem resolving refactor code actions", e);
        }
    }
    if (monitor.isCanceled()) {
        return Collections.emptyList();
    }
    if (containsKind(codeActionKinds, JavaCodeActionKind.QUICK_ASSIST)) {
        try {
            List<ChangeCorrectionProposal> quickassistProposals = this.quickAssistProcessor.getAssists(params, context, locations);
            quickassistProposals.sort(comparator);
            proposals.addAll(quickassistProposals);
        } catch (CoreException e) {
            JavaLanguageServerPlugin.logException("Problem resolving quick assist code actions", e);
        }
    }
    if (monitor.isCanceled()) {
        return Collections.emptyList();
    }
    try {
        for (ChangeCorrectionProposal proposal : proposals) {
            Optional<Either<Command, CodeAction>> codeActionFromProposal = getCodeActionFromProposal(proposal, params.getContext());
            if (codeActionFromProposal.isPresent() && !codeActions.contains(codeActionFromProposal.get())) {
                codeActions.add(codeActionFromProposal.get());
            }
        }
    } catch (CoreException e) {
        JavaLanguageServerPlugin.logException("Problem converting proposal to code actions", e);
    }
    if (monitor.isCanceled()) {
        return Collections.emptyList();
    }
    if (containsKind(codeActionKinds, CodeActionKind.Source)) {
        codeActions.addAll(sourceAssistProcessor.getSourceActionCommands(params, context, locations, monitor));
    }
    if (monitor.isCanceled()) {
        return Collections.emptyList();
    }
    populateDataFields(codeActions);
    return codeActions;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) Arrays(java.util.Arrays) CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) CoreException(org.eclipse.core.runtime.CoreException) StringUtils(org.apache.commons.lang3.StringUtils) DefaultCodeFormatterConstants(org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants) QuickFixProcessor(org.eclipse.jdt.ls.core.internal.corrections.QuickFixProcessor) DiagnosticsHelper(org.eclipse.jdt.ls.core.internal.corrections.DiagnosticsHelper) Map(java.util.Map) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) CodeAction(org.eclipse.lsp4j.CodeAction) JDTUtils(org.eclipse.jdt.ls.core.internal.JDTUtils) DiagnosticSeverity(org.eclipse.lsp4j.DiagnosticSeverity) ProblemLocationCore(org.eclipse.jdt.internal.ui.text.correction.ProblemLocationCore) Collectors(java.util.stream.Collectors) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) QuickAssistProcessor(org.eclipse.jdt.ls.core.internal.text.correction.QuickAssistProcessor) IJavaModelMarker(org.eclipse.jdt.core.IJavaModelMarker) IProblemLocationCore(org.eclipse.jdt.internal.ui.text.correction.IProblemLocationCore) List(java.util.List) JsonArray(com.google.gson.JsonArray) Command(org.eclipse.lsp4j.Command) Preferences(org.eclipse.jdt.ls.core.internal.preferences.Preferences) InnovationContext(org.eclipse.jdt.ls.core.internal.corrections.InnovationContext) Optional(java.util.Optional) ChangeUtil(org.eclipse.jdt.ls.core.internal.ChangeUtil) RefactoringCorrectionCommandProposal(org.eclipse.jdt.ls.core.internal.text.correction.RefactoringCorrectionCommandProposal) JavaCodeActionKind(org.eclipse.jdt.ls.core.internal.JavaCodeActionKind) HashMap(java.util.HashMap) Diagnostic(org.eclipse.lsp4j.Diagnostic) RefactorProcessor(org.eclipse.jdt.ls.core.internal.corrections.RefactorProcessor) CodeActionContext(org.eclipse.lsp4j.CodeActionContext) ArrayList(java.util.ArrayList) SourceAssistProcessor(org.eclipse.jdt.ls.core.internal.text.correction.SourceAssistProcessor) JsonElement(com.google.gson.JsonElement) CodeActionParams(org.eclipse.lsp4j.CodeActionParams) ChangeCorrectionProposal(org.eclipse.jdt.ls.core.internal.corrections.proposals.ChangeCorrectionProposal) CUCorrectionCommandProposal(org.eclipse.jdt.ls.core.internal.text.correction.CUCorrectionCommandProposal) JavaCore(org.eclipse.jdt.core.JavaCore) JavaLanguageServerPlugin(org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin) NonProjectFixProcessor(org.eclipse.jdt.ls.core.internal.text.correction.NonProjectFixProcessor) PreferenceManager(org.eclipse.jdt.ls.core.internal.preferences.PreferenceManager) AssignToVariableAssistCommandProposal(org.eclipse.jdt.ls.core.internal.text.correction.AssignToVariableAssistCommandProposal) CoreASTProvider(org.eclipse.jdt.core.manipulation.CoreASTProvider) WorkspaceEdit(org.eclipse.lsp4j.WorkspaceEdit) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ForkJoinPool(java.util.concurrent.ForkJoinPool) CodeActionKind(org.eclipse.lsp4j.CodeActionKind) Comparator(java.util.Comparator) Collections(java.util.Collections) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Diagnostic(org.eclipse.lsp4j.Diagnostic) InnovationContext(org.eclipse.jdt.ls.core.internal.corrections.InnovationContext) ChangeCorrectionProposal(org.eclipse.jdt.ls.core.internal.corrections.proposals.ChangeCorrectionProposal) IProblemLocationCore(org.eclipse.jdt.internal.ui.text.correction.IProblemLocationCore) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CoreException(org.eclipse.core.runtime.CoreException) CoreException(org.eclipse.core.runtime.CoreException)

Example 69 with Command

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

the class CodeLensHandler method resolve.

public CodeLens resolve(CodeLens lens, IProgressMonitor monitor) {
    if (lens == null) {
        return null;
    }
    // Note that codelens resolution is honored if the request was emitted
    // before disabling codelenses in the preferences, else invalid codeLenses
    // (i.e. having no commands) would be returned.
    final JsonArray data = (JsonArray) lens.getData();
    final String type = JSONUtility.toModel(data.get(2), String.class);
    final Position position = JSONUtility.toModel(data.get(1), Position.class);
    final String uri = JSONUtility.toModel(data.get(0), String.class);
    String label = null;
    String command = null;
    List<Location> locations = null;
    if (REFERENCES_TYPE.equals(type)) {
        label = "reference";
        command = JAVA_SHOW_REFERENCES_COMMAND;
    } else if (IMPLEMENTATION_TYPE.equals(type)) {
        label = "implementation";
        command = JAVA_SHOW_IMPLEMENTATIONS_COMMAND;
    }
    try {
        ITypeRoot typeRoot = JDTUtils.resolveTypeRoot(uri);
        if (typeRoot != null) {
            IJavaElement element = JDTUtils.findElementAtSelection(typeRoot, position.getLine(), position.getCharacter(), this.preferenceManager, monitor);
            if (REFERENCES_TYPE.equals(type)) {
                try {
                    locations = findReferences(element, monitor);
                } catch (CoreException e) {
                    JavaLanguageServerPlugin.logException(e.getMessage(), e);
                }
            } else if (IMPLEMENTATION_TYPE.equals(type)) {
                if (element instanceof IType) {
                    try {
                        IDocument document = JsonRpcHelpers.toDocument(typeRoot.getBuffer());
                        int offset = document.getLineOffset(position.getLine()) + position.getCharacter();
                        locations = findImplementations(typeRoot, (IType) element, offset, monitor);
                    } catch (CoreException | BadLocationException e) {
                        JavaLanguageServerPlugin.logException(e.getMessage(), e);
                    }
                }
            }
        }
    } catch (CoreException e) {
        JavaLanguageServerPlugin.logException("Problem resolving code lens", e);
    }
    if (locations == null) {
        locations = Collections.emptyList();
    }
    if (label != null && command != null) {
        int size = locations.size();
        Command c = new Command(size + " " + label + ((size == 1) ? "" : "s"), command, Arrays.asList(uri, position, locations));
        lens.setCommand(c);
    }
    return lens;
}
Also used : JsonArray(com.google.gson.JsonArray) IJavaElement(org.eclipse.jdt.core.IJavaElement) CoreException(org.eclipse.core.runtime.CoreException) Position(org.eclipse.lsp4j.Position) Command(org.eclipse.lsp4j.Command) ITypeRoot(org.eclipse.jdt.core.ITypeRoot) IDocument(org.eclipse.jface.text.IDocument) Location(org.eclipse.lsp4j.Location) IType(org.eclipse.jdt.core.IType)

Example 70 with Command

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

the class JVMConfigurator method sendNotification.

private static void sendNotification(JavaClientConnection connection, String message) {
    if (connection == null) {
        return;
    }
    PreferenceManager preferencesManager = JavaLanguageServerPlugin.getPreferencesManager();
    if (preferencesManager != null && preferencesManager.getClientPreferences().isActionableRuntimeNotificationSupport()) {
        ActionableNotification runtimeNotification = new ActionableNotification().withSeverity(Severity.error.toMessageType()).withMessage(message).withCommands(Arrays.asList(new Command("Open Settings", "java.runtimeValidation.open", null)));
        connection.sendActionableNotification(runtimeNotification);
        return;
    }
    connection.showNotificationMessage(MessageType.Error, message);
}
Also used : Command(org.eclipse.lsp4j.Command) PreferenceManager(org.eclipse.jdt.ls.core.internal.preferences.PreferenceManager)

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