From 38ec5594789d41faeda0ef7b519b706b6cda67d3 Mon Sep 17 00:00:00 2001 From: Kris De Volder Date: Tue, 8 Nov 2016 15:18:27 -0800 Subject: [PATCH] Make vscode-extensions work again --- .../languageserver/LaunguageServerApp.java | 38 +++++++++++++++---- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/vscode-extensions/commons/commons-language-server/src/main/java/org/springframework/ide/vscode/commons/languageserver/LaunguageServerApp.java b/vscode-extensions/commons/commons-language-server/src/main/java/org/springframework/ide/vscode/commons/languageserver/LaunguageServerApp.java index 0caed326d..18c34f57c 100644 --- a/vscode-extensions/commons/commons-language-server/src/main/java/org/springframework/ide/vscode/commons/languageserver/LaunguageServerApp.java +++ b/vscode-extensions/commons/commons-language-server/src/main/java/org/springframework/ide/vscode/commons/languageserver/LaunguageServerApp.java @@ -4,12 +4,16 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintStream; -import java.io.PrintWriter; import java.net.Socket; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.function.Function; import java.util.logging.Level; import java.util.logging.Logger; import org.eclipse.lsp4j.jsonrpc.Launcher; +import org.eclipse.lsp4j.jsonrpc.MessageConsumer; import org.eclipse.lsp4j.services.LanguageClient; import org.eclipse.lsp4j.services.LanguageClientAware; import org.eclipse.lsp4j.services.LanguageServer; @@ -25,13 +29,13 @@ import com.google.inject.Provider; * Then call this class's start method with a Provider as * a argument. *

- * Alternatively, you can also subclass it and implement the abstract + * Alternatively, you can also subclass it and implement the abstract * `createServer` method. - * + * * @author Kris De Volder */ public abstract class LaunguageServerApp { - + public static void start(Provider languageServerFactory) throws IOException { LaunguageServerApp app = new LaunguageServerApp() { @Override @@ -134,18 +138,36 @@ public abstract class LaunguageServerApp { * 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) { + protected void run(Connection connection) throws InterruptedException, ExecutionException { LanguageServer server = createServer(); - boolean validate = false; // not totally sure what it does, disabling it for now. - Launcher launcher = Launcher.createLauncher(server, LanguageClient.class, connection.in, connection.out, validate, new PrintWriter(System.out)); + ExecutorService executor = Executors.newCachedThreadPool(); + Function 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.log(Level.WARNING, "Unsupported message was ignored!", e); + } + }; + }; + Launcher launcher = Launcher.createLauncher(server, + LanguageClient.class, + connection.in, + connection.out, + executor, + wrapper + ); if (server instanceof LanguageClientAware) { LanguageClient client = launcher.getRemoteProxy(); ((LanguageClientAware) server).connect(client); } - launcher.startListening(); + launcher.startListening().get(); } protected abstract LanguageServer createServer();