LSP: Forcefully shutdown uninitialized servers #7449
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The LSP spec has this to say about initialize:
(https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#initialize)
The spec is not really explicit about how to handle this scenario. Before a client sends the 'initialize' request we are allowed to send an 'exit' notification, but after 'initialize' we can't send any requests (like shutdown) or notifications (like exit). So my intepretation is that we should forcefully close the server in this state.
This matches the behavior of Neovim's built-in LSP client:
https://github.com/neovim/neovim/blob/5ceb2238d3685255cd517ca87fd7edae9ed88811/runtime/lua/vim/lsp.lua#L1610-L1628
This is a rough edge for ltex-ls which has a long start-up time. Some configure ltex-ls for git-commits for spell-checking and it's possible to finish writing your commit message,
:wq
and have the shutdown request time out before the server is initialized.Closes #7446
Closes #7211
Also see #5732. I think it would be fine in practice to also send an exit notification here but the spec is explicit that other requests/notifications are not allowed after 'initialize'.