Search in sources :

Example 11 with WorkspaceFolder

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

the class PropertyReferenceFinderTest method wsFolder.

private Collection<WorkspaceFolder> wsFolder(Path directory) {
    if (directory != null) {
        WorkspaceFolder folder = new WorkspaceFolder();
        folder.setName(directory.getFileName().toString());
        folder.setUri(directory.toUri().toString());
        return ImmutableList.of(folder);
    }
    return ImmutableList.of();
}
Also used : WorkspaceFolder(org.eclipse.lsp4j.WorkspaceFolder)

Example 12 with WorkspaceFolder

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

the class SimpleLanguageServer method getWorkspaceFolders.

private List<WorkspaceFolder> getWorkspaceFolders(InitializeParams params) {
    List<WorkspaceFolder> initialFolders = new ArrayList<>();
    Object initOptions = params.getInitializationOptions();
    if (initOptions != null && initOptions instanceof JsonObject) {
        JsonObject initializationOptions = (JsonObject) initOptions;
        JsonElement folders = initializationOptions.get("workspaceFolders");
        if (folders != null && folders instanceof JsonArray) {
            JsonArray workspaceFolders = (JsonArray) folders;
            for (JsonElement object : workspaceFolders) {
                String folderUri = object.getAsString();
                String folderName = null;
                int folderNameStart = folderUri.lastIndexOf("/");
                if (folderNameStart > 0) {
                    folderName = folderUri.substring(folderUri.lastIndexOf("/") + 1);
                }
                WorkspaceFolder folder = new WorkspaceFolder();
                folder.setName(folderName);
                folder.setUri(folderUri);
                initialFolders.add(folder);
            }
        }
    }
    return initialFolders;
}
Also used : JsonArray(com.google.gson.JsonArray) JsonElement(com.google.gson.JsonElement) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) JsonObject(com.google.gson.JsonObject) WorkspaceFolder(org.eclipse.lsp4j.WorkspaceFolder)

Example 13 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 14 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)

Example 15 with WorkspaceFolder

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

the class WorkspaceFolderChangeHandlerTest method testUpdateWorkspaceFolder.

@Test
public void testUpdateWorkspaceFolder() throws Exception {
    File rootFolder = copyFiles("maven/salut", true);
    String rootFolderUri = rootFolder.toURI().toString();
    IPath rootFolderPath = ResourceUtils.canonicalFilePathFromURI(rootFolderUri);
    WorkspaceFolder workspaceFolder = new WorkspaceFolder(rootFolder.toURI().toString());
    WorkspaceFoldersChangeEvent event = new WorkspaceFoldersChangeEvent(Arrays.asList(workspaceFolder), Collections.emptyList());
    DidChangeWorkspaceFoldersParams params = new DidChangeWorkspaceFoldersParams(event);
    workspaceFolderChangeHander.update(params);
    assertTrue(preferenceManager.getPreferences().getRootPaths().contains(rootFolderPath));
    waitForBackgroundJobs();
    event = new WorkspaceFoldersChangeEvent(Collections.emptyList(), Arrays.asList(workspaceFolder));
    params = new DidChangeWorkspaceFoldersParams(event);
    workspaceFolderChangeHander.update(params);
    assertFalse(preferenceManager.getPreferences().getRootPaths().contains(rootFolderPath));
}
Also used : IPath(org.eclipse.core.runtime.IPath) WorkspaceFoldersChangeEvent(org.eclipse.lsp4j.WorkspaceFoldersChangeEvent) File(java.io.File) DidChangeWorkspaceFoldersParams(org.eclipse.lsp4j.DidChangeWorkspaceFoldersParams) WorkspaceFolder(org.eclipse.lsp4j.WorkspaceFolder) Test(org.junit.Test) AbstractProjectsManagerBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest)

Aggregations

WorkspaceFolder (org.eclipse.lsp4j.WorkspaceFolder)15 ArrayList (java.util.ArrayList)5 InitializeParams (org.eclipse.lsp4j.InitializeParams)4 WorkspaceFoldersChangeEvent (org.eclipse.lsp4j.WorkspaceFoldersChangeEvent)4 File (java.io.File)3 DidChangeWorkspaceFoldersParams (org.eclipse.lsp4j.DidChangeWorkspaceFoldersParams)3 InitializeResult (org.eclipse.lsp4j.InitializeResult)3 ImmutableList (com.google.common.collect.ImmutableList)2 URI (java.net.URI)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 IPath (org.eclipse.core.runtime.IPath)2 ClientCapabilities (org.eclipse.lsp4j.ClientCapabilities)2 DocumentSymbolCapabilities (org.eclipse.lsp4j.DocumentSymbolCapabilities)2 ServerCapabilities (org.eclipse.lsp4j.ServerCapabilities)2 TextDocumentClientCapabilities (org.eclipse.lsp4j.TextDocumentClientCapabilities)2