send shutdown/exit to LSP server upon vim exit#783
Conversation
castedo
commented
Mar 16, 2026
- remove unnecessary wait loop after sending LSP exit
- remove old unused global variable LSPServers
* remove unnecessary wait loop after sending LSP exit * remove old unused global variable LSPServers
|
I'm not 100% sure, but I'm pretty sure that it is not needed and does nothing more than add a 2 seconds delay (which is why this wasn't called during vim exit). The LSP request of shutdown is already synchronous so I strongly suspect this provides all the delay that is needed (and I see pylsp respond VERY quickly). After that I don't think vim really needs to wait after the LSP exit getting sent. |
Sorry, that was ambiguous. By 'it' I mean the delay wait loop code that I remove in this PR (so that the function can be called upon vim exit without issue). |
This delay is needed when restarting a language server using the |
|
Oh my, I should address that. I am thinking I should fix this PR so there are two distinct kinds of shutdown/exit. A "fast" one that is only used for vim exit and the existing "slow" one that is used otherwise. @yegappan What do you think? |
Yes. Sounds good to me. |
* renamed from StopAllServers since previously unused * reverted autoload/lsp/lsp.vim to leave StopServer as is
|
OK, I've reverted StopServer with its wait/delay to be like main. This PR now has vim exit take a separate code path through a new "fast" function. |
|
@yegappan I don't see any issues with this PR now. Is there anything you see that should be updated? |
125ms timeout on synchronous 'shutdown' request for vim exit
|
@yegappan Here's a new proposal I've coded in the PR now: a sync call to shutdown with a 125ms timeout. Seems to me a good simple trade-off. Under normal circumstances servers will respond much faster than that and vim and server are doing a proper LSP protocol dance. Under unusual circumstances, a user won't even notice since it won't be more than an eighth of a second before the whole subprocess is terminated anyway. |
There was a problem hiding this comment.
Pull request overview
This PR updates the Vim LSP plugin to send a fast shutdown + exit sequence to all running LSP servers during VimLeavePre, and removes an unused global server list in favor of using the existing filetype→server map.
Changes:
- Add a
VimLeavePreautocmd to trigger a fast shutdown/exit of all LSP servers. - Implement
FastShutdownServer()/FastShutdownExitAllServers()using a short synchronous timeout forshutdown. - Remove the unused global
LSPServerslist.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| plugin/lsp.vim | Hooks Vim exit (VimLeavePre) to trigger the new fast shutdown routine. |
| autoload/lsp/lsp.vim | Implements fast shutdown/exit helpers and removes the unused LSPServers global. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Thanks for the patch. Can you address the comments from the copilot review? |
|
I will look into adding a timeout parameter to the lsp_server.rpc() call in a later PR, so that it can be used directly. |
Did you actually read the AI comments from the copilot review? |
Yes. I did go through the comments added by copilot. As some of the comments are valid, I requested you to address them. Thanks for addressing the comments. |