Java Code Examples for org.eclipse.lsp4j.InitializeResult#setCapabilities()
The following examples show how to use
org.eclipse.lsp4j.InitializeResult#setCapabilities() .
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: XLanguageServerImpl.java From n4js with Eclipse Public License 1.0 | 6 votes |
@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\'"); } this.initializeParams = params; openFilesManager.setIssueRegistry(issueRegistry); openFilesManager.addListener(this); lspBuilder.getIndexRaw().addListener(this); Stopwatch sw = Stopwatch.createStarted(); LOG.info("Start server initialization in workspace directory " + baseDir); lspBuilder.initialize(baseDir, issueRegistry); LOG.info("Server initialization done after " + sw); initializeResult = new InitializeResult(); initializeResult.setCapabilities(createServerCapabilities(params)); return CompletableFuture.completedFuture(initializeResult); }
Example 2
Source File: LSPBindings.java From netbeans with Apache License 2.0 | 5 votes |
private static InitializeResult initServer(Process p, LanguageServer server, FileObject root) throws InterruptedException, ExecutionException { InitializeParams initParams = new InitializeParams(); initParams.setRootUri(Utils.toURI(root)); initParams.setRootPath(FileUtil.toFile(root).getAbsolutePath()); //some servers still expect root path initParams.setProcessId(0); TextDocumentClientCapabilities tdcc = new TextDocumentClientCapabilities(); DocumentSymbolCapabilities dsc = new DocumentSymbolCapabilities(); dsc.setHierarchicalDocumentSymbolSupport(true); dsc.setSymbolKind(new SymbolKindCapabilities(Arrays.asList(SymbolKind.values()))); tdcc.setDocumentSymbol(dsc); WorkspaceClientCapabilities wcc = new WorkspaceClientCapabilities(); wcc.setWorkspaceEdit(new WorkspaceEditCapabilities()); wcc.getWorkspaceEdit().setDocumentChanges(true); wcc.getWorkspaceEdit().setResourceOperations(Arrays.asList(ResourceOperationKind.Create, ResourceOperationKind.Delete, ResourceOperationKind.Rename)); initParams.setCapabilities(new ClientCapabilities(wcc, tdcc, null)); CompletableFuture<InitializeResult> initResult = server.initialize(initParams); while (true) { try { return initResult.get(100, TimeUnit.MILLISECONDS); } catch (TimeoutException ex) { if (p != null && !p.isAlive()) { InitializeResult emptyResult = new InitializeResult(); emptyResult.setCapabilities(new ServerCapabilities()); return emptyResult; } } } }
Example 3
Source File: SyntaxInitHandler.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@Override public void registerCapabilities(InitializeResult initializeResult) { ServerCapabilities capabilities = new ServerCapabilities(); if (!preferenceManager.getClientPreferences().isClientDocumentSymbolProviderRegistered() && !preferenceManager.getClientPreferences().isDocumentSymbolDynamicRegistered()) { capabilities.setDocumentSymbolProvider(Boolean.TRUE); } if (!preferenceManager.getClientPreferences().isDefinitionDynamicRegistered()) { capabilities.setDefinitionProvider(Boolean.TRUE); } if (!preferenceManager.getClientPreferences().isTypeDefinitionDynamicRegistered()) { capabilities.setTypeDefinitionProvider(Boolean.TRUE); } if (!preferenceManager.getClientPreferences().isFoldgingRangeDynamicRegistered()) { capabilities.setFoldingRangeProvider(Boolean.TRUE); } if (!preferenceManager.getClientPreferences().isSelectionRangeDynamicRegistered()) { capabilities.setSelectionRangeProvider(Boolean.TRUE); } if (!preferenceManager.getClientPreferences().isHoverDynamicRegistered()) { capabilities.setHoverProvider(Boolean.TRUE); } if (!preferenceManager.getClientPreferences().isCompletionDynamicRegistered()) { capabilities.setCompletionProvider(CompletionHandler.DEFAULT_COMPLETION_OPTIONS); } TextDocumentSyncOptions textDocumentSyncOptions = new TextDocumentSyncOptions(); textDocumentSyncOptions.setOpenClose(Boolean.TRUE); textDocumentSyncOptions.setSave(new SaveOptions(Boolean.TRUE)); textDocumentSyncOptions.setChange(TextDocumentSyncKind.Incremental); capabilities.setTextDocumentSync(textDocumentSyncOptions); WorkspaceServerCapabilities wsCapabilities = new WorkspaceServerCapabilities(); WorkspaceFoldersOptions wsFoldersOptions = new WorkspaceFoldersOptions(); wsFoldersOptions.setSupported(Boolean.TRUE); wsFoldersOptions.setChangeNotifications(Boolean.TRUE); wsCapabilities.setWorkspaceFolders(wsFoldersOptions); capabilities.setWorkspace(wsCapabilities); initializeResult.setCapabilities(capabilities); }
Example 4
Source File: LanguageServerImpl.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@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); }
Example 5
Source File: InitHandler.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
@Override public void registerCapabilities(InitializeResult initializeResult) { ServerCapabilities capabilities = new ServerCapabilities(); if (!preferenceManager.getClientPreferences().isCompletionDynamicRegistered()) { capabilities.setCompletionProvider(CompletionHandler.DEFAULT_COMPLETION_OPTIONS); } if (!preferenceManager.getClientPreferences().isFormattingDynamicRegistrationSupported()) { capabilities.setDocumentFormattingProvider(Boolean.TRUE); } if (!preferenceManager.getClientPreferences().isRangeFormattingDynamicRegistrationSupported()) { capabilities.setDocumentRangeFormattingProvider(Boolean.TRUE); } if (!preferenceManager.getClientPreferences().isOnTypeFormattingDynamicRegistrationSupported()) { capabilities.setDocumentOnTypeFormattingProvider(new DocumentOnTypeFormattingOptions(";", Arrays.asList("\n", "}"))); } if (!preferenceManager.getClientPreferences().isCodeLensDynamicRegistrationSupported()) { capabilities.setCodeLensProvider(new CodeLensOptions(true)); } if (!preferenceManager.getClientPreferences().isSignatureHelpDynamicRegistrationSupported()) { capabilities.setSignatureHelpProvider(SignatureHelpHandler.createOptions()); } if (!preferenceManager.getClientPreferences().isRenameDynamicRegistrationSupported()) { capabilities.setRenameProvider(RenameHandler.createOptions()); } if (!preferenceManager.getClientPreferences().isCodeActionDynamicRegistered()) { capabilities.setCodeActionProvider(Boolean.TRUE); } if (!preferenceManager.getClientPreferences().isExecuteCommandDynamicRegistrationSupported()) { Set<String> commands = commandHandler.getAllCommands(); if (!commands.isEmpty()) { capabilities.setExecuteCommandProvider(new ExecuteCommandOptions(new ArrayList<>(commands))); } } else { // Send static command at the startup - they remain registered all the time Set<String> staticCommands = commandHandler.getStaticCommands(); if (!staticCommands.isEmpty()) { capabilities.setExecuteCommandProvider(new ExecuteCommandOptions(new ArrayList<>(staticCommands))); } } if (!preferenceManager.getClientPreferences().isWorkspaceSymbolDynamicRegistered()) { capabilities.setWorkspaceSymbolProvider(Boolean.TRUE); } if (!preferenceManager.getClientPreferences().isClientDocumentSymbolProviderRegistered() && !preferenceManager.getClientPreferences().isDocumentSymbolDynamicRegistered()) { capabilities.setDocumentSymbolProvider(Boolean.TRUE); } if (!preferenceManager.getClientPreferences().isDefinitionDynamicRegistered()) { capabilities.setDefinitionProvider(Boolean.TRUE); } if (!preferenceManager.getClientPreferences().isTypeDefinitionDynamicRegistered()) { capabilities.setTypeDefinitionProvider(Boolean.TRUE); } if (!preferenceManager.getClientPreferences().isClientHoverProviderRegistered() && !preferenceManager.getClientPreferences().isHoverDynamicRegistered()) { capabilities.setHoverProvider(Boolean.TRUE); } if (!preferenceManager.getClientPreferences().isReferencesDynamicRegistered()) { capabilities.setReferencesProvider(Boolean.TRUE); } if (!preferenceManager.getClientPreferences().isDocumentHighlightDynamicRegistered()) { capabilities.setDocumentHighlightProvider(Boolean.TRUE); } if (!preferenceManager.getClientPreferences().isFoldgingRangeDynamicRegistered()) { capabilities.setFoldingRangeProvider(Boolean.TRUE); } if (!preferenceManager.getClientPreferences().isImplementationDynamicRegistered()) { capabilities.setImplementationProvider(Boolean.TRUE); } if (!preferenceManager.getClientPreferences().isSelectionRangeDynamicRegistered()) { capabilities.setSelectionRangeProvider(Boolean.TRUE); } capabilities.setCallHierarchyProvider(Boolean.TRUE); TextDocumentSyncOptions textDocumentSyncOptions = new TextDocumentSyncOptions(); textDocumentSyncOptions.setOpenClose(Boolean.TRUE); textDocumentSyncOptions.setSave(new SaveOptions(Boolean.TRUE)); textDocumentSyncOptions.setChange(TextDocumentSyncKind.Incremental); if (preferenceManager.getClientPreferences().isWillSaveRegistered()) { textDocumentSyncOptions.setWillSave(Boolean.TRUE); } if (preferenceManager.getClientPreferences().isWillSaveWaitUntilRegistered()) { textDocumentSyncOptions.setWillSaveWaitUntil(Boolean.TRUE); } capabilities.setTextDocumentSync(textDocumentSyncOptions); if (preferenceManager.getClientPreferences().isSemanticHighlightingSupported()) { SemanticHighlightingServerCapabilities semanticHighlightingCapabilities = new SemanticHighlightingServerCapabilities(); semanticHighlightingCapabilities.setScopes(SemanticHighlightingService.getAllScopes()); capabilities.setSemanticHighlighting(semanticHighlightingCapabilities); } WorkspaceServerCapabilities wsCapabilities = new WorkspaceServerCapabilities(); WorkspaceFoldersOptions wsFoldersOptions = new WorkspaceFoldersOptions(); wsFoldersOptions.setSupported(Boolean.TRUE); wsFoldersOptions.setChangeNotifications(Boolean.TRUE); wsCapabilities.setWorkspaceFolders(wsFoldersOptions); capabilities.setWorkspace(wsCapabilities); initializeResult.setCapabilities(capabilities); }