ease debugging and development of the boot java ls by connecting both sides via a socket on demand

This commit is contained in:
Martin Lippert
2017-08-17 13:57:17 +02:00
parent e1aa67f5a5
commit 2b99d3848f
3 changed files with 130 additions and 1 deletions

View File

@@ -5,7 +5,7 @@
<extension
point="org.eclipse.lsp4e.languageServer">
<server
class="org.springframework.boot.ide.java.servers.SpringBootJavaLanguageServer"
class="org.springframework.boot.ide.java.servers.DelegatingStreamConnectionProvider"
id="org.eclipse.languageserver.languages.springbootjava"
label="Spring Boot Java Language Server">
</server>

View File

@@ -0,0 +1,65 @@
/*******************************************************************************
* Copyright (c) 2017 Pivotal, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Pivotal, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.boot.ide.java.servers;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.eclipse.lsp4e.server.StreamConnectionProvider;
/**
* if the system property "boot-java-ls-port" exists, delegate to the socket-based
* stream connection provider, otherwise use the standard process-based stream
* connection provider.
*
* This allows you to run the language server in server mode (listens on a port for
* a connection) and connect the IDE integration to that already running language
* server instead of starting a new process for it.
*
* @author Martin Lippert
*/
public class DelegatingStreamConnectionProvider implements StreamConnectionProvider {
private StreamConnectionProvider provider;
public DelegatingStreamConnectionProvider() {
String port = System.getProperty("boot-java-ls-port");
if (port != null) {
this.provider = new SpringBootJavaLanguageServerViaSocket(Integer.parseInt(port));
}
else {
this.provider = new SpringBootJavaLanguageServer();
}
}
@Override
public void start() throws IOException {
this.provider.start();
}
@Override
public InputStream getInputStream() {
return this.provider.getInputStream();
}
@Override
public OutputStream getOutputStream() {
return this.provider.getOutputStream();
}
@Override
public void stop() {
this.provider.stop();
}
}

View File

@@ -0,0 +1,64 @@
/*******************************************************************************
* Copyright (c) 2017 Pivotal, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Pivotal, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.boot.ide.java.servers;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import org.eclipse.lsp4e.server.StreamConnectionProvider;
public class SpringBootJavaLanguageServerViaSocket implements StreamConnectionProvider {
private OutputStream outputStream;
private InputStream inputStream;
private Socket socket;
private int port;
public SpringBootJavaLanguageServerViaSocket(int port) {
this.port = port;
}
@Override
public void start() throws IOException {
try {
socket = new Socket("localhost", port);
outputStream = socket.getOutputStream();
inputStream = socket.getInputStream();
}
catch (IOException e) {
e.printStackTrace();
}
}
@Override
public InputStream getInputStream() {
return inputStream;
}
@Override
public OutputStream getOutputStream() {
return outputStream;
}
@Override
public void stop() {
if (socket != null) {
try {
socket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}