org.eclipse.lsp4j.CompletionOptions Java Examples
The following examples show how to use
org.eclipse.lsp4j.CompletionOptions.
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: LSContentAssistProcessor.java From intellij-quarkus with Eclipse Public License 2.0 | 6 votes |
private void initiateLanguageServers(Project project, Document document) { if (this.completionLanguageServersFuture != null) { try { this.completionLanguageServersFuture.cancel(true); } catch (CancellationException ex) { // nothing } } this.completionTriggerChars = new char[0]; this.completionLanguageServersFuture = LanguageServiceAccessor.getInstance(project).getLanguageServers(document, capabilities -> { CompletionOptions provider = capabilities.getCompletionProvider(); if (provider != null) { synchronized (this.completionTriggerCharsSemaphore) { this.completionTriggerChars = mergeTriggers(this.completionTriggerChars, provider.getTriggerCharacters()); } return true; } return false; }); }
Example #2
Source File: GroovyLanguageServer.java From groovy-language-server with Apache License 2.0 | 5 votes |
@Override public CompletableFuture<InitializeResult> initialize(InitializeParams params) { String rootUriString = params.getRootUri(); if (rootUriString != null) { URI uri = URI.create(params.getRootUri()); Path workspaceRoot = Paths.get(uri); groovyServices.setWorkspaceRoot(workspaceRoot); } CompletionOptions completionOptions = new CompletionOptions(false, Arrays.asList(".")); ServerCapabilities serverCapabilities = new ServerCapabilities(); serverCapabilities.setCompletionProvider(completionOptions); serverCapabilities.setTextDocumentSync(TextDocumentSyncKind.Full); serverCapabilities.setDocumentSymbolProvider(true); serverCapabilities.setWorkspaceSymbolProvider(true); serverCapabilities.setDocumentSymbolProvider(true); serverCapabilities.setReferencesProvider(true); serverCapabilities.setDefinitionProvider(true); serverCapabilities.setTypeDefinitionProvider(true); serverCapabilities.setHoverProvider(true); serverCapabilities.setRenameProvider(true); SignatureHelpOptions signatureHelpOptions = new SignatureHelpOptions(); signatureHelpOptions.setTriggerCharacters(Arrays.asList("(", ",")); serverCapabilities.setSignatureHelpProvider(signatureHelpOptions); InitializeResult initializeResult = new InitializeResult(serverCapabilities); return CompletableFuture.completedFuture(initializeResult); }
Example #3
Source File: CamelLanguageServer.java From camel-language-server with Apache License 2.0 | 5 votes |
private ServerCapabilities createServerCapabilities() { ServerCapabilities capabilities = new ServerCapabilities(); capabilities.setTextDocumentSync(TextDocumentSyncKind.Full); capabilities.setCompletionProvider(new CompletionOptions(Boolean.TRUE, Arrays.asList(".","?","&", "\"", "="))); capabilities.setHoverProvider(Boolean.TRUE); capabilities.setDocumentSymbolProvider(Boolean.TRUE); capabilities.setReferencesProvider(Boolean.TRUE); capabilities.setDefinitionProvider(Boolean.TRUE); capabilities.setCodeActionProvider(new CodeActionOptions(Arrays.asList(CodeActionKind.QuickFix))); return capabilities; }
Example #4
Source File: CompletionProviderImpl.java From netbeans with Apache License 2.0 | 5 votes |
private boolean hasCompletionResolve(LSPBindings server) { ServerCapabilities capabilities = server.getInitResult().getCapabilities(); if (capabilities == null) return false; CompletionOptions completionProvider = capabilities.getCompletionProvider(); if (completionProvider == null) return false; Boolean resolveProvider = completionProvider.getResolveProvider(); return resolveProvider != null && resolveProvider; }
Example #5
Source File: CompletionProviderImpl.java From netbeans with Apache License 2.0 | 5 votes |
private boolean isTriggerCharacter(LSPBindings server, String text) { InitializeResult init = server.getInitResult(); if (init == null) return false; ServerCapabilities capabilities = init.getCapabilities(); if (capabilities == null) return false; CompletionOptions completionOptions = capabilities.getCompletionProvider(); if (completionOptions == null) return false; List<String> triggerCharacters = completionOptions.getTriggerCharacters(); if (triggerCharacters == null) return false; return triggerCharacters.stream().anyMatch(trigger -> text.endsWith(trigger)); }
Example #6
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 #7
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; }
Example #8
Source File: ServerCapabilities.java From lsp4j with Eclipse Public License 2.0 | 4 votes |
/** * The server provides completion support. */ @Pure public CompletionOptions getCompletionProvider() { return this.completionProvider; }
Example #9
Source File: ServerCapabilities.java From lsp4j with Eclipse Public License 2.0 | 4 votes |
/** * The server provides completion support. */ public void setCompletionProvider(final CompletionOptions completionProvider) { this.completionProvider = completionProvider; }