Search in sources :

Example 1 with LanguageClient

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

the class SocketServerLauncher method main.

public static void main(final String[] args) {
    try {
        ServerModule _serverModule = new ServerModule();
        final Injector injector = Guice.createInjector(_serverModule);
        final LanguageServer languageServer = injector.<LanguageServer>getInstance(LanguageServer.class);
        final ServerSocketChannel serverSocket = ServerSocketChannel.open();
        InetSocketAddress _inetSocketAddress = new InetSocketAddress("localhost", 5007);
        serverSocket.bind(_inetSocketAddress);
        final SocketChannel socketChannel = serverSocket.accept();
        InputStream _newInputStream = Channels.newInputStream(socketChannel);
        OutputStream _newOutputStream = Channels.newOutputStream(socketChannel);
        PrintWriter _printWriter = new PrintWriter(System.out);
        final Launcher<LanguageClient> launcher = LSPLauncher.createServerLauncher(languageServer, _newInputStream, _newOutputStream, true, _printWriter);
        launcher.startListening().get();
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : LanguageServer(org.eclipse.lsp4j.services.LanguageServer) ServerSocketChannel(java.nio.channels.ServerSocketChannel) SocketChannel(java.nio.channels.SocketChannel) Injector(com.google.inject.Injector) InetSocketAddress(java.net.InetSocketAddress) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) LanguageClient(org.eclipse.lsp4j.services.LanguageClient) ServerSocketChannel(java.nio.channels.ServerSocketChannel) ServerModule(org.eclipse.xtext.ide.server.ServerModule) PrintWriter(java.io.PrintWriter)

Example 2 with LanguageClient

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

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

the class SimpleTextDocumentService method publishDiagnostics.

public void publishDiagnostics(TextDocumentIdentifier docId, Collection<Diagnostic> diagnostics) {
    LanguageClient client = server.getClient();
    if (client != null && diagnostics != null) {
        PublishDiagnosticsParams params = new PublishDiagnosticsParams();
        params.setUri(docId.getUri());
        params.setDiagnostics(ImmutableList.copyOf(diagnostics));
        client.publishDiagnostics(params);
    }
}
Also used : LanguageClient(org.eclipse.lsp4j.services.LanguageClient) PublishDiagnosticsParams(org.eclipse.lsp4j.PublishDiagnosticsParams)

Example 4 with LanguageClient

use of org.eclipse.lsp4j.services.LanguageClient 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)

Example 5 with LanguageClient

use of org.eclipse.lsp4j.services.LanguageClient in project vscode-nextgenas by BowlerHatLLC.

the class Main method main.

/**
     * The main entry point when the JAR is run. Opens a socket to communicate
     * with Visual Studio Code using the port specified with the
     * -Dnextgeas.vscode.port command line option. Then, instantiates the
     * ActionScriptLanguageServer, and passes it to the LSP4J library,
     * which handles all of the language server protocol communication.
     * LSP4J calls methods on ActionScriptLanguageServer as requests come in
     * from the text editor.
     */
public static void main(String[] args) {
    String port = System.getProperty(SYSTEM_PROPERTY_PORT);
    if (port == null) {
        System.err.println("NextGen ActionScript language server encountered an error: System property nextgeas.vscode.port is required.");
        System.exit(MISSING_PORT);
    }
    try {
        Socket socket = new Socket(SOCKET_HOST, Integer.parseInt(port));
        ActionScriptLanguageServer server = new ActionScriptLanguageServer();
        Launcher<LanguageClient> launcher = LSPLauncher.createServerLauncher(server, socket.getInputStream(), socket.getOutputStream());
        server.connect(launcher.getRemoteProxy());
        launcher.startListening();
    } catch (Exception e) {
        System.err.println("NextGen ActionScript language server failed to connect.");
        System.err.println("Visit the following URL to file an issue, and please include this log: https://github.com/BowlerHatLLC/vscode-nextgenas/issues");
        e.printStackTrace(System.err);
        System.exit(SERVER_CONNECT_ERROR);
    }
}
Also used : LanguageClient(org.eclipse.lsp4j.services.LanguageClient) Socket(java.net.Socket)

Aggregations

LanguageClient (org.eclipse.lsp4j.services.LanguageClient)10 Injector (com.google.inject.Injector)2 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 PrintWriter (java.io.PrintWriter)2 ExecutionException (java.util.concurrent.ExecutionException)2 LanguageClientAware (org.eclipse.lsp4j.services.LanguageClientAware)2 LanguageServer (org.eclipse.lsp4j.services.LanguageServer)2 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 Socket (java.net.Socket)1 AsynchronousServerSocketChannel (java.nio.channels.AsynchronousServerSocketChannel)1 AsynchronousSocketChannel (java.nio.channels.AsynchronousSocketChannel)1 ServerSocketChannel (java.nio.channels.ServerSocketChannel)1 SocketChannel (java.nio.channels.SocketChannel)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ExecutorService (java.util.concurrent.ExecutorService)1 OnOpen (javax.websocket.OnOpen)1 BallerinaLanguageServer (org.ballerinalang.langserver.BallerinaLanguageServer)1 URI (org.eclipse.emf.common.util.URI)1