Search in sources :

Example 1 with SimpleLanguageServer

use of org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer in project sts4 by spring-projects.

the class LaunguageServerApp method startAsServer.

/**
 * starts up the language server and let it listen for connections from the outside
 * instead of connecting itself to an existing port or channel.
 *
 * This is meant for development only, to reduce turnaround times while working
 * on the language server from within an IDE, so that you can start the language
 * server right away in debug mode and let the vscode extension connect to that
 * instance instead of vice versa.
 *
 * Source of inspiration:
 * https://github.com/itemis/xtext-languageserver-example/blob/master/org.xtext.example.mydsl.ide/src/org/xtext/example/mydsl/ide/RunServer.java
 */
public void startAsServer() throws IOException, InterruptedException {
    Log.info("Starting LS as standlone server");
    Function<MessageConsumer, MessageConsumer> wrapper = consumer -> {
        MessageConsumer result = consumer;
        return result;
    };
    SimpleLanguageServer languageServer = createServer();
    Launcher<STS4LanguageClient> launcher = createSocketLauncher(languageServer, STS4LanguageClient.class, new InetSocketAddress("localhost", SERVER_STANDALONE_PORT), createServerThreads(), wrapper);
    languageServer.connect(launcher.getRemoteProxy());
    Future<?> future = launcher.startListening();
    while (!future.isDone()) {
        Thread.sleep(10_000l);
    }
}
Also used : OutputStream(java.io.OutputStream) PrintStream(java.io.PrintStream) AsynchronousServerSocketChannel(java.nio.channels.AsynchronousServerSocketChannel) LanguageClientAware(org.eclipse.lsp4j.services.LanguageClientAware) Socket(java.net.Socket) Launcher(org.eclipse.lsp4j.jsonrpc.Launcher) LanguageClient(org.eclipse.lsp4j.services.LanguageClient) SocketAddress(java.net.SocketAddress) Provider(javax.inject.Provider) Log(org.springframework.ide.vscode.commons.util.Log) Channels(java.nio.channels.Channels) IOException(java.io.IOException) LanguageServer(org.eclipse.lsp4j.services.LanguageServer) InetSocketAddress(java.net.InetSocketAddress) Function(java.util.function.Function) Executors(java.util.concurrent.Executors) MessageConsumer(org.eclipse.lsp4j.jsonrpc.MessageConsumer) ExecutionException(java.util.concurrent.ExecutionException) Future(java.util.concurrent.Future) LoggingFormat(org.springframework.ide.vscode.commons.languageserver.util.LoggingFormat) ExecutorService(java.util.concurrent.ExecutorService) InputStream(java.io.InputStream) AsynchronousSocketChannel(java.nio.channels.AsynchronousSocketChannel) SimpleLanguageServer(org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer) MessageConsumer(org.eclipse.lsp4j.jsonrpc.MessageConsumer) SimpleLanguageServer(org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer) InetSocketAddress(java.net.InetSocketAddress)

Aggregations

IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 PrintStream (java.io.PrintStream)1 InetSocketAddress (java.net.InetSocketAddress)1 Socket (java.net.Socket)1 SocketAddress (java.net.SocketAddress)1 AsynchronousServerSocketChannel (java.nio.channels.AsynchronousServerSocketChannel)1 AsynchronousSocketChannel (java.nio.channels.AsynchronousSocketChannel)1 Channels (java.nio.channels.Channels)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1 Executors (java.util.concurrent.Executors)1 Future (java.util.concurrent.Future)1 Function (java.util.function.Function)1 Provider (javax.inject.Provider)1 Launcher (org.eclipse.lsp4j.jsonrpc.Launcher)1 MessageConsumer (org.eclipse.lsp4j.jsonrpc.MessageConsumer)1 LanguageClient (org.eclipse.lsp4j.services.LanguageClient)1 LanguageClientAware (org.eclipse.lsp4j.services.LanguageClientAware)1