Search in sources :

Example 6 with WorkspaceFolder

use of org.eclipse.lsp4j.WorkspaceFolder 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 7 with WorkspaceFolder

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

the class SimpleWorkspaceService method didChangeWorkspaceFolders.

@Override
public synchronized void didChangeWorkspaceFolders(DidChangeWorkspaceFoldersParams params) {
    WorkspaceFoldersChangeEvent evt = params.getEvent();
    boolean changed = false;
    for (WorkspaceFolder r : evt.getAdded()) {
        workspaceRoots.add(r);
        changed = true;
    }
    for (WorkspaceFolder r : evt.getRemoved()) {
        workspaceRoots.remove(r);
        changed = true;
    }
    if (changed) {
        workspaceFolderListeners.fire(params);
    }
}
Also used : WorkspaceFoldersChangeEvent(org.eclipse.lsp4j.WorkspaceFoldersChangeEvent) WorkspaceFolder(org.eclipse.lsp4j.WorkspaceFolder)

Aggregations

WorkspaceFolder (org.eclipse.lsp4j.WorkspaceFolder)7 ArrayList (java.util.ArrayList)4 URI (java.net.URI)2 ImmutableList (com.google.common.collect.ImmutableList)1 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 File (java.io.File)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 BlockingQueue (java.util.concurrent.BlockingQueue)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1