What’s a graceful way to restart a language server?


Some context: Our language server in theia connects to a remote server in our cluster to get symbol tables. We support the ability to switch to different versions of our runtime in vscode (eg to a local dev machine), and want to achieve the same in theia.

We are passing the remote connection info to the lsp via program args. I’d rather not implement special lsp commands to pass on new endpoint info if I can avoid it. What’s a graceful way of bouncing the LSP?

Can it be initiated from theia backend? Will the client cope? Will just killing the lsp process be enough to initiate a restart


[original thread by Max Hillaert]

You can restart it from frontend: https://github.com/theia-ide/theia/blob/441ce8edc865b9c148e730b36ff8e47259b5a7a0/packages/languages/src/browser/language-client-contribution.ts#L41

for exampl ts ls is restarted when a user select another version or change some preferences: https://github.com/theia-ide/theia/blob/441ce8edc865b9c148e730b36ff8e47259b5a7a0/packages/typescript/src/browser/typescript-client-contribution.ts#L66-L71

[Max Hillaert]


@max-hillaert your approach is fine for a theia extensions, but if you ever want to reuse the LS somewhere else, you’re probably better off with the custom commands (VS Code API has no provision to restart a LS)

@tsmaeder I think if vscode extension is using vscode-languageclieint then it can call start and stop on an instance of a language client.

True, but you can’t call that from a theia extension, for example, right?

i think you are right if you mean theia plugins. Right now theia plugin cannot use vscode namespace and cannot make use of vscode-languageclient directly.

[Max Hillaert]

Yeah. I think I’m going to introduce custom command to avoid the orchestration. The server info event comes from the backend from a server manager extension. Having to orchestrate the event to the language server and then to the front end of the language extension to deactivate the language client , seems more work and more error prone than just a custom lsp command that resets the remote connection and clear any caches in the lsp. Easier to write tests too.