Search in sources :

Example 1 with RegistrationParams

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

the class LanguageServerHarness method intialize.

public InitializeResult intialize(File workspaceRoot) throws Exception {
    server = factory.call();
    int parentPid = random.nextInt(40000) + 1000;
    InitializeParams initParams = new InitializeParams();
    if (workspaceRoot != null) {
        initParams.setRootPath(workspaceRoot.toString());
        initParams.setRootUri(UriUtil.toUri(workspaceRoot).toString());
    }
    initParams.setProcessId(parentPid);
    ClientCapabilities clientCap = new ClientCapabilities();
    TextDocumentClientCapabilities textCap = new TextDocumentClientCapabilities();
    CompletionCapabilities completionCap = new CompletionCapabilities(new CompletionItemCapabilities(true));
    textCap.setCompletion(completionCap);
    clientCap.setTextDocument(textCap);
    WorkspaceClientCapabilities workspaceCap = new WorkspaceClientCapabilities();
    workspaceCap.setApplyEdit(true);
    ExecuteCommandCapabilities exeCap = new ExecuteCommandCapabilities();
    exeCap.setDynamicRegistration(true);
    workspaceCap.setExecuteCommand(exeCap);
    clientCap.setWorkspace(workspaceCap);
    initParams.setCapabilities(clientCap);
    initResult = getServer().initialize(initParams).get();
    if (getServer() instanceof LanguageClientAware) {
        ((LanguageClientAware) getServer()).connect(new STS4LanguageClient() {

            @Override
            public void telemetryEvent(Object object) {
            // TODO Auto-generated method stub
            }

            @Override
            public CompletableFuture<MessageActionItem> showMessageRequest(ShowMessageRequestParams requestParams) {
                // TODO Auto-generated method stub
                return CompletableFuture.completedFuture(new MessageActionItem("Some Message Request Answer"));
            }

            @Override
            public void showMessage(MessageParams messageParams) {
            // TODO Auto-generated method stub
            }

            @Override
            public void publishDiagnostics(PublishDiagnosticsParams diagnostics) {
                receiveDiagnostics(diagnostics);
            }

            @Override
            public void highlight(HighlightParams highlights) {
                receiveHighlights(highlights);
            }

            @Override
            public void logMessage(MessageParams message) {
            // TODO Auto-generated method stub
            }

            @Override
            public CompletableFuture<ApplyWorkspaceEditResponse> applyEdit(ApplyWorkspaceEditParams params) {
                return Mono.fromCallable(() -> {
                    perform(params.getEdit());
                    return new ApplyWorkspaceEditResponse(true);
                }).toFuture();
            }

            @Override
            public CompletableFuture<Void> registerCapability(RegistrationParams params) {
                return CompletableFuture.completedFuture(null);
            }

            @Override
            public void progress(ProgressParams progressEvent) {
            // TODO Auto-generated method stub
            }

            @Override
            public CompletableFuture<Object> moveCursor(CursorMovement cursorMovement) {
                for (Editor editor : activeEditors) {
                    if (editor.getUri().equals(cursorMovement.getUri())) {
                        editor.setCursor(cursorMovement.getPosition());
                        return CompletableFuture.completedFuture(new ApplyWorkspaceEditResponse(true));
                    }
                }
                return CompletableFuture.completedFuture(new ApplyWorkspaceEditResponse(false));
            }

            @Override
            public CompletableFuture<ProjectResponse> project(String uri) {
                return CompletableFuture.completedFuture(null);
            }

            @Override
            public CompletableFuture<Object> addClasspathListener(ClasspathListenerParams params) {
                return CompletableFuture.completedFuture("ok");
            }

            @Override
            public CompletableFuture<Object> removeClasspathListener(ClasspathListenerParams classpathListenerParams) {
                return CompletableFuture.completedFuture("ok");
            }
        });
    }
    getServer().initialized();
    return initResult;
}
Also used : CursorMovement(org.springframework.ide.vscode.commons.languageserver.quickfix.QuickfixEdit.CursorMovement) ShowMessageRequestParams(org.eclipse.lsp4j.ShowMessageRequestParams) ClientCapabilities(org.eclipse.lsp4j.ClientCapabilities) WorkspaceClientCapabilities(org.eclipse.lsp4j.WorkspaceClientCapabilities) TextDocumentClientCapabilities(org.eclipse.lsp4j.TextDocumentClientCapabilities) CompletionItemCapabilities(org.eclipse.lsp4j.CompletionItemCapabilities) CompletableFuture(java.util.concurrent.CompletableFuture) RegistrationParams(org.eclipse.lsp4j.RegistrationParams) CompletionCapabilities(org.eclipse.lsp4j.CompletionCapabilities) ExecuteCommandCapabilities(org.eclipse.lsp4j.ExecuteCommandCapabilities) ApplyWorkspaceEditParams(org.eclipse.lsp4j.ApplyWorkspaceEditParams) ClasspathListenerParams(org.springframework.ide.vscode.commons.languageserver.jdt.ls.ClasspathListenerParams) STS4LanguageClient(org.springframework.ide.vscode.commons.languageserver.STS4LanguageClient) MessageParams(org.eclipse.lsp4j.MessageParams) LanguageClientAware(org.eclipse.lsp4j.services.LanguageClientAware) HighlightParams(org.springframework.ide.vscode.commons.languageserver.HighlightParams) InitializeParams(org.eclipse.lsp4j.InitializeParams) TextDocumentClientCapabilities(org.eclipse.lsp4j.TextDocumentClientCapabilities) MessageActionItem(org.eclipse.lsp4j.MessageActionItem) WorkspaceClientCapabilities(org.eclipse.lsp4j.WorkspaceClientCapabilities) ApplyWorkspaceEditResponse(org.eclipse.lsp4j.ApplyWorkspaceEditResponse) PublishDiagnosticsParams(org.eclipse.lsp4j.PublishDiagnosticsParams) ProgressParams(org.springframework.ide.vscode.commons.languageserver.ProgressParams)

Example 2 with RegistrationParams

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

the class JDTLanguageServer method registerCapability.

public void registerCapability(String id, String method, Object options) {
    if (registeredCapabilities.add(id)) {
        Registration registration = new Registration(id, method, options);
        RegistrationParams registrationParams = new RegistrationParams(Collections.singletonList(registration));
        client.registerCapability(registrationParams);
    }
}
Also used : RegistrationParams(org.eclipse.lsp4j.RegistrationParams) Registration(org.eclipse.lsp4j.Registration)

Example 3 with RegistrationParams

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

the class ExecutableCommandRegistry method register.

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);
    };
}
Also used : UnregistrationParams(org.eclipse.lsp4j.UnregistrationParams) RegistrationParams(org.eclipse.lsp4j.RegistrationParams) Registration(org.eclipse.lsp4j.Registration) Unregistration(org.eclipse.lsp4j.Unregistration) ExecuteCommandOptions(org.eclipse.lsp4j.ExecuteCommandOptions)

Example 4 with RegistrationParams

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

the class ClasspathListenerManager method addClasspathListener.

public Disposable addClasspathListener(ClasspathListener classpathListener) {
    String callbackCommandId = "sts4.classpath." + RandomStringUtils.randomAlphabetic(8);
    // 1. register callback command handler in SimpleLanguageServer
    Disposable unregisterCommand = server.onCommand(callbackCommandId, (ExecuteCommandParams callbackParams) -> async.invoke(() -> {
        List<Object> args = callbackParams.getArguments();
        // Note: not sure... but args might be deserialized as com.google.gson.JsonElement's.
        // If so the code below is not correct (casts will fail).
        String projectUri = ((JsonElement) args.get(0)).getAsString();
        String name = ((JsonElement) args.get(1)).getAsString();
        boolean deleted = ((JsonElement) args.get(2)).getAsBoolean();
        Classpath classpath = gson.fromJson((JsonElement) args.get(3), Classpath.class);
        classpathListener.changed(new ClasspathListener.Event(projectUri, name, deleted, classpath));
        return "done";
    }));
    // 2. register the callback command with the client
    String registrationId = UUID.randomUUID().toString();
    RegistrationParams params = new RegistrationParams(ImmutableList.of(new Registration(registrationId, WORKSPACE_EXECUTE_COMMAND, ImmutableMap.of("commands", ImmutableList.of(callbackCommandId)))));
    server.getClient().registerCapability(params).join();
    // 3. call the client to ask it to call that callback
    server.getClient().addClasspathListener(new ClasspathListenerParams(callbackCommandId)).join();
    // Cleanups:
    return () -> {
        try {
            log.info("Unregistering classpath callback " + callbackCommandId + " ...");
            this.server.getClient().removeClasspathListener(new ClasspathListenerParams(callbackCommandId)).join();
            log.info("Unregistering classpath callback " + callbackCommandId + " OK");
            this.server.getClient().unregisterCapability(new UnregistrationParams(ImmutableList.of(new Unregistration(registrationId, WORKSPACE_EXECUTE_COMMAND)))).join();
            unregisterCommand.dispose();
        } catch (Exception e) {
            log.error("", e);
        }
    };
}
Also used : Disposable(reactor.core.Disposable) UnregistrationParams(org.eclipse.lsp4j.UnregistrationParams) Unregistration(org.eclipse.lsp4j.Unregistration) ExecuteCommandParams(org.eclipse.lsp4j.ExecuteCommandParams) RegistrationParams(org.eclipse.lsp4j.RegistrationParams) JsonElement(com.google.gson.JsonElement) Registration(org.eclipse.lsp4j.Registration) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList)

Example 5 with RegistrationParams

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

the class SimpleLanguageServer method initialized.

@Override
public void initialized() {
    async.withLog(log, () -> {
        Registration registration = new Registration(WORKSPACE_FOLDERS_CAPABILITY_ID, WORKSPACE_FOLDERS_CAPABILITY_NAME, null);
        RegistrationParams registrationParams = new RegistrationParams(Collections.singletonList(registration));
        getClient().registerCapability(registrationParams);
        // triggers onInitialized handlers.
        this.initialized.complete(null);
    });
}
Also used : RegistrationParams(org.eclipse.lsp4j.RegistrationParams) Registration(org.eclipse.lsp4j.Registration)

Aggregations

RegistrationParams (org.eclipse.lsp4j.RegistrationParams)6 Registration (org.eclipse.lsp4j.Registration)5 Unregistration (org.eclipse.lsp4j.Unregistration)3 UnregistrationParams (org.eclipse.lsp4j.UnregistrationParams)3 List (java.util.List)2 ImmutableList (com.google.common.collect.ImmutableList)1 JsonElement (com.google.gson.JsonElement)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Consumer (java.util.function.Consumer)1 Collectors (java.util.stream.Collectors)1 ApplyWorkspaceEditParams (org.eclipse.lsp4j.ApplyWorkspaceEditParams)1 ApplyWorkspaceEditResponse (org.eclipse.lsp4j.ApplyWorkspaceEditResponse)1 ClientCapabilities (org.eclipse.lsp4j.ClientCapabilities)1 CompletionCapabilities (org.eclipse.lsp4j.CompletionCapabilities)1 CompletionItemCapabilities (org.eclipse.lsp4j.CompletionItemCapabilities)1 ExecuteCommandCapabilities (org.eclipse.lsp4j.ExecuteCommandCapabilities)1 ExecuteCommandOptions (org.eclipse.lsp4j.ExecuteCommandOptions)1 ExecuteCommandParams (org.eclipse.lsp4j.ExecuteCommandParams)1