Java Code Examples for org.eclipse.lsp4j.InitializeParams#getCapabilities()
The following examples show how to use
org.eclipse.lsp4j.InitializeParams#getCapabilities() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChangeConverter2.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected ChangeConverter2(IResourceServiceProvider.Registry registry, WorkspaceEdit edit, ILanguageServerAccess access, UriExtensions uriExtensions) { this.registry = registry; this.uriExtensions = uriExtensions; this.edit = edit; this.access = access; Boolean documentChanges = null; if (access != null) { InitializeParams initializeParams = access.getInitializeParams(); if (initializeParams != null) { ClientCapabilities clientCapabilities = initializeParams.getCapabilities(); if (clientCapabilities != null) { WorkspaceClientCapabilities workspaceClientCapabilities = clientCapabilities.getWorkspace(); if (workspaceClientCapabilities != null) { WorkspaceEditCapabilities workspaceEditCapabilities = workspaceClientCapabilities .getWorkspaceEdit(); if (workspaceEditCapabilities != null) { documentChanges = workspaceEditCapabilities.getDocumentChanges(); } } } } } this.useDocumentChanges = documentChanges == Boolean.TRUE; if (this.useDocumentChanges) { this.edit.setDocumentChanges(new ArrayList<>()); } else { this.edit.setChanges(new LinkedHashMap<>()); } }
Example 2
Source File: XLanguageServerImpl.java From n4js with Eclipse Public License 1.0 | 4 votes |
/** * Configure the server capabilities for this instance. * * @param params * the initialization parameters * @return the server capabilities */ 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); } boolean supportsCodeActions = allLanguages.stream() .anyMatch((serviceProvider) -> serviceProvider.get(ICodeActionService.class) != null || serviceProvider.get(ICodeActionService2.class) != null); if (supportsCodeActions) { Optional<List<String>> supportedKinds = getSupportedCodeActionKinds(); if (supportedKinds.isPresent()) { serverCapabilities.setCodeActionProvider(new CodeActionOptions(supportedKinds.get())); } else { serverCapabilities.setCodeActionProvider(true); } } else { serverCapabilities.setCodeActionProvider(false); } 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; if (textDocument != null) { rename = textDocument.getRename(); } 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(IRenameService.class) != null || serviceProvider.get(IRenameService2.class) != null))); } WorkspaceClientCapabilities workspace = null; if (clientCapabilities != null) { workspace = clientCapabilities.getWorkspace(); } ExecuteCommandCapabilities executeCommand = null; if (workspace != null) { executeCommand = workspace.getExecuteCommand(); } if (executeCommand != null) { commandRegistry.initialize(allLanguages, clientCapabilities, client); ExecuteCommandOptions executeCommandOptions = new ExecuteCommandOptions(); executeCommandOptions.setCommands(commandRegistry.getCommands()); serverCapabilities.setExecuteCommandProvider(executeCommandOptions); } semanticHighlightingRegistry.initialize(allLanguages, clientCapabilities, client); serverCapabilities.setSemanticHighlighting(new SemanticHighlightingServerCapabilities( semanticHighlightingRegistry.getAllScopes())); for (IResourceServiceProvider language : allLanguages) { ICapabilitiesContributor capabilitiesContributor = language.get(ICapabilitiesContributor.class); if (capabilitiesContributor != null) { capabilitiesContributor.contribute(serverCapabilities, params); } } return serverCapabilities; }
Example 3
Source File: AbstractLanguageServerTest.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
protected InitializeResult initialize(final Procedure1<? super InitializeParams> initializer, final boolean callInitialized) { try { InitializeParams _initializeParams = new InitializeParams(); final Procedure1<InitializeParams> _function = (InitializeParams it) -> { it.setProcessId(Integer.valueOf(1)); it.setRootUri(this._uriExtensions.toUriString(this.root.toURI().normalize())); String _rootUri = it.getRootUri(); WorkspaceFolder _workspaceFolder = new WorkspaceFolder(_rootUri, ""); it.setWorkspaceFolders(Collections.<WorkspaceFolder>unmodifiableList(CollectionLiterals.<WorkspaceFolder>newArrayList(_workspaceFolder))); }; final InitializeParams params = ObjectExtensions.<InitializeParams>operator_doubleArrow(_initializeParams, _function); if (initializer!=null) { initializer.apply(params); } Boolean _elvis = null; ClientCapabilities _capabilities = params.getCapabilities(); TextDocumentClientCapabilities _textDocument = null; if (_capabilities!=null) { _textDocument=_capabilities.getTextDocument(); } DocumentSymbolCapabilities _documentSymbol = null; if (_textDocument!=null) { _documentSymbol=_textDocument.getDocumentSymbol(); } Boolean _hierarchicalDocumentSymbolSupport = null; if (_documentSymbol!=null) { _hierarchicalDocumentSymbolSupport=_documentSymbol.getHierarchicalDocumentSymbolSupport(); } if (_hierarchicalDocumentSymbolSupport != null) { _elvis = _hierarchicalDocumentSymbolSupport; } else { _elvis = Boolean.valueOf(false); } this.hierarchicalDocumentSymbolSupport = (_elvis).booleanValue(); final InitializeResult result = this.languageServer.initialize(params).get(); if (callInitialized) { this.languageServer.initialized(null); } return result; } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example 4
Source File: LanguageServerImpl.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
/** * 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; if (textDocument != null) { rename = textDocument.getRename(); } 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); } semanticHighlightingRegistry.initialize(allLanguages, clientCapabilities, client); serverCapabilities.setSemanticHighlighting( new SemanticHighlightingServerCapabilities(semanticHighlightingRegistry.getAllScopes())); for (IResourceServiceProvider language : allLanguages) { ICapabilitiesContributor capabilitiesContributor = language.get(ICapabilitiesContributor.class); if (capabilitiesContributor != null) { capabilitiesContributor.contribute(serverCapabilities, params); } } return serverCapabilities; }