private StreamProvider createProvider() { Integer port = JDTEnvironmentUtils.getClientPort(); if (port != null) { return new SocketStreamProvider(JDTEnvironmentUtils.getClientHost(), port); } return new StdIOStreamProvider(); }
/** * Has no effect, and always returns with {@code false} if the JDT LS has been * started from the source either in debug or development mode. If the * {@code CLIENT_HOST} and {@code CLIENT_PORT} environment variables are set and * the {@link JDTEnvironmentUtils#SOCKET_STREAM_DEBUG socket.stream.debug} is * set to {@code true}, the the server will start with plain socket connection * and will wait until the client connects. */ public static boolean inSocketStreamDebugMode() { return Boolean.parseBoolean(Environment.get(SOCKET_STREAM_DEBUG, "false")) && (Platform.inDebugMode() || Platform.inDevelopmentMode()) && getClientHost() != null && getClientPort() != null; }
private void startConnection() throws IOException { Launcher<JavaLanguageClient> launcher; ExecutorService executorService = Executors.newCachedThreadPool(); protocol = new JDTLanguageServer(projectsManager, preferenceManager); if (JDTEnvironmentUtils.inSocketStreamDebugMode()) { String host = JDTEnvironmentUtils.getClientHost(); Integer port = JDTEnvironmentUtils.getClientPort(); InetSocketAddress inetSocketAddress = new InetSocketAddress(host, port); AsynchronousServerSocketChannel serverSocket = AsynchronousServerSocketChannel.open().bind(inetSocketAddress); try { AsynchronousSocketChannel socketChannel = serverSocket.accept().get(); InputStream in = Channels.newInputStream(socketChannel); OutputStream out = Channels.newOutputStream(socketChannel); Function<MessageConsumer, MessageConsumer> messageConsumer = it -> it; launcher = Launcher.createIoLauncher(protocol, JavaLanguageClient.class, in, out, executorService, messageConsumer); } catch (InterruptedException | ExecutionException e) { throw new RuntimeException("Error when opening a socket channel at " + host + ":" + port + ".", e); } } else { ConnectionStreamFactory connectionFactory = new ConnectionStreamFactory(); InputStream in = connectionFactory.getInputStream(); OutputStream out = connectionFactory.getOutputStream(); Function<MessageConsumer, MessageConsumer> wrapper = new ParentProcessWatcher(this.languageServer); launcher = Launcher.createLauncher(protocol, JavaLanguageClient.class, in, out, executorService, wrapper); } protocol.connectClient(launcher.getRemoteProxy()); launcher.startListening(); }