Search in sources :

Example 11 with InitializeResult

use of org.eclipse.lsp4j.InitializeResult in project eclipse.jdt.ls by eclipse.

the class InitHandlerTest method initialize.

private InitializeResult initialize(boolean dynamicRegistration) throws InterruptedException, ExecutionException {
    InitializeParams params = new InitializeParams();
    ClientCapabilities capabilities = new ClientCapabilities();
    WorkspaceClientCapabilities workspaceCapabilities = new WorkspaceClientCapabilities();
    workspaceCapabilities.setDidChangeConfiguration(new DidChangeConfigurationCapabilities(dynamicRegistration));
    ExecuteCommandCapabilities executeCommand = new ExecuteCommandCapabilities(dynamicRegistration);
    workspaceCapabilities.setExecuteCommand(executeCommand);
    capabilities.setWorkspace(workspaceCapabilities);
    TextDocumentClientCapabilities textDocument = new TextDocumentClientCapabilities();
    SynchronizationCapabilities synchronizationCapabilities = new SynchronizationCapabilities();
    synchronizationCapabilities.setWillSave(Boolean.TRUE);
    synchronizationCapabilities.setWillSaveWaitUntil(Boolean.TRUE);
    capabilities.setTextDocument(textDocument);
    params.setCapabilities(capabilities);
    CompletableFuture<InitializeResult> result = server.initialize(params);
    return result.get();
}
Also used : WorkspaceClientCapabilities(org.eclipse.lsp4j.WorkspaceClientCapabilities) InitializeResult(org.eclipse.lsp4j.InitializeResult) DidChangeConfigurationCapabilities(org.eclipse.lsp4j.DidChangeConfigurationCapabilities) WorkspaceClientCapabilities(org.eclipse.lsp4j.WorkspaceClientCapabilities) TextDocumentClientCapabilities(org.eclipse.lsp4j.TextDocumentClientCapabilities) ClientCapabilities(org.eclipse.lsp4j.ClientCapabilities) SynchronizationCapabilities(org.eclipse.lsp4j.SynchronizationCapabilities) InitializeParams(org.eclipse.lsp4j.InitializeParams) ExecuteCommandCapabilities(org.eclipse.lsp4j.ExecuteCommandCapabilities) TextDocumentClientCapabilities(org.eclipse.lsp4j.TextDocumentClientCapabilities)

Example 12 with InitializeResult

use of org.eclipse.lsp4j.InitializeResult in project eclipse.jdt.ls by eclipse.

the class InitHandlerTest method testExecuteCommandProviderDynamicRegistration.

@Test
public void testExecuteCommandProviderDynamicRegistration() throws Exception {
    ClientPreferences mockCapabilies = mock(ClientPreferences.class);
    when(mockCapabilies.isExecuteCommandDynamicRegistrationSupported()).thenReturn(Boolean.TRUE);
    when(preferenceManager.getClientPreferences()).thenReturn(mockCapabilies);
    InitializeResult result = initialize(true);
    assertNull(result.getCapabilities().getExecuteCommandProvider());
}
Also used : InitializeResult(org.eclipse.lsp4j.InitializeResult) ClientPreferences(org.eclipse.jdt.ls.core.internal.preferences.ClientPreferences) AbstractProjectsManagerBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest) Test(org.junit.Test)

Example 13 with InitializeResult

use of org.eclipse.lsp4j.InitializeResult in project eclipse.jdt.ls by eclipse.

the class InitHandler method initialize.

@SuppressWarnings("unchecked")
InitializeResult initialize(InitializeParams param) {
    logInfo("Initializing Java Language Server " + JavaLanguageServerPlugin.getVersion());
    Map<?, ?> initializationOptions = this.getInitializationOptions(param);
    Map<String, Object> extendedClientCapabilities = getInitializationOption(initializationOptions, "extendedClientCapabilities", Map.class);
    if (param.getCapabilities() == null) {
        preferenceManager.updateClientPrefences(new ClientCapabilities(), extendedClientCapabilities);
    } else {
        preferenceManager.updateClientPrefences(param.getCapabilities(), extendedClientCapabilities);
    }
    Collection<IPath> rootPaths = new ArrayList<>();
    Collection<String> workspaceFolders = getInitializationOption(initializationOptions, "workspaceFolders", Collection.class);
    if (workspaceFolders != null && !workspaceFolders.isEmpty()) {
        for (String uri : workspaceFolders) {
            IPath filePath = ResourceUtils.filePathFromURI(uri);
            if (filePath != null) {
                rootPaths.add(filePath);
            }
        }
    } else {
        String rootPath = param.getRootUri();
        if (rootPath == null) {
            rootPath = param.getRootPath();
            if (rootPath != null) {
                logInfo("In LSP 3.0, InitializeParams.rootPath is deprecated in favour of InitializeParams.rootUri!");
            }
        }
        if (rootPath != null) {
            IPath filePath = ResourceUtils.filePathFromURI(rootPath);
            if (filePath != null) {
                rootPaths.add(filePath);
            }
        }
    }
    if (rootPaths.isEmpty()) {
        IPath workspaceLocation = ResourcesPlugin.getWorkspace().getRoot().getLocation();
        logInfo("No workspace folders or root uri was defined. Falling back on " + workspaceLocation);
        rootPaths.add(workspaceLocation);
    }
    if (initializationOptions.get(SETTINGS_KEY) instanceof Map) {
        Object settings = initializationOptions.get(SETTINGS_KEY);
        @SuppressWarnings("unchecked") Preferences prefs = Preferences.createFrom((Map<String, Object>) settings);
        preferenceManager.update(prefs);
    }
    triggerInitialization(rootPaths);
    addWorkspaceDiagnosticsHandler();
    Integer processId = param.getProcessId();
    if (processId != null) {
        JavaLanguageServerPlugin.getLanguageServer().setParentProcessId(processId.longValue());
    }
    try {
        Collection<String> bundleList = getInitializationOption(initializationOptions, BUNDLES_KEY, Collection.class);
        BundleUtils.loadBundles(bundleList);
    } catch (CoreException e) {
        // The additional plug-ins should not affect the main language server loading.
        JavaLanguageServerPlugin.logException("Failed to load extension bundles ", e);
    }
    InitializeResult result = new InitializeResult();
    ServerCapabilities capabilities = new ServerCapabilities();
    capabilities.setCompletionProvider(new CompletionOptions(Boolean.TRUE, Arrays.asList(".", "@", "#")));
    if (!preferenceManager.getClientPreferences().isFormattingDynamicRegistrationSupported()) {
        capabilities.setDocumentFormattingProvider(Boolean.TRUE);
    }
    if (!preferenceManager.getClientPreferences().isRangeFormattingDynamicRegistrationSupported()) {
        capabilities.setDocumentRangeFormattingProvider(Boolean.TRUE);
    }
    if (!preferenceManager.getClientPreferences().isCodeLensDynamicRegistrationSupported()) {
        capabilities.setCodeLensProvider(new CodeLensOptions(true));
    }
    if (!preferenceManager.getClientPreferences().isSignatureHelpDynamicRegistrationSupported()) {
        capabilities.setSignatureHelpProvider(SignatureHelpHandler.createOptions());
    }
    if (!preferenceManager.getClientPreferences().isRenameDynamicRegistrationSupported()) {
        capabilities.setRenameProvider(Boolean.TRUE);
    }
    if (!preferenceManager.getClientPreferences().isCodeActionDynamicRegistered()) {
        capabilities.setCodeActionProvider(Boolean.TRUE);
    }
    if (!preferenceManager.getClientPreferences().isExecuteCommandDynamicRegistrationSupported()) {
        Set<String> commands = WorkspaceExecuteCommandHandler.getCommands();
        capabilities.setExecuteCommandProvider(new ExecuteCommandOptions(new ArrayList<>(commands)));
    }
    if (!preferenceManager.getClientPreferences().isWorkspaceSymbolDynamicRegistered()) {
        capabilities.setWorkspaceSymbolProvider(Boolean.TRUE);
    }
    if (!preferenceManager.getClientPreferences().isDocumentSymbolDynamicRegistered()) {
        capabilities.setDocumentSymbolProvider(Boolean.TRUE);
    }
    if (!preferenceManager.getClientPreferences().isDefinitionDynamicRegistered()) {
        capabilities.setDefinitionProvider(Boolean.TRUE);
    }
    if (!preferenceManager.getClientPreferences().isHoverDynamicRegistered()) {
        capabilities.setHoverProvider(Boolean.TRUE);
    }
    if (!preferenceManager.getClientPreferences().isReferencesDynamicRegistered()) {
        capabilities.setReferencesProvider(Boolean.TRUE);
    }
    if (!preferenceManager.getClientPreferences().isDocumentHighlightDynamicRegistered()) {
        capabilities.setDocumentHighlightProvider(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);
    WorkspaceServerCapabilities wsCapabilities = new WorkspaceServerCapabilities();
    WorkspaceFoldersOptions wsFoldersOptions = new WorkspaceFoldersOptions();
    wsFoldersOptions.setSupported(Boolean.TRUE);
    wsFoldersOptions.setChangeNotifications(Boolean.TRUE);
    wsCapabilities.setWorkspaceFolders(wsFoldersOptions);
    capabilities.setWorkspace(wsCapabilities);
    result.setCapabilities(capabilities);
    return result;
}
Also used : IPath(org.eclipse.core.runtime.IPath) TextDocumentSyncOptions(org.eclipse.lsp4j.TextDocumentSyncOptions) ArrayList(java.util.ArrayList) ClientCapabilities(org.eclipse.lsp4j.ClientCapabilities) WorkspaceFoldersOptions(org.eclipse.lsp4j.WorkspaceFoldersOptions) WorkspaceServerCapabilities(org.eclipse.lsp4j.WorkspaceServerCapabilities) CompletionOptions(org.eclipse.lsp4j.CompletionOptions) InitializeResult(org.eclipse.lsp4j.InitializeResult) CoreException(org.eclipse.core.runtime.CoreException) ServerCapabilities(org.eclipse.lsp4j.ServerCapabilities) WorkspaceServerCapabilities(org.eclipse.lsp4j.WorkspaceServerCapabilities) CodeLensOptions(org.eclipse.lsp4j.CodeLensOptions) SaveOptions(org.eclipse.lsp4j.SaveOptions) Preferences(org.eclipse.jdt.ls.core.internal.preferences.Preferences) ExecuteCommandOptions(org.eclipse.lsp4j.ExecuteCommandOptions) Map(java.util.Map)

Example 14 with InitializeResult

use of org.eclipse.lsp4j.InitializeResult in project ballerina by ballerina-lang.

the class BallerinaLanguageServer method initialize.

public CompletableFuture<InitializeResult> initialize(InitializeParams params) {
    final InitializeResult res = new InitializeResult(new ServerCapabilities());
    final SignatureHelpOptions signatureHelpOptions = new SignatureHelpOptions(Arrays.asList("(", ","));
    final List<String> commandList = new ArrayList<>(Arrays.asList(CommandConstants.CMD_IMPORT_PACKAGE, CommandConstants.CMD_ADD_DOCUMENTATION, CommandConstants.CMD_ADD_ALL_DOC));
    final ExecuteCommandOptions executeCommandOptions = new ExecuteCommandOptions(commandList);
    final CompletionOptions completionOptions = new CompletionOptions();
    completionOptions.setTriggerCharacters(Arrays.asList(":", ".", ">"));
    res.getCapabilities().setCompletionProvider(completionOptions);
    res.getCapabilities().setTextDocumentSync(TextDocumentSyncKind.Full);
    res.getCapabilities().setSignatureHelpProvider(signatureHelpOptions);
    res.getCapabilities().setHoverProvider(true);
    res.getCapabilities().setDocumentSymbolProvider(true);
    res.getCapabilities().setDefinitionProvider(true);
    res.getCapabilities().setReferencesProvider(true);
    res.getCapabilities().setCodeActionProvider(true);
    res.getCapabilities().setExecuteCommandProvider(executeCommandOptions);
    res.getCapabilities().setDocumentFormattingProvider(true);
    res.getCapabilities().setRenameProvider(true);
    return CompletableFuture.supplyAsync(() -> res);
}
Also used : CompletionOptions(org.eclipse.lsp4j.CompletionOptions) SignatureHelpOptions(org.eclipse.lsp4j.SignatureHelpOptions) InitializeResult(org.eclipse.lsp4j.InitializeResult) ArrayList(java.util.ArrayList) ServerCapabilities(org.eclipse.lsp4j.ServerCapabilities) ExecuteCommandOptions(org.eclipse.lsp4j.ExecuteCommandOptions)

Example 15 with InitializeResult

use of org.eclipse.lsp4j.InitializeResult in project sts4 by spring-projects.

the class SimpleLanguageServer method initialize.

@Override
public CompletableFuture<InitializeResult> initialize(InitializeParams params) {
    Log.debug("Initializing: " + params);
    // multi-root workspace handling
    List<WorkspaceFolder> workspaceFolders = getWorkspaceFolders(params);
    if (!workspaceFolders.isEmpty()) {
        this.getWorkspaceService().setWorkspaceFolders(workspaceFolders);
    } else {
        String rootUri = params.getRootUri();
        if (rootUri == null) {
            Log.debug("workspaceRoot NOT SET");
        } else {
            List<WorkspaceFolder> singleRootFolder = new ArrayList<>();
            String name;
            try {
                name = Paths.get(new URI(rootUri).getPath()).getFileName().toString();
            } catch (Exception e) {
                name = "";
            }
            WorkspaceFolder folder = new WorkspaceFolder();
            folder.setName(name);
            folder.setUri(rootUri);
            singleRootFolder.add(folder);
            this.getWorkspaceService().setWorkspaceFolders(singleRootFolder);
        }
    }
    this.hasCompletionSnippetSupport = safeGet(false, () -> params.getCapabilities().getTextDocument().getCompletion().getCompletionItem().getSnippetSupport());
    this.hasExecuteCommandSupport = safeGet(false, () -> params.getCapabilities().getWorkspace().getExecuteCommand() != null);
    this.hasFileWatcherRegistrationSupport = safeGet(false, () -> params.getCapabilities().getWorkspace().getDidChangeWatchedFiles().getDynamicRegistration());
    Log.debug("workspaceRoots = " + getWorkspaceService().getWorkspaceRoots());
    Log.debug("hasCompletionSnippetSupport = " + hasCompletionSnippetSupport);
    Log.debug("hasExecuteCommandSupport = " + hasExecuteCommandSupport);
    InitializeResult result = new InitializeResult();
    if (hasExecuteCommandSupport) {
        getWorkspaceService().onExecuteCommand(this::executeCommand);
    }
    ServerCapabilities cap = getServerCapabilities();
    result.setCapabilities(cap);
    Consumer<InitializeParams> ih = this.initializeHandler;
    if (ih != null) {
        ih.accept(params);
    }
    return CompletableFuture.completedFuture(result);
}
Also used : InitializeResult(org.eclipse.lsp4j.InitializeResult) ArrayList(java.util.ArrayList) ServerCapabilities(org.eclipse.lsp4j.ServerCapabilities) WorkspaceServerCapabilities(org.eclipse.lsp4j.WorkspaceServerCapabilities) InitializeParams(org.eclipse.lsp4j.InitializeParams) URI(java.net.URI) BadLocationException(org.springframework.ide.vscode.commons.util.BadLocationException) WorkspaceFolder(org.eclipse.lsp4j.WorkspaceFolder)

Aggregations

InitializeResult (org.eclipse.lsp4j.InitializeResult)15 ServerCapabilities (org.eclipse.lsp4j.ServerCapabilities)7 AbstractProjectsManagerBasedTest (org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest)4 ClientPreferences (org.eclipse.jdt.ls.core.internal.preferences.ClientPreferences)4 ClientCapabilities (org.eclipse.lsp4j.ClientCapabilities)4 CompletionOptions (org.eclipse.lsp4j.CompletionOptions)4 ExecuteCommandOptions (org.eclipse.lsp4j.ExecuteCommandOptions)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 InitializeParams (org.eclipse.lsp4j.InitializeParams)3 SignatureHelpOptions (org.eclipse.lsp4j.SignatureHelpOptions)3 TextDocumentSyncOptions (org.eclipse.lsp4j.TextDocumentSyncOptions)3 URI (java.net.URI)2 Map (java.util.Map)2 CodeLensOptions (org.eclipse.lsp4j.CodeLensOptions)2 ExecuteCommandCapabilities (org.eclipse.lsp4j.ExecuteCommandCapabilities)2 SaveOptions (org.eclipse.lsp4j.SaveOptions)2 WorkspaceClientCapabilities (org.eclipse.lsp4j.WorkspaceClientCapabilities)2 WorkspaceServerCapabilities (org.eclipse.lsp4j.WorkspaceServerCapabilities)2 ResponseMessage (org.eclipse.lsp4j.jsonrpc.messages.ResponseMessage)2