lsp4j
lsp4j copied to clipboard
Shutdown if Parent Process Shuts Down
LS does not exit if the parent process is not alive see https://github.com/eclipse/xtext-core/issues/552
How could this be solved generically in LSP4J? I think it's the responsibility of the Xtext language server to take care of this.
i think lsp4j should provide a facilitly to make this a oneliner in every implementer of ILanguageServer or even should provide default method. since the wait loop is done in lsp4j anyway. that would be the point to check and shutdown.
maybe @akosyakov can give some hints how he implemented that in real world scenarios.
The code is here:
https://github.com/eclipse/lsp4j/blob/a78806c809d5daadd34403b32833d163443a3cce/org.eclipse.lsp4j.services/src/main/java/org/eclipse/lsp4j/services/transport/server/LanguageServerEndpoint.xtend#L83-L92
That was taken from the old LS-API implementation. It does not work anymore with the LSP4J code structure because the general JSON-RPC implementation in org.eclipse.lsp4j.jsonrpc does not depend on the actual protocol in org.eclipse.lsp4j (but the other way around). And I'm against adding a default implementation to the LanguageServer interface, since that would be overridden by existing implementations anyway.
We could add a utility class that can be used by the LanguageServer implementations.
On jdt.ls we ended up implementing a parent process check that would activate only after a period of inactivity because windows users were not happy with the constant resource consumption. https://github.com/eclipse/eclipse.jdt.ls/commit/8654474dd7fa5f0d1fb33c0c38ab254efe41c4df
I implemented a utility class in #164. However, it works only for Unix-type systems. We should't add new API that supports only some of the relevant operating systems.
If anyone is eager to solve this, feel free to extend my solution in #164 so it also supports Windows.
I have had success by simply exiting when System.in closes: https://github.com/georgewfraser/kotlin-language-server/commit/0c9e2d0b68892d3b62f5b1e9141c0e8f656e2262
BSL LS solved this problem via java's ProcessHandler and Spring's scheduler: https://github.com/1c-syntax/bsl-language-server/blob/develop/src/main/java/com/github/_1c_syntax/bsl/languageserver/ParentProcessWatcher.java
ProcessHandle also has an onExit that can be used to monitor this AFAICT
Optional.ofNullable(params.getProcessId())
.flatMap(ProcessHandle::of)
.ifPresent(processHandle -> {
processHandle.onExit().thenRun(this::exit);
});
@DavidGregory084 cool and clean solution. I'll give it a try.
@DavidGregory084 ok, it was some kind of hard to test, but it is working. thank you!
https://github.com/1c-syntax/bsl-language-server/pull/2881/files