Search in sources :

Example 11 with InitializeParams

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

the class WorkspaceFoldersTest method testInitialize.

@Test
public void testInitialize() throws Exception {
    File rootFolder1 = temporaryFolder.newFolder("root1");
    File rootFolder2 = temporaryFolder.newFolder("root2");
    writeFile(rootFolder1, "one.testlang", "type Foo { Bar bar }");
    String twoUri = writeFile(rootFolder2, "two.testlang", "type Bar { Foo foo }");
    initialize((InitializeParams it) -> {
        it.setWorkspaceFolders(Lists.newArrayList(new WorkspaceFolder(uriExtensions.toUriString(rootFolder1.toURI()), "root1"), new WorkspaceFolder(uriExtensions.toUriString(rootFolder2.toURI()), "root2")));
    });
    Assert.assertEquals(2, getDiagnostics().size());
    Assert.assertEquals(1, getDiagnostics().get(twoUri).size());
    withBuild(() -> {
        DidChangeWorkspaceFoldersParams didChangeWorkspaceFoldersParams = new DidChangeWorkspaceFoldersParams();
        WorkspaceFoldersChangeEvent workspaceFoldersChangeEvent = new WorkspaceFoldersChangeEvent();
        workspaceFoldersChangeEvent.setRemoved(Lists.newArrayList(new WorkspaceFolder(uriExtensions.toUriString(rootFolder2.toURI()), "root2")));
        didChangeWorkspaceFoldersParams.setEvent(workspaceFoldersChangeEvent);
        languageServer.didChangeWorkspaceFolders(didChangeWorkspaceFoldersParams);
    });
    Assert.assertEquals(0, getDiagnostics().get(twoUri).size());
    withBuild(() -> {
        DidChangeWorkspaceFoldersParams didChangeWorkspaceFoldersParams = new DidChangeWorkspaceFoldersParams();
        WorkspaceFoldersChangeEvent workspaceFoldersChangeEvent = new WorkspaceFoldersChangeEvent();
        workspaceFoldersChangeEvent.setAdded(Lists.newArrayList(new WorkspaceFolder(uriExtensions.toUriString(rootFolder2.toURI()), "root2")));
        didChangeWorkspaceFoldersParams.setEvent(workspaceFoldersChangeEvent);
        languageServer.didChangeWorkspaceFolders(didChangeWorkspaceFoldersParams);
    });
    Assert.assertEquals(1, getDiagnostics().get(twoUri).size());
}
Also used : WorkspaceFoldersChangeEvent(org.eclipse.lsp4j.WorkspaceFoldersChangeEvent) InitializeParams(org.eclipse.lsp4j.InitializeParams) File(java.io.File) DidChangeWorkspaceFoldersParams(org.eclipse.lsp4j.DidChangeWorkspaceFoldersParams) WorkspaceFolder(org.eclipse.lsp4j.WorkspaceFolder) Test(org.junit.Test)

Example 12 with InitializeParams

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

the class AbstractIdeQuickfixTest method quickfixesAreOffered.

private void quickfixesAreOffered(EObject target, String issueCode, String originalText, QuickfixExpectation... expected) {
    List<QuickfixExpectation> expectedSorted = IterableExtensions.sortBy(Arrays.asList(expected), it -> it.label);
    ICompositeNode elementNode = NodeModelUtils.getNode(target);
    LineAndColumn elementStartPosition = NodeModelUtils.getLineAndColumn(elementNode, elementNode.getOffset());
    LineAndColumn elementEndPosition = NodeModelUtils.getLineAndColumn(elementNode, elementNode.getEndOffset());
    Position startPos = new Position(elementStartPosition.getLine() - 1, elementStartPosition.getColumn() - 1);
    Position endPos = new Position(elementEndPosition.getLine() - 1, elementEndPosition.getColumn() - 1);
    Diagnostic issue = new Diagnostic();
    issue.setCode(issueCode);
    issue.setMessage("error");
    issue.setSeverity(DiagnosticSeverity.Error);
    issue.setSource("source");
    issue.setRange(new Range(startPos, endPos));
    ICodeActionService2.Options options = new ICodeActionService2.Options();
    options.setCancelIndicator(CancelIndicator.NullImpl);
    options.setDocument(new Document(Integer.valueOf(0), originalText));
    options.setResource((XtextResource) target.eResource());
    options.setLanguageServerAccess(new ILanguageServerAccess() {

        @Override
        public void addBuildListener(ILanguageServerAccess.IBuildListener listener) {
            throw new UnsupportedOperationException();
        }

        @Override
        public <T extends Object> CompletableFuture<T> doRead(String uri, Function<ILanguageServerAccess.Context, T> function) {
            ILanguageServerAccess.Context ctx = new ILanguageServerAccess.Context(options.getResource(), options.getDocument(), true, CancelIndicator.NullImpl);
            return CompletableFuture.completedFuture(function.apply(ctx));
        }

        @Override
        public <T extends Object> CompletableFuture<T> doReadIndex(Function<? super ILanguageServerAccess.IndexContext, ? extends T> function) {
            return null;
        }

        @Override
        public InitializeParams getInitializeParams() {
            return null;
        }

        @Override
        public InitializeResult getInitializeResult() {
            return null;
        }

        @Override
        public LanguageClient getLanguageClient() {
            return null;
        }

        @Override
        public ResourceSet newLiveScopeResourceSet(URI uri) {
            // re-using the existing ResourceSet because it contains the URI protocol mapping for "inmemory" resources.
            ResourceSet resourceSet = options.getResource().getResourceSet();
            return resourceSet;
        }
    });
    CodeActionParams codeActionParams = new CodeActionParams();
    codeActionParams.setRange(new Range(startPos, endPos));
    codeActionParams.setTextDocument(new TextDocumentIdentifier(target.eResource().getURI().toString()));
    CodeActionContext codeActionContext = new CodeActionContext();
    codeActionContext.setDiagnostics(Collections.singletonList(issue));
    codeActionParams.setContext(codeActionContext);
    options.setCodeActionParams(codeActionParams);
    List<DiagnosticResolution> actualIssueResolutions = IterableExtensions.sortBy(quickFixProvider.getResolutions(options, issue), DiagnosticResolution::getLabel);
    assertEquals("The number of quickfixes does not match!", expectedSorted.size(), actualIssueResolutions.size());
    for (int i = 0; i < actualIssueResolutions.size(); i++) {
        DiagnosticResolution actualIssueResolution = actualIssueResolutions.get(i);
        QuickfixExpectation expectedIssueResolution = expectedSorted.get(i);
        assertEquals(expectedIssueResolution.label, actualIssueResolution.getLabel());
        assertEquals(expectedIssueResolution.description, actualIssueResolution.getLabel());
        assertIssueResolutionResult(toUnixLineSeparator(expectedIssueResolution.getExpectedResult()), actualIssueResolution, originalText, options.getDocument());
    }
}
Also used : TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) DiagnosticResolution(org.eclipse.xtext.ide.editor.quickfix.DiagnosticResolution) Diagnostic(org.eclipse.lsp4j.Diagnostic) Document(org.eclipse.xtext.ide.server.Document) URI(org.eclipse.emf.common.util.URI) CompletableFuture(java.util.concurrent.CompletableFuture) LanguageClient(org.eclipse.lsp4j.services.LanguageClient) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) ILanguageServerAccess(org.eclipse.xtext.ide.server.ILanguageServerAccess) CodeActionContext(org.eclipse.lsp4j.CodeActionContext) CodeActionParams(org.eclipse.lsp4j.CodeActionParams) Position(org.eclipse.lsp4j.Position) ICodeActionService2(org.eclipse.xtext.ide.server.codeActions.ICodeActionService2) InitializeParams(org.eclipse.lsp4j.InitializeParams) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) LineAndColumn(org.eclipse.xtext.util.LineAndColumn) Range(org.eclipse.lsp4j.Range) InitializeResult(org.eclipse.lsp4j.InitializeResult) CodeActionContext(org.eclipse.lsp4j.CodeActionContext)

Example 13 with InitializeParams

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

the class PrepareRenameTest method initializeWithPrepareSupport.

private InitializeResult initializeWithPrepareSupport() {
    return super.initialize((InitializeParams params) -> {
        ClientCapabilities clientCapabilities = new ClientCapabilities();
        WorkspaceClientCapabilities workspaceClientCapabilities = new WorkspaceClientCapabilities();
        clientCapabilities.setWorkspace(workspaceClientCapabilities);
        TextDocumentClientCapabilities textDocumentClientCapabilities = new TextDocumentClientCapabilities();
        textDocumentClientCapabilities.setRename(new RenameCapabilities(true, false));
        clientCapabilities.setTextDocument(textDocumentClientCapabilities);
        params.setCapabilities(clientCapabilities);
    });
}
Also used : WorkspaceClientCapabilities(org.eclipse.lsp4j.WorkspaceClientCapabilities) RenameCapabilities(org.eclipse.lsp4j.RenameCapabilities) WorkspaceClientCapabilities(org.eclipse.lsp4j.WorkspaceClientCapabilities) TextDocumentClientCapabilities(org.eclipse.lsp4j.TextDocumentClientCapabilities) ClientCapabilities(org.eclipse.lsp4j.ClientCapabilities) InitializeParams(org.eclipse.lsp4j.InitializeParams) TextDocumentClientCapabilities(org.eclipse.lsp4j.TextDocumentClientCapabilities)

Example 14 with InitializeParams

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

the class LanguageServerImpl method initialize.

@Override
public CompletableFuture<InitializeResult> initialize(InitializeParams params) {
    if (initializeParams != null) {
        throw new IllegalStateException("This language server has already been initialized.");
    }
    URI baseDir = getBaseDir(params);
    if (languagesRegistry.getExtensionToFactoryMap().isEmpty()) {
        throw new IllegalStateException("No Xtext languages have been registered. Please make sure you have added the languages\'s setup class in \'/META-INF/services/org.eclipse.xtext.ISetup\'");
    }
    initializeParams = params;
    InitializeResult result = new InitializeResult();
    result.setCapabilities(createServerCapabilities(params));
    access.addBuildListener(this);
    return requestManager.runWrite(() -> {
        if (workspaceManager.isSupportsWorkspaceFolders()) {
            List<WorkspaceFolder> workspaceFolders = params.getWorkspaceFolders();
            if (workspaceFolders == null)
                workspaceFolders = Collections.emptyList();
            workspaceManager.initialize(workspaceFolders, this::publishDiagnostics, CancelIndicator.NullImpl);
        } else {
            workspaceManager.initialize(baseDir, this::publishDiagnostics, CancelIndicator.NullImpl);
        }
        return result;
    }, (cancelIndicator, it) -> it).thenApply(it -> initializeResult = it);
}
Also used : Arrays(java.util.Arrays) CodeLensOptions(org.eclipse.lsp4j.CodeLensOptions) DidChangeTextDocumentParams(org.eclipse.lsp4j.DidChangeTextDocumentParams) WorkspaceSymbolParams(org.eclipse.lsp4j.WorkspaceSymbolParams) LanguageServer(org.eclipse.lsp4j.services.LanguageServer) DidSaveTextDocumentParams(org.eclipse.lsp4j.DidSaveTextDocumentParams) PublishDiagnosticsParams(org.eclipse.lsp4j.PublishDiagnosticsParams) Map(java.util.Map) RenameParams(org.eclipse.lsp4j.RenameParams) Endpoint(org.eclipse.lsp4j.jsonrpc.Endpoint) IRenameService2(org.eclipse.xtext.ide.server.rename.IRenameService2) TextDocumentService(org.eclipse.lsp4j.services.TextDocumentService) DiagnosticSeverity(org.eclipse.lsp4j.DiagnosticSeverity) SignatureHelpOptions(org.eclipse.lsp4j.SignatureHelpOptions) ISignatureHelpService(org.eclipse.xtext.ide.server.signatureHelp.ISignatureHelpService) Set(java.util.Set) DocumentOnTypeFormattingParams(org.eclipse.lsp4j.DocumentOnTypeFormattingParams) WorkspaceService(org.eclipse.lsp4j.services.WorkspaceService) LocationLink(org.eclipse.lsp4j.LocationLink) FormattingService(org.eclipse.xtext.ide.server.formatting.FormattingService) ExecuteCommandOptions(org.eclipse.lsp4j.ExecuteCommandOptions) ResourceDescriptionsProvider(org.eclipse.xtext.resource.impl.ResourceDescriptionsProvider) JsonRpcMethod(org.eclipse.lsp4j.jsonrpc.json.JsonRpcMethod) WorkspaceFolder(org.eclipse.lsp4j.WorkspaceFolder) FoldingRange(org.eclipse.lsp4j.FoldingRange) ContentAssistService(org.eclipse.xtext.ide.server.contentassist.ContentAssistService) Pair(org.eclipse.xtext.xbase.lib.Pair) LanguageClientAware(org.eclipse.lsp4j.services.LanguageClientAware) URI(org.eclipse.emf.common.util.URI) IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) HierarchicalDocumentSymbolService(org.eclipse.xtext.ide.server.symbol.HierarchicalDocumentSymbolService) HoverParams(org.eclipse.lsp4j.HoverParams) Diagnostic(org.eclipse.lsp4j.Diagnostic) Supplier(java.util.function.Supplier) DocumentRangeFormattingParams(org.eclipse.lsp4j.DocumentRangeFormattingParams) Hover(org.eclipse.lsp4j.Hover) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) ArrayList(java.util.ArrayList) IHoverService(org.eclipse.xtext.ide.server.hover.IHoverService) LinkedHashMap(java.util.LinkedHashMap) FileChangeType(org.eclipse.lsp4j.FileChangeType) TextDocumentItem(org.eclipse.lsp4j.TextDocumentItem) TextEdit(org.eclipse.lsp4j.TextEdit) Lists(com.google.common.collect.Lists) DocumentFormattingParams(org.eclipse.lsp4j.DocumentFormattingParams) VersionedTextDocumentIdentifier(org.eclipse.lsp4j.VersionedTextDocumentIdentifier) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) InitializeResult(org.eclipse.lsp4j.InitializeResult) DocumentHighlight(org.eclipse.lsp4j.DocumentHighlight) ServiceEndpoints(org.eclipse.lsp4j.jsonrpc.services.ServiceEndpoints) DidChangeWatchedFilesParams(org.eclipse.lsp4j.DidChangeWatchedFilesParams) DocumentHighlightParams(org.eclipse.lsp4j.DocumentHighlightParams) PrepareRenameResult(org.eclipse.lsp4j.PrepareRenameResult) ICodeActionService2(org.eclipse.xtext.ide.server.codeActions.ICodeActionService2) SignatureHelp(org.eclipse.lsp4j.SignatureHelp) TreeMap(java.util.TreeMap) WorkspaceEdit(org.eclipse.lsp4j.WorkspaceEdit) Issue(org.eclipse.xtext.validation.Issue) RenameOptions(org.eclipse.lsp4j.RenameOptions) DocumentSymbolService(org.eclipse.xtext.ide.server.symbol.DocumentSymbolService) CompletionOptions(org.eclipse.lsp4j.CompletionOptions) IBuildListener(org.eclipse.xtext.ide.server.ILanguageServerAccess.IBuildListener) SignatureHelpParams(org.eclipse.lsp4j.SignatureHelpParams) ClientCapabilities(org.eclipse.lsp4j.ClientCapabilities) BufferedCancelIndicator(org.eclipse.xtext.util.BufferedCancelIndicator) LanguageClient(org.eclipse.lsp4j.services.LanguageClient) Inject(com.google.inject.Inject) WorkspaceClientCapabilities(org.eclipse.lsp4j.WorkspaceClientCapabilities) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) ICodeLensService(org.eclipse.xtext.ide.server.codelens.ICodeLensService) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) FoldingRangeRequestParams(org.eclipse.lsp4j.FoldingRangeRequestParams) Logger(org.apache.log4j.Logger) CodeLens(org.eclipse.lsp4j.CodeLens) DidChangeWorkspaceFoldersParams(org.eclipse.lsp4j.DidChangeWorkspaceFoldersParams) IReferenceFinder(org.eclipse.xtext.findReferences.IReferenceFinder) Location(org.eclipse.lsp4j.Location) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) TextDocumentClientCapabilities(org.eclipse.lsp4j.TextDocumentClientCapabilities) DidCloseTextDocumentParams(org.eclipse.lsp4j.DidCloseTextDocumentParams) Objects(com.google.common.base.Objects) CodeAction(org.eclipse.lsp4j.CodeAction) LinkedListMultimap(com.google.common.collect.LinkedListMultimap) TextDocumentPositionParams(org.eclipse.lsp4j.TextDocumentPositionParams) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) IDocumentSymbolService(org.eclipse.xtext.ide.server.symbol.IDocumentSymbolService) PrepareRenameParams(org.eclipse.lsp4j.PrepareRenameParams) ICodeLensResolver(org.eclipse.xtext.ide.server.codelens.ICodeLensResolver) FoldingRangeService(org.eclipse.xtext.ide.server.folding.FoldingRangeService) DefinitionParams(org.eclipse.lsp4j.DefinitionParams) ServerCapabilities(org.eclipse.lsp4j.ServerCapabilities) CompletionItem(org.eclipse.lsp4j.CompletionItem) RenameCapabilities(org.eclipse.lsp4j.RenameCapabilities) List(java.util.List) Command(org.eclipse.lsp4j.Command) IDocumentHighlightService(org.eclipse.xtext.ide.server.occurrences.IDocumentHighlightService) WorkspaceSymbolService(org.eclipse.xtext.ide.server.symbol.WorkspaceSymbolService) DidOpenTextDocumentParams(org.eclipse.lsp4j.DidOpenTextDocumentParams) InitializeParams(org.eclipse.lsp4j.InitializeParams) WorkspaceFoldersOptions(org.eclipse.lsp4j.WorkspaceFoldersOptions) Buildable(org.eclipse.xtext.ide.server.BuildManager.Buildable) CompletionParams(org.eclipse.lsp4j.CompletionParams) DocumentSymbolParams(org.eclipse.lsp4j.DocumentSymbolParams) CompletableFuture(java.util.concurrent.CompletableFuture) Range(org.eclipse.lsp4j.Range) DocumentSymbolCapabilities(org.eclipse.lsp4j.DocumentSymbolCapabilities) Multimap(com.google.common.collect.Multimap) Function(java.util.function.Function) SymbolInformation(org.eclipse.lsp4j.SymbolInformation) CodeActionParams(org.eclipse.lsp4j.CodeActionParams) ExecuteCommandCapabilities(org.eclipse.lsp4j.ExecuteCommandCapabilities) ImmutableList(com.google.common.collect.ImmutableList) ExecuteCommandParams(org.eclipse.lsp4j.ExecuteCommandParams) CancelIndicator(org.eclipse.xtext.util.CancelIndicator) Position(org.eclipse.lsp4j.Position) CodeLensParams(org.eclipse.lsp4j.CodeLensParams) CompletionList(org.eclipse.lsp4j.CompletionList) DidChangeConfigurationParams(org.eclipse.lsp4j.DidChangeConfigurationParams) TextDocumentSyncKind(org.eclipse.lsp4j.TextDocumentSyncKind) InitializedParams(org.eclipse.lsp4j.InitializedParams) Severity(org.eclipse.xtext.diagnostics.Severity) FoldingRangeCapabilities(org.eclipse.lsp4j.FoldingRangeCapabilities) WorkspaceServerCapabilities(org.eclipse.lsp4j.WorkspaceServerCapabilities) ExecutableCommandRegistry(org.eclipse.xtext.ide.server.commands.ExecutableCommandRegistry) JsonRpcMethodProvider(org.eclipse.lsp4j.jsonrpc.json.JsonRpcMethodProvider) RequestManager(org.eclipse.xtext.ide.server.concurrent.RequestManager) WorkspaceResourceAccess(org.eclipse.xtext.ide.server.findReferences.WorkspaceResourceAccess) Collections(java.util.Collections) DocumentSymbol(org.eclipse.lsp4j.DocumentSymbol) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) ReferenceParams(org.eclipse.lsp4j.ReferenceParams) InitializeResult(org.eclipse.lsp4j.InitializeResult) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) CompletionList(org.eclipse.lsp4j.CompletionList) URI(org.eclipse.emf.common.util.URI)

Example 15 with InitializeParams

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

the class LanguageServerImpl method createServerCapabilities.

/**
 * Configure the server capabilities for this instance.
 *
 * @param params
 *            the initialization parametrs
 * @return the server capabilities
 * @since 2.20
 */
protected ServerCapabilities createServerCapabilities(InitializeParams params) {
    ServerCapabilities serverCapabilities = new ServerCapabilities();
    serverCapabilities.setHoverProvider(true);
    serverCapabilities.setDefinitionProvider(true);
    serverCapabilities.setReferencesProvider(true);
    serverCapabilities.setDocumentSymbolProvider(true);
    serverCapabilities.setWorkspaceSymbolProvider(true);
    Set<? extends IResourceServiceProvider> allLanguages = getAllLanguages();
    if (allLanguages.stream().anyMatch((serviceProvider) -> serviceProvider.get(ICodeLensService.class) != null)) {
        CodeLensOptions codeLensOptions = new CodeLensOptions();
        codeLensOptions.setResolveProvider(allLanguages.stream().anyMatch((serviceProvider) -> serviceProvider.get(ICodeLensResolver.class) != null));
        serverCapabilities.setCodeLensProvider(codeLensOptions);
    }
    serverCapabilities.setCodeActionProvider(allLanguages.stream().anyMatch((serviceProvider) -> serviceProvider.get(ICodeActionService2.class) != null));
    serverCapabilities.setSignatureHelpProvider(new SignatureHelpOptions(ImmutableList.of("(", ",")));
    serverCapabilities.setTextDocumentSync(TextDocumentSyncKind.Incremental);
    CompletionOptions completionOptions = new CompletionOptions();
    completionOptions.setResolveProvider(false);
    completionOptions.setTriggerCharacters(ImmutableList.of("."));
    serverCapabilities.setCompletionProvider(completionOptions);
    serverCapabilities.setDocumentFormattingProvider(true);
    serverCapabilities.setDocumentRangeFormattingProvider(true);
    serverCapabilities.setDocumentHighlightProvider(true);
    ClientCapabilities clientCapabilities = null;
    if (params != null) {
        clientCapabilities = params.getCapabilities();
    }
    TextDocumentClientCapabilities textDocument = null;
    if (clientCapabilities != null) {
        textDocument = clientCapabilities.getTextDocument();
    }
    RenameCapabilities rename = null;
    FoldingRangeCapabilities folding = null;
    if (textDocument != null) {
        rename = textDocument.getRename();
        folding = textDocument.getFoldingRange();
    }
    if (folding != null) {
        serverCapabilities.setFoldingRangeProvider(allLanguages.stream().anyMatch(serviceProvider -> serviceProvider.get(FoldingRangeService.class) != null));
    }
    Boolean prepareSupport = null;
    if (rename != null) {
        prepareSupport = rename.getPrepareSupport();
    }
    boolean clientPrepareSupport = Objects.equal(Boolean.TRUE, prepareSupport);
    if (clientPrepareSupport && allLanguages.stream().anyMatch(serviceProvider -> serviceProvider.get(IRenameService2.class) != null)) {
        RenameOptions renameOptions = new RenameOptions();
        renameOptions.setPrepareProvider(true);
        serverCapabilities.setRenameProvider(Either.<Boolean, RenameOptions>forRight(renameOptions));
    } else {
        serverCapabilities.setRenameProvider(Either.forLeft(allLanguages.stream().anyMatch((serviceProvider) -> serviceProvider.get(IRenameService2.class) != null)));
    }
    WorkspaceClientCapabilities workspace = null;
    if (clientCapabilities != null) {
        workspace = clientCapabilities.getWorkspace();
    }
    ExecuteCommandCapabilities executeCommand = null;
    if (workspace != null) {
        executeCommand = workspace.getExecuteCommand();
        if (workspace.getWorkspaceFolders() == Boolean.TRUE && workspaceManager.isSupportsWorkspaceFolders()) {
            WorkspaceFoldersOptions workspaceFoldersOptions = new WorkspaceFoldersOptions();
            workspaceFoldersOptions.setSupported(true);
            workspaceFoldersOptions.setChangeNotifications(true);
            serverCapabilities.setWorkspace(new WorkspaceServerCapabilities(workspaceFoldersOptions));
        }
    }
    if (executeCommand != null) {
        commandRegistry.initialize(allLanguages, clientCapabilities, client);
        ExecuteCommandOptions executeCommandOptions = new ExecuteCommandOptions();
        executeCommandOptions.setCommands(commandRegistry.getCommands());
        serverCapabilities.setExecuteCommandProvider(executeCommandOptions);
    }
    for (IResourceServiceProvider language : allLanguages) {
        ICapabilitiesContributor capabilitiesContributor = language.get(ICapabilitiesContributor.class);
        if (capabilitiesContributor != null) {
            capabilitiesContributor.contribute(serverCapabilities, params);
        }
    }
    return serverCapabilities;
}
Also used : Arrays(java.util.Arrays) CodeLensOptions(org.eclipse.lsp4j.CodeLensOptions) DidChangeTextDocumentParams(org.eclipse.lsp4j.DidChangeTextDocumentParams) WorkspaceSymbolParams(org.eclipse.lsp4j.WorkspaceSymbolParams) LanguageServer(org.eclipse.lsp4j.services.LanguageServer) DidSaveTextDocumentParams(org.eclipse.lsp4j.DidSaveTextDocumentParams) PublishDiagnosticsParams(org.eclipse.lsp4j.PublishDiagnosticsParams) Map(java.util.Map) RenameParams(org.eclipse.lsp4j.RenameParams) Endpoint(org.eclipse.lsp4j.jsonrpc.Endpoint) IRenameService2(org.eclipse.xtext.ide.server.rename.IRenameService2) TextDocumentService(org.eclipse.lsp4j.services.TextDocumentService) DiagnosticSeverity(org.eclipse.lsp4j.DiagnosticSeverity) SignatureHelpOptions(org.eclipse.lsp4j.SignatureHelpOptions) ISignatureHelpService(org.eclipse.xtext.ide.server.signatureHelp.ISignatureHelpService) Set(java.util.Set) DocumentOnTypeFormattingParams(org.eclipse.lsp4j.DocumentOnTypeFormattingParams) WorkspaceService(org.eclipse.lsp4j.services.WorkspaceService) LocationLink(org.eclipse.lsp4j.LocationLink) FormattingService(org.eclipse.xtext.ide.server.formatting.FormattingService) ExecuteCommandOptions(org.eclipse.lsp4j.ExecuteCommandOptions) ResourceDescriptionsProvider(org.eclipse.xtext.resource.impl.ResourceDescriptionsProvider) JsonRpcMethod(org.eclipse.lsp4j.jsonrpc.json.JsonRpcMethod) WorkspaceFolder(org.eclipse.lsp4j.WorkspaceFolder) FoldingRange(org.eclipse.lsp4j.FoldingRange) ContentAssistService(org.eclipse.xtext.ide.server.contentassist.ContentAssistService) Pair(org.eclipse.xtext.xbase.lib.Pair) LanguageClientAware(org.eclipse.lsp4j.services.LanguageClientAware) URI(org.eclipse.emf.common.util.URI) IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) HierarchicalDocumentSymbolService(org.eclipse.xtext.ide.server.symbol.HierarchicalDocumentSymbolService) HoverParams(org.eclipse.lsp4j.HoverParams) Diagnostic(org.eclipse.lsp4j.Diagnostic) Supplier(java.util.function.Supplier) DocumentRangeFormattingParams(org.eclipse.lsp4j.DocumentRangeFormattingParams) Hover(org.eclipse.lsp4j.Hover) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) ArrayList(java.util.ArrayList) IHoverService(org.eclipse.xtext.ide.server.hover.IHoverService) LinkedHashMap(java.util.LinkedHashMap) FileChangeType(org.eclipse.lsp4j.FileChangeType) TextDocumentItem(org.eclipse.lsp4j.TextDocumentItem) TextEdit(org.eclipse.lsp4j.TextEdit) Lists(com.google.common.collect.Lists) DocumentFormattingParams(org.eclipse.lsp4j.DocumentFormattingParams) VersionedTextDocumentIdentifier(org.eclipse.lsp4j.VersionedTextDocumentIdentifier) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) InitializeResult(org.eclipse.lsp4j.InitializeResult) DocumentHighlight(org.eclipse.lsp4j.DocumentHighlight) ServiceEndpoints(org.eclipse.lsp4j.jsonrpc.services.ServiceEndpoints) DidChangeWatchedFilesParams(org.eclipse.lsp4j.DidChangeWatchedFilesParams) DocumentHighlightParams(org.eclipse.lsp4j.DocumentHighlightParams) PrepareRenameResult(org.eclipse.lsp4j.PrepareRenameResult) ICodeActionService2(org.eclipse.xtext.ide.server.codeActions.ICodeActionService2) SignatureHelp(org.eclipse.lsp4j.SignatureHelp) TreeMap(java.util.TreeMap) WorkspaceEdit(org.eclipse.lsp4j.WorkspaceEdit) Issue(org.eclipse.xtext.validation.Issue) RenameOptions(org.eclipse.lsp4j.RenameOptions) DocumentSymbolService(org.eclipse.xtext.ide.server.symbol.DocumentSymbolService) CompletionOptions(org.eclipse.lsp4j.CompletionOptions) IBuildListener(org.eclipse.xtext.ide.server.ILanguageServerAccess.IBuildListener) SignatureHelpParams(org.eclipse.lsp4j.SignatureHelpParams) ClientCapabilities(org.eclipse.lsp4j.ClientCapabilities) BufferedCancelIndicator(org.eclipse.xtext.util.BufferedCancelIndicator) LanguageClient(org.eclipse.lsp4j.services.LanguageClient) Inject(com.google.inject.Inject) WorkspaceClientCapabilities(org.eclipse.lsp4j.WorkspaceClientCapabilities) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) ICodeLensService(org.eclipse.xtext.ide.server.codelens.ICodeLensService) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) FoldingRangeRequestParams(org.eclipse.lsp4j.FoldingRangeRequestParams) Logger(org.apache.log4j.Logger) CodeLens(org.eclipse.lsp4j.CodeLens) DidChangeWorkspaceFoldersParams(org.eclipse.lsp4j.DidChangeWorkspaceFoldersParams) IReferenceFinder(org.eclipse.xtext.findReferences.IReferenceFinder) Location(org.eclipse.lsp4j.Location) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) TextDocumentClientCapabilities(org.eclipse.lsp4j.TextDocumentClientCapabilities) DidCloseTextDocumentParams(org.eclipse.lsp4j.DidCloseTextDocumentParams) Objects(com.google.common.base.Objects) CodeAction(org.eclipse.lsp4j.CodeAction) LinkedListMultimap(com.google.common.collect.LinkedListMultimap) TextDocumentPositionParams(org.eclipse.lsp4j.TextDocumentPositionParams) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) IDocumentSymbolService(org.eclipse.xtext.ide.server.symbol.IDocumentSymbolService) PrepareRenameParams(org.eclipse.lsp4j.PrepareRenameParams) ICodeLensResolver(org.eclipse.xtext.ide.server.codelens.ICodeLensResolver) FoldingRangeService(org.eclipse.xtext.ide.server.folding.FoldingRangeService) DefinitionParams(org.eclipse.lsp4j.DefinitionParams) ServerCapabilities(org.eclipse.lsp4j.ServerCapabilities) CompletionItem(org.eclipse.lsp4j.CompletionItem) RenameCapabilities(org.eclipse.lsp4j.RenameCapabilities) List(java.util.List) Command(org.eclipse.lsp4j.Command) IDocumentHighlightService(org.eclipse.xtext.ide.server.occurrences.IDocumentHighlightService) WorkspaceSymbolService(org.eclipse.xtext.ide.server.symbol.WorkspaceSymbolService) DidOpenTextDocumentParams(org.eclipse.lsp4j.DidOpenTextDocumentParams) InitializeParams(org.eclipse.lsp4j.InitializeParams) WorkspaceFoldersOptions(org.eclipse.lsp4j.WorkspaceFoldersOptions) Buildable(org.eclipse.xtext.ide.server.BuildManager.Buildable) CompletionParams(org.eclipse.lsp4j.CompletionParams) DocumentSymbolParams(org.eclipse.lsp4j.DocumentSymbolParams) CompletableFuture(java.util.concurrent.CompletableFuture) Range(org.eclipse.lsp4j.Range) DocumentSymbolCapabilities(org.eclipse.lsp4j.DocumentSymbolCapabilities) Multimap(com.google.common.collect.Multimap) Function(java.util.function.Function) SymbolInformation(org.eclipse.lsp4j.SymbolInformation) CodeActionParams(org.eclipse.lsp4j.CodeActionParams) ExecuteCommandCapabilities(org.eclipse.lsp4j.ExecuteCommandCapabilities) ImmutableList(com.google.common.collect.ImmutableList) ExecuteCommandParams(org.eclipse.lsp4j.ExecuteCommandParams) CancelIndicator(org.eclipse.xtext.util.CancelIndicator) Position(org.eclipse.lsp4j.Position) CodeLensParams(org.eclipse.lsp4j.CodeLensParams) CompletionList(org.eclipse.lsp4j.CompletionList) DidChangeConfigurationParams(org.eclipse.lsp4j.DidChangeConfigurationParams) TextDocumentSyncKind(org.eclipse.lsp4j.TextDocumentSyncKind) InitializedParams(org.eclipse.lsp4j.InitializedParams) Severity(org.eclipse.xtext.diagnostics.Severity) FoldingRangeCapabilities(org.eclipse.lsp4j.FoldingRangeCapabilities) WorkspaceServerCapabilities(org.eclipse.lsp4j.WorkspaceServerCapabilities) ExecutableCommandRegistry(org.eclipse.xtext.ide.server.commands.ExecutableCommandRegistry) JsonRpcMethodProvider(org.eclipse.lsp4j.jsonrpc.json.JsonRpcMethodProvider) RequestManager(org.eclipse.xtext.ide.server.concurrent.RequestManager) WorkspaceResourceAccess(org.eclipse.xtext.ide.server.findReferences.WorkspaceResourceAccess) Collections(java.util.Collections) DocumentSymbol(org.eclipse.lsp4j.DocumentSymbol) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) ReferenceParams(org.eclipse.lsp4j.ReferenceParams) ICodeLensResolver(org.eclipse.xtext.ide.server.codelens.ICodeLensResolver) RenameOptions(org.eclipse.lsp4j.RenameOptions) RenameCapabilities(org.eclipse.lsp4j.RenameCapabilities) ICodeActionService2(org.eclipse.xtext.ide.server.codeActions.ICodeActionService2) ClientCapabilities(org.eclipse.lsp4j.ClientCapabilities) WorkspaceClientCapabilities(org.eclipse.lsp4j.WorkspaceClientCapabilities) TextDocumentClientCapabilities(org.eclipse.lsp4j.TextDocumentClientCapabilities) TextDocumentClientCapabilities(org.eclipse.lsp4j.TextDocumentClientCapabilities) WorkspaceFoldersOptions(org.eclipse.lsp4j.WorkspaceFoldersOptions) FoldingRangeService(org.eclipse.xtext.ide.server.folding.FoldingRangeService) WorkspaceServerCapabilities(org.eclipse.lsp4j.WorkspaceServerCapabilities) CompletionOptions(org.eclipse.lsp4j.CompletionOptions) WorkspaceClientCapabilities(org.eclipse.lsp4j.WorkspaceClientCapabilities) SignatureHelpOptions(org.eclipse.lsp4j.SignatureHelpOptions) IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) FoldingRangeCapabilities(org.eclipse.lsp4j.FoldingRangeCapabilities) IRenameService2(org.eclipse.xtext.ide.server.rename.IRenameService2) ServerCapabilities(org.eclipse.lsp4j.ServerCapabilities) WorkspaceServerCapabilities(org.eclipse.lsp4j.WorkspaceServerCapabilities) CodeLensOptions(org.eclipse.lsp4j.CodeLensOptions) ExecuteCommandCapabilities(org.eclipse.lsp4j.ExecuteCommandCapabilities) ExecuteCommandOptions(org.eclipse.lsp4j.ExecuteCommandOptions)

Aggregations

InitializeParams (org.eclipse.lsp4j.InitializeParams)19 ClientCapabilities (org.eclipse.lsp4j.ClientCapabilities)11 TextDocumentClientCapabilities (org.eclipse.lsp4j.TextDocumentClientCapabilities)9 WorkspaceClientCapabilities (org.eclipse.lsp4j.WorkspaceClientCapabilities)8 InitializeResult (org.eclipse.lsp4j.InitializeResult)7 RenameCapabilities (org.eclipse.lsp4j.RenameCapabilities)6 ExecuteCommandCapabilities (org.eclipse.lsp4j.ExecuteCommandCapabilities)5 WorkspaceFolder (org.eclipse.lsp4j.WorkspaceFolder)5 File (java.io.File)4 CompletableFuture (java.util.concurrent.CompletableFuture)4 Range (org.eclipse.lsp4j.Range)4 TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)4 ArrayList (java.util.ArrayList)3 URI (org.eclipse.emf.common.util.URI)3 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)3 CodeActionParams (org.eclipse.lsp4j.CodeActionParams)3 Diagnostic (org.eclipse.lsp4j.Diagnostic)3 DidChangeWorkspaceFoldersParams (org.eclipse.lsp4j.DidChangeWorkspaceFoldersParams)3 DocumentSymbolCapabilities (org.eclipse.lsp4j.DocumentSymbolCapabilities)3 Position (org.eclipse.lsp4j.Position)3