Search in sources :

Example 1 with InitializeParams

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

the class SonarLintLanguageServerTest method initialize_should_not_crash_when_disableTelemetry_param_missing.

@Test
public void initialize_should_not_crash_when_disableTelemetry_param_missing() {
    NullInputStream input = new NullInputStream(1000);
    NullOutputStream output = new NullOutputStream();
    SonarLintLanguageServer ls = new SonarLintLanguageServer(input, output, Collections.emptyList());
    InitializeParams params = mock(InitializeParams.class);
    when(params.getInitializationOptions()).thenReturn(Collections.emptyMap());
    ls.initialize(params);
}
Also used : InitializeParams(org.eclipse.lsp4j.InitializeParams) NullInputStream(org.apache.commons.io.input.NullInputStream) NullOutputStream(org.apache.commons.io.output.NullOutputStream) Test(org.junit.Test)

Example 2 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) {
    try {
        InitializeParams _initializeParams = new InitializeParams();
        final Procedure1<InitializeParams> _function = (InitializeParams it) -> {
            it.setProcessId(Integer.valueOf(1));
            it.setRootUri(this._uriExtensions.toUriString(this.root.toURI().normalize()));
        };
        final InitializeParams params = ObjectExtensions.<InitializeParams>operator_doubleArrow(_initializeParams, _function);
        if (initializer != null) {
            initializer.apply(params);
        }
        return this.languageServer.initialize(params).get();
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : InitializeParams(org.eclipse.lsp4j.InitializeParams)

Example 3 with InitializeParams

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

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

the class CommandServiceTest method testExecute.

@Test
public void testExecute() throws Exception {
    initialize((InitializeParams it) -> {
        ClientCapabilities clientCapabilities = new ClientCapabilities();
        WorkspaceClientCapabilities workspaceClientCapabilities = new WorkspaceClientCapabilities();
        workspaceClientCapabilities.setExecuteCommand(new ExecuteCommandCapabilities(true));
        clientCapabilities.setWorkspace(workspaceClientCapabilities);
        it.setCapabilities(clientCapabilities);
    });
    testExecuteCommand((TestExecuteCommandConfiguration cfg) -> {
        cfg.command = "testlang.a";
        cfg.assertCommandResult = (Object o) -> {
            if (o instanceof String) {
                assertEquals("a", (String) o);
            } else {
                Assert.fail("no string");
            }
        };
    });
    testExecuteCommand((TestExecuteCommandConfiguration cfg) -> {
        cfg.command = "testlang.b";
        cfg.assertCommandResult = (Object o) -> {
            if (o instanceof String) {
                assertEquals("b", (String) o);
            } else {
                Assert.fail("no string");
            }
        };
    });
    testExecuteCommand((TestExecuteCommandConfiguration cfg) -> {
        cfg.command = "doesnotexist.c";
        cfg.assertCommandResult = (Object o) -> {
            Assert.assertNull(o);
        };
    });
}
Also used : WorkspaceClientCapabilities(org.eclipse.lsp4j.WorkspaceClientCapabilities) WorkspaceClientCapabilities(org.eclipse.lsp4j.WorkspaceClientCapabilities) ClientCapabilities(org.eclipse.lsp4j.ClientCapabilities) InitializeParams(org.eclipse.lsp4j.InitializeParams) ExecuteCommandCapabilities(org.eclipse.lsp4j.ExecuteCommandCapabilities) Test(org.junit.Test)

Example 5 with InitializeParams

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

the class RenameTest3 method initialize.

@Override
protected InitializeResult initialize() {
    return super.initialize((InitializeParams params) -> {
        ClientCapabilities clientCapabilities = new ClientCapabilities();
        WorkspaceClientCapabilities workspaceClientCapabilities = new WorkspaceClientCapabilities();
        WorkspaceEditCapabilities workspaceEditCapabilities = new WorkspaceEditCapabilities();
        workspaceEditCapabilities.setDocumentChanges(true);
        workspaceClientCapabilities.setWorkspaceEdit(workspaceEditCapabilities);
        clientCapabilities.setWorkspace(workspaceClientCapabilities);
        TextDocumentClientCapabilities textDocumentClientCapabilities = new TextDocumentClientCapabilities();
        textDocumentClientCapabilities.setRename(new RenameCapabilities(true, false));
        clientCapabilities.setTextDocument(textDocumentClientCapabilities);
        params.setCapabilities(clientCapabilities);
    });
}
Also used : WorkspaceClientCapabilities(org.eclipse.lsp4j.WorkspaceClientCapabilities) WorkspaceEditCapabilities(org.eclipse.lsp4j.WorkspaceEditCapabilities) RenameCapabilities(org.eclipse.lsp4j.RenameCapabilities) WorkspaceClientCapabilities(org.eclipse.lsp4j.WorkspaceClientCapabilities) TextDocumentClientCapabilities(org.eclipse.lsp4j.TextDocumentClientCapabilities) ClientCapabilities(org.eclipse.lsp4j.ClientCapabilities) InitializeParams(org.eclipse.lsp4j.InitializeParams) TextDocumentClientCapabilities(org.eclipse.lsp4j.TextDocumentClientCapabilities)

Aggregations

InitializeParams (org.eclipse.lsp4j.InitializeParams)17 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 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 PrepareRenameParams (org.eclipse.lsp4j.PrepareRenameParams)3