lsp4j icon indicating copy to clipboard operation
lsp4j copied to clipboard

Shutdown if Parent Process Shuts Down

Open cdietrich opened this issue 7 years ago • 12 comments

LS does not exit if the parent process is not alive see https://github.com/eclipse/xtext-core/issues/552

cdietrich avatar Feb 20 '18 13:02 cdietrich

How could this be solved generically in LSP4J? I think it's the responsibility of the Xtext language server to take care of this.

spoenemann avatar Feb 22 '18 09:02 spoenemann

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.

cdietrich avatar Feb 22 '18 10:02 cdietrich

maybe @akosyakov can give some hints how he implemented that in real world scenarios.

cdietrich avatar Feb 22 '18 10:02 cdietrich

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.

spoenemann avatar Feb 22 '18 10:02 spoenemann

We could add a utility class that can be used by the LanguageServer implementations.

spoenemann avatar Feb 22 '18 10:02 spoenemann

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

gorkem avatar Feb 23 '18 21:02 gorkem

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.

spoenemann avatar Mar 01 '18 09:03 spoenemann

I have had success by simply exiting when System.in closes: https://github.com/georgewfraser/kotlin-language-server/commit/0c9e2d0b68892d3b62f5b1e9141c0e8f656e2262

georgewfraser avatar Apr 22 '18 06:04 georgewfraser

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

nixel2007 avatar Apr 04 '22 08:04 nixel2007

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 avatar Jul 29 '22 21:07 DavidGregory084

@DavidGregory084 cool and clean solution. I'll give it a try.

nixel2007 avatar Jul 31 '22 22:07 nixel2007

@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

nixel2007 avatar Sep 08 '22 19:09 nixel2007