A lsp/NoopHandle.java => lsp/NoopHandle.java +122 -0
@@ 0,0 1,122 @@
+package lsp;
+
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.Future;
+
+import org.eclipse.lsp4j.jsonrpc.Launcher;
+import org.eclipse.lsp4j.jsonrpc.RemoteEndpoint;
+import org.eclipse.lsp4j.services.LanguageServer;
+
+import org.eclipse.lsp4j.DidChangeConfigurationParams;
+import org.eclipse.lsp4j.DidChangeNotebookDocumentParams;
+import org.eclipse.lsp4j.DidChangeTextDocumentParams;
+import org.eclipse.lsp4j.DidChangeWatchedFilesParams;
+import org.eclipse.lsp4j.DidCloseNotebookDocumentParams;
+import org.eclipse.lsp4j.DidCloseTextDocumentParams;
+import org.eclipse.lsp4j.DidOpenNotebookDocumentParams;
+import org.eclipse.lsp4j.DidOpenTextDocumentParams;
+import org.eclipse.lsp4j.DidSaveNotebookDocumentParams;
+import org.eclipse.lsp4j.DidSaveTextDocumentParams;
+import org.eclipse.lsp4j.InitializeParams;
+import org.eclipse.lsp4j.InitializeResult;
+import org.eclipse.lsp4j.WorkDoneProgressCancelParams;
+import org.eclipse.lsp4j.services.LanguageServer;
+import org.eclipse.lsp4j.services.NotebookDocumentService;
+import org.eclipse.lsp4j.services.TextDocumentService;
+import org.eclipse.lsp4j.services.WorkspaceService;
+
+public class NoopHandle implements Launcher<LanguageServer> {
+ private LanguageServer mock;
+
+ public NoopHandle() {
+ this.mock = new MockLanguageServer();
+ }
+
+ public Future<Void> startListening() {
+ return null;
+ }
+
+ public LanguageServer getRemoteProxy() {
+ return this.mock;
+ }
+
+ public RemoteEndpoint getRemoteEndpoint() {
+ return null;
+ }
+
+ // Copied from: https://github.com/eclipse-lsp4j/lsp4j/blob/main/org.eclipse.lsp4j/src/test/java/org/eclipse/lsp4j/test/services/MockLanguageServer.java
+ private static class MockLanguageServer implements LanguageServer, NotebookDocumentService, TextDocumentService, WorkspaceService {
+ @Override
+ public CompletableFuture<InitializeResult> initialize(InitializeParams params) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public CompletableFuture<Object> shutdown() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void exit() {
+ }
+
+ @Override
+ public NotebookDocumentService getNotebookDocumentService() {
+ return this;
+ }
+
+ @Override
+ public TextDocumentService getTextDocumentService() {
+ return this;
+ }
+
+ @Override
+ public WorkspaceService getWorkspaceService() {
+ return this;
+ }
+
+ @Override
+ public void didChangeConfiguration(DidChangeConfigurationParams params) {
+ }
+
+ @Override
+ public void didChangeWatchedFiles(DidChangeWatchedFilesParams params) {
+ }
+
+ @Override
+ public void didOpen(DidOpenTextDocumentParams params) {
+ }
+
+ @Override
+ public void didChange(DidChangeTextDocumentParams params) {
+ }
+
+ @Override
+ public void didClose(DidCloseTextDocumentParams params) {
+ }
+
+ @Override
+ public void didSave(DidSaveTextDocumentParams params) {
+ }
+
+ @Override
+ public void didOpen(DidOpenNotebookDocumentParams params) {
+ }
+
+ @Override
+ public void didChange(DidChangeNotebookDocumentParams params) {
+ }
+
+ @Override
+ public void didClose(DidCloseNotebookDocumentParams params) {
+ }
+
+ @Override
+ public void didSave(DidSaveNotebookDocumentParams params) {
+ }
+
+ @Override
+ public void cancelProgress(WorkDoneProgressCancelParams params) {
+ }
+ }
+}
M lsp/Server.java => lsp/Server.java +6 -6
@@ 105,7 105,7 @@ public class Server {
this.client = new jEditLanguageClient(this);
this.process = new SubprocessServer(serverDefinition);
this.workspaceFolders = new ArrayList<>();
- this.handle = null;
+ this.handle = new NoopHandle();
this.initResult = null;
}
@@ 118,7 118,7 @@ public class Server {
}
public boolean isRunning() {
- return this.handle != null;
+ return !(this.handle instanceof NoopHandle);
}
public boolean isInitialized() {
@@ 138,14 138,14 @@ public class Server {
}
public void startIfNeeded(Buffer buffer) {
- if (starting || handle != null) {
+ if (starting || isRunning()) {
return;
}
start(buffer);
}
private synchronized void start(Buffer buffer) {
- if (starting || handle != null) {
+ if (starting || isRunning()) {
return;
}
starting = true;
@@ 181,7 181,7 @@ public class Server {
}
this.client.unpaintDiagnostics();
this.client.removeErrors();
- this.handle = null;
+ this.handle = new NoopHandle();
this.initResult = null;
this.starting = false;
}
@@ 211,7 211,7 @@ public class Server {
log(Log.NOTICE, "Server has stopped: " + this.process.getName());
log(Log.DEBUG, "(If the reason why is not clear, try running the server directly and observing its output.)");
log(Log.DEBUG, "(Standard output is captured by lsp4j, and is unfortunately not able to be read directly.)");
- this.handle = null;
+ this.handle = new NoopHandle();
this.initResult = null;
} catch (Exception e) {
log(Log.ERROR, "Server crashed", e);