eclipse-lsp4j / lsp4j

A Java implementation of the language server protocol intended to be consumed by tools and language servers implemented in Java.
https://eclipse.org/lsp4j
Other
599 stars 143 forks source link

Question - LanguageServer shutdown and exit #720

Closed gquerret closed 1 year ago

gquerret commented 1 year ago

When using VSCode remote workspaces (with SSH), my language server (which is using LSP4J) stays alive forever on the server. I currently implement the shutdown entrypoint:

@Override
public CompletableFuture<Object> shutdown() {
  // Stop subprocesses started by the LS and various monitors
  return CompletableFuture.completedFuture(Boolean.TRUE); // Javadoc does not specify which kind of Object to return
}

And also the exit entrypoing:

@Override
public void exit() {
  LOGGER.info("Bye !");
  System.exit(0);
}

In VSCode, when using File -> Close Folder or File -> Close Remote Connection, the shutdown entrypoint is called, but not exit. Is that expected ? Or is there another way to stop the LS ?

nixel2007 commented 1 year ago

Looks like it is a question for vscode team

gquerret commented 1 year ago

I have to admit that the exit() entrypoint is also not called when VSCode manages a local directory. Closing the VSCode window kills the Java process, but exit() is not called. Any hint on how to manage a clean shutdown of the LS (from VSCode or any other editor) ?

gquerret commented 1 year ago

I think I have my answer here. As the shutdown entrypoint can cancel the shutdown request, it has to return an object to confirm the shutdown, and then handle the shutdown by itself.