Search in sources :

Example 16 with InitializeParams

use of org.eclipse.lsp4j.InitializeParams in project xtext-core by eclipse.

the class AbstractLanguageServerTest method initialize.

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));
            String _uriString = this._uriExtensions.toUriString(this.root.toURI().normalize());
            WorkspaceFolder _workspaceFolder = new WorkspaceFolder(_uriString, "");
            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);
    }
}
Also used : InitializeResult(org.eclipse.lsp4j.InitializeResult) DocumentSymbolCapabilities(org.eclipse.lsp4j.DocumentSymbolCapabilities) ClientCapabilities(org.eclipse.lsp4j.ClientCapabilities) TextDocumentClientCapabilities(org.eclipse.lsp4j.TextDocumentClientCapabilities) InitializeParams(org.eclipse.lsp4j.InitializeParams) TextDocumentClientCapabilities(org.eclipse.lsp4j.TextDocumentClientCapabilities) WorkspaceFolder(org.eclipse.lsp4j.WorkspaceFolder)

Example 17 with InitializeParams

use of org.eclipse.lsp4j.InitializeParams 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)

Example 18 with InitializeParams

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

the class InitHandlerTest method testConfigureJVMs.

@Test
public void testConfigureJVMs() throws Exception {
    InitHandler handler = new InitHandler(projectsManager, preferenceManager, server.getClientConnection(), commandHandler);
    IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(IConstants.PLUGIN_ID);
    boolean isWorkspaceInitialized = isWorkspaceInitialized(prefs);
    boolean[] changed = new boolean[] { false };
    IVMInstall defaultVM = JavaRuntime.getDefaultVMInstall();
    IVMInstallChangedListener listener = new IVMInstallChangedListener() {

        @Override
        public void defaultVMInstallChanged(IVMInstall previous, IVMInstall current) {
            changed[0] = true;
        }

        @Override
        public void vmChanged(PropertyChangeEvent event) {
        }

        @Override
        public void vmAdded(IVMInstall vm) {
        }

        @Override
        public void vmRemoved(IVMInstall vm) {
        }
    };
    try {
        prefs.putBoolean(IConstants.WORKSPACE_INITIALIZED, false);
        InitializeParams params = new InitializeParams();
        Map<String, Object> initializationOptions = new HashMap<>();
        String javaHome = new File(TestVMType.getFakeJDKsLocation(), "9").getAbsolutePath();
        HashMap<String, Object> homeMap = getMap("home", javaHome);
        Map<String, Object> javaMap = getMap("java", homeMap);
        initializationOptions.put(InitHandler.SETTINGS_KEY, javaMap);
        params.setInitializationOptions(initializationOptions);
        assertFalse(isWorkspaceInitialized(prefs));
        JavaRuntime.addVMInstallChangedListener(listener);
        handler.handleInitializationOptions(params);
        assertTrue(isWorkspaceInitialized(prefs));
        assertTrue(changed[0]);
        changed[0] = false;
        handler.handleInitializationOptions(params);
        assertFalse(changed[0]);
    } finally {
        prefs.putBoolean(IConstants.WORKSPACE_INITIALIZED, isWorkspaceInitialized);
        JavaRuntime.removeVMInstallChangedListener(listener);
        JavaRuntime.setDefaultVMInstall(defaultVM, new NullProgressMonitor());
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) PropertyChangeEvent(org.eclipse.jdt.launching.PropertyChangeEvent) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) HashMap(java.util.HashMap) IVMInstallChangedListener(org.eclipse.jdt.launching.IVMInstallChangedListener) InitializeParams(org.eclipse.lsp4j.InitializeParams) IVMInstall(org.eclipse.jdt.launching.IVMInstall) File(java.io.File) AbstractProjectsManagerBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest) Test(org.junit.Test)

Example 19 with InitializeParams

use of org.eclipse.lsp4j.InitializeParams 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)

Aggregations

InitializeParams (org.eclipse.lsp4j.InitializeParams)19 ClientCapabilities (org.eclipse.lsp4j.ClientCapabilities)11 TextDocumentClientCapabilities (org.eclipse.lsp4j.TextDocumentClientCapabilities)9 WorkspaceClientCapabilities (org.eclipse.lsp4j.WorkspaceClientCapabilities)8 InitializeResult (org.eclipse.lsp4j.InitializeResult)7 RenameCapabilities (org.eclipse.lsp4j.RenameCapabilities)6 ExecuteCommandCapabilities (org.eclipse.lsp4j.ExecuteCommandCapabilities)5 WorkspaceFolder (org.eclipse.lsp4j.WorkspaceFolder)5 File (java.io.File)4 CompletableFuture (java.util.concurrent.CompletableFuture)4 Range (org.eclipse.lsp4j.Range)4 TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)4 ArrayList (java.util.ArrayList)3 URI (org.eclipse.emf.common.util.URI)3 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)3 CodeActionParams (org.eclipse.lsp4j.CodeActionParams)3 Diagnostic (org.eclipse.lsp4j.Diagnostic)3 DidChangeWorkspaceFoldersParams (org.eclipse.lsp4j.DidChangeWorkspaceFoldersParams)3 DocumentSymbolCapabilities (org.eclipse.lsp4j.DocumentSymbolCapabilities)3 Position (org.eclipse.lsp4j.Position)3