org.eclipse.lsp4j.ExecuteCommandOptions Java Examples
The following examples show how to use
org.eclipse.lsp4j.ExecuteCommandOptions.
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: InitHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Test public void testStaticCommandWithDynamicRegistration() throws Exception { when(commandHandler.getAllCommands()).thenReturn(new HashSet<>(Arrays.asList("cmd1", "cmd2", "cmd3", "cmd4"))); when(commandHandler.getStaticCommands()).thenReturn(new HashSet<>(Arrays.asList("cmd1", "cmd2"))); when(commandHandler.getNonStaticCommands()).thenReturn(new HashSet<>(Arrays.asList("cmd3", "cmd4"))); ClientPreferences mockCapabilies = mock(ClientPreferences.class); when(mockCapabilies.isExecuteCommandDynamicRegistrationSupported()).thenReturn(Boolean.TRUE); when(preferenceManager.getClientPreferences()).thenReturn(mockCapabilies); InitializeResult result = initialize(true); ExecuteCommandOptions commandProvider = result.getCapabilities().getExecuteCommandProvider(); assertNotNull(commandProvider); assertTrue(commandProvider.getCommands().contains("cmd1")); assertTrue(commandProvider.getCommands().contains("cmd2")); assertFalse(commandProvider.getCommands().contains("cmd3")); assertFalse(commandProvider.getCommands().contains("cmd4")); }
Example #2
Source File: InitHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Test public void testStaticCommandWithoutDynamicRegistration() throws Exception { when(commandHandler.getAllCommands()).thenReturn(new HashSet<>(Arrays.asList("cmd1", "cmd2", "cmd3", "cmd4"))); when(commandHandler.getStaticCommands()).thenReturn(new HashSet<>(Arrays.asList("cmd1", "cmd2"))); when(commandHandler.getNonStaticCommands()).thenReturn(new HashSet<>(Arrays.asList("cmd3", "cmd4"))); ClientPreferences mockCapabilies = mock(ClientPreferences.class); when(mockCapabilies.isExecuteCommandDynamicRegistrationSupported()).thenReturn(Boolean.FALSE); when(preferenceManager.getClientPreferences()).thenReturn(mockCapabilies); InitializeResult result = initialize(true); ExecuteCommandOptions commandProvider = result.getCapabilities().getExecuteCommandProvider(); assertNotNull(commandProvider); assertTrue(commandProvider.getCommands().containsAll(Arrays.asList("cmd1", "cmd2", "cmd3", "cmd4"))); }
Example #3
Source File: ExecutableCommandRegistry.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
protected IDisposable register(String command, IExecutableCommandService service) { String requestId = UUID.randomUUID().toString(); Registration reg = new Registration(); reg.setId(requestId); reg.setMethod(ExecutableCommandRegistry.METHOD); ExecuteCommandOptions executeCommandOptions = new ExecuteCommandOptions(); executeCommandOptions.setCommands(Collections.unmodifiableList(Lists.newArrayList(command))); reg.setRegisterOptions(executeCommandOptions); RegistrationParams registrationParams = new RegistrationParams(); registrationParams.setRegistrations(Lists.newArrayList(reg)); client.registerCapability(registrationParams); registeredCommands.put(command, service); return () -> { Unregistration unReg = new Unregistration(); unReg.setId(requestId); unReg.setMethod(ExecutableCommandRegistry.METHOD); UnregistrationParams unregistrationParams = new UnregistrationParams(); unregistrationParams.setUnregisterations(Lists.newArrayList(unReg)); this.client.unregisterCapability(unregistrationParams); this.registeredCommands.remove(command, service); }; }
Example #4
Source File: LanguageServerWrapper.java From intellij-quarkus with Eclipse Public License 2.0 | 5 votes |
void unregisterCommands(List<String> cmds) { ServerCapabilities caps = this.getServerCapabilities(); if (caps != null) { ExecuteCommandOptions commandProvider = caps.getExecuteCommandProvider(); if (commandProvider != null) { List<String> existingCommands = commandProvider.getCommands(); existingCommands.removeAll(cmds); } } }
Example #5
Source File: CommandExecutor.java From intellij-quarkus with Eclipse Public License 2.0 | 5 votes |
private static CompletableFuture<LanguageServer> getLanguageServerForCommand(Project project, Command command, Document document, LanguageServersRegistry.LanguageServerDefinition languageServerDefinition) throws IOException { CompletableFuture<LanguageServer> languageServerFuture = LanguageServiceAccessor.getInstance(project) .getInitializedLanguageServer(document, languageServerDefinition, serverCapabilities -> { ExecuteCommandOptions provider = serverCapabilities.getExecuteCommandProvider(); return provider != null && provider.getCommands().contains(command.getCommand()); }); return languageServerFuture; }
Example #6
Source File: JDTLanguageServer.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
/** * Toggles the server capabilities according to user preferences. */ private void syncCapabilitiesToSettings() { if (preferenceManager.getClientPreferences().isCompletionDynamicRegistered()) { toggleCapability(preferenceManager.getPreferences().isCompletionEnabled(), Preferences.COMPLETION_ID, Preferences.COMPLETION, CompletionHandler.DEFAULT_COMPLETION_OPTIONS); } if (preferenceManager.getClientPreferences().isFormattingDynamicRegistrationSupported()) { toggleCapability(preferenceManager.getPreferences().isJavaFormatEnabled(), Preferences.FORMATTING_ID, Preferences.TEXT_DOCUMENT_FORMATTING, null); } if (preferenceManager.getClientPreferences().isRangeFormattingDynamicRegistrationSupported()) { toggleCapability(preferenceManager.getPreferences().isJavaFormatEnabled(), Preferences.FORMATTING_RANGE_ID, Preferences.TEXT_DOCUMENT_RANGE_FORMATTING, null); } if (preferenceManager.getClientPreferences().isOnTypeFormattingDynamicRegistrationSupported()) { toggleCapability(preferenceManager.getPreferences().isJavaFormatOnTypeEnabled(), Preferences.FORMATTING_ON_TYPE_ID, Preferences.TEXT_DOCUMENT_ON_TYPE_FORMATTING, new DocumentOnTypeFormattingOptions(";", Arrays.asList("\n", "}"))); } if (preferenceManager.getClientPreferences().isCodeLensDynamicRegistrationSupported()) { toggleCapability(preferenceManager.getPreferences().isCodeLensEnabled(), Preferences.CODE_LENS_ID, Preferences.TEXT_DOCUMENT_CODE_LENS, new CodeLensOptions(true)); } if (preferenceManager.getClientPreferences().isSignatureHelpDynamicRegistrationSupported()) { toggleCapability(preferenceManager.getPreferences().isSignatureHelpEnabled(), Preferences.SIGNATURE_HELP_ID, Preferences.TEXT_DOCUMENT_SIGNATURE_HELP, SignatureHelpHandler.createOptions()); } if (preferenceManager.getClientPreferences().isRenameDynamicRegistrationSupported()) { toggleCapability(preferenceManager.getPreferences().isRenameEnabled(), Preferences.RENAME_ID, Preferences.TEXT_DOCUMENT_RENAME, RenameHandler.createOptions()); } if (preferenceManager.getClientPreferences().isExecuteCommandDynamicRegistrationSupported()) { toggleCapability(preferenceManager.getPreferences().isExecuteCommandEnabled(), Preferences.EXECUTE_COMMAND_ID, Preferences.WORKSPACE_EXECUTE_COMMAND, new ExecuteCommandOptions(new ArrayList<>(commandHandler.getNonStaticCommands()))); } if (preferenceManager.getClientPreferences().isCodeActionDynamicRegistered()) { toggleCapability(preferenceManager.getClientPreferences().isCodeActionDynamicRegistered(), Preferences.CODE_ACTION_ID, Preferences.CODE_ACTION, getCodeActionOptions()); } if (preferenceManager.getClientPreferences().isFoldgingRangeDynamicRegistered()) { toggleCapability(preferenceManager.getPreferences().isFoldingRangeEnabled(), Preferences.FOLDINGRANGE_ID, Preferences.FOLDINGRANGE, null); } if (preferenceManager.getClientPreferences().isSelectionRangeDynamicRegistered()) { toggleCapability(preferenceManager.getPreferences().isSelectionRangeEnabled(), Preferences.SELECTION_RANGE_ID, Preferences.SELECTION_RANGE, null); } }
Example #7
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 #8
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); }
Example #9
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 #10
Source File: ServerCapabilities.java From lsp4j with Eclipse Public License 2.0 | 4 votes |
/** * The server provides execute command support. */ @Pure public ExecuteCommandOptions getExecuteCommandProvider() { return this.executeCommandProvider; }
Example #11
Source File: ServerCapabilities.java From lsp4j with Eclipse Public License 2.0 | 4 votes |
/** * The server provides execute command support. */ public void setExecuteCommandProvider(final ExecuteCommandOptions executeCommandProvider) { this.executeCommandProvider = executeCommandProvider; }