Search in sources :

Example 1 with LanguageClientAware

use of org.eclipse.lsp4j.services.LanguageClientAware in project ballerina by ballerina-lang.

the class Main method startServer.

public static void startServer(InputStream in, OutputStream out) throws InterruptedException, ExecutionException {
    BallerinaLanguageServer server = new BallerinaLanguageServer();
    Launcher<LanguageClient> l = LSPLauncher.createServerLauncher(server, in, out);
    LanguageClient client = l.getRemoteProxy();
    ((LanguageClientAware) server).connect(client);
    Future<?> startListening = l.startListening();
    startListening.get();
}
Also used : BallerinaLanguageServer(org.ballerinalang.langserver.BallerinaLanguageServer) LanguageClient(org.eclipse.lsp4j.services.LanguageClient) LanguageClientAware(org.eclipse.lsp4j.services.LanguageClientAware)

Example 2 with LanguageClientAware

use of org.eclipse.lsp4j.services.LanguageClientAware 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 3 with LanguageClientAware

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

the class LaunguageServerApp method run.

/**
 * Listen for requests from the parent node process.
 * Send replies asynchronously.
 * When the request stream is closed, wait for 5s for all outstanding responses to compute, then return.
 * @throws ExecutionException
 * @throws InterruptedException
 */
protected void run(Connection connection) throws InterruptedException, ExecutionException {
    LanguageServer server = createServer();
    ExecutorService executor = createServerThreads();
    Function<MessageConsumer, MessageConsumer> wrapper = (MessageConsumer consumer) -> {
        return (msg) -> {
            try {
                consumer.consume(msg);
            } catch (UnsupportedOperationException e) {
                // log a warning and ignore. We are getting some messages from vsCode the server doesn't know about
                Log.warn("Unsupported message was ignored!", e);
            }
        };
    };
    Launcher<STS4LanguageClient> launcher = Launcher.createLauncher(server, STS4LanguageClient.class, connection.in, connection.out, executor, wrapper);
    if (server instanceof LanguageClientAware) {
        LanguageClient client = launcher.getRemoteProxy();
        ((LanguageClientAware) server).connect(client);
    }
    launcher.startListening().get();
}
Also used : LanguageServer(org.eclipse.lsp4j.services.LanguageServer) SimpleLanguageServer(org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer) MessageConsumer(org.eclipse.lsp4j.jsonrpc.MessageConsumer) ExecutorService(java.util.concurrent.ExecutorService) LanguageClient(org.eclipse.lsp4j.services.LanguageClient) LanguageClientAware(org.eclipse.lsp4j.services.LanguageClientAware)

Aggregations

LanguageClientAware (org.eclipse.lsp4j.services.LanguageClientAware)3 LanguageClient (org.eclipse.lsp4j.services.LanguageClient)2 CompletableFuture (java.util.concurrent.CompletableFuture)1 ExecutorService (java.util.concurrent.ExecutorService)1 BallerinaLanguageServer (org.ballerinalang.langserver.BallerinaLanguageServer)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 InitializeParams (org.eclipse.lsp4j.InitializeParams)1 MessageActionItem (org.eclipse.lsp4j.MessageActionItem)1 MessageParams (org.eclipse.lsp4j.MessageParams)1 PublishDiagnosticsParams (org.eclipse.lsp4j.PublishDiagnosticsParams)1 RegistrationParams (org.eclipse.lsp4j.RegistrationParams)1 ShowMessageRequestParams (org.eclipse.lsp4j.ShowMessageRequestParams)1 TextDocumentClientCapabilities (org.eclipse.lsp4j.TextDocumentClientCapabilities)1 WorkspaceClientCapabilities (org.eclipse.lsp4j.WorkspaceClientCapabilities)1 MessageConsumer (org.eclipse.lsp4j.jsonrpc.MessageConsumer)1