mirror of
https://github.com/neovim/neovim
synced 2025-07-16 01:01:49 +00:00
fix(lsp): check if client is stopping before reuse #33796
Problem: Stopping a language server and then calling vim.lsp.start() with the same name/root will return the old language server that's in the middle of shutting down. vim.lsp.start() won't return a new server until the old process has terminated. Solution: Introducing a client._is_stopping field that tracks the shutdown phase, preventing the client from being reused.
This commit is contained in:
@ -387,6 +387,7 @@ function Client.create(config)
|
||||
capabilities = config.capabilities,
|
||||
workspace_folders = lsp._get_workspace_folders(config.workspace_folders or config.root_dir),
|
||||
root_dir = config.root_dir,
|
||||
_is_stopping = false,
|
||||
_before_init_cb = config.before_init,
|
||||
_on_init_cbs = vim._ensure_list(config.on_init),
|
||||
_on_exit_cbs = vim._ensure_list(config.on_exit),
|
||||
@ -804,12 +805,13 @@ end
|
||||
---
|
||||
--- @param force? boolean
|
||||
function Client:stop(force)
|
||||
local rpc = self.rpc
|
||||
|
||||
if rpc.is_closing() then
|
||||
if self:is_stopped() then
|
||||
return
|
||||
end
|
||||
|
||||
self._is_stopping = true
|
||||
local rpc = self.rpc
|
||||
|
||||
vim.lsp._watchfiles.cancel(self.id)
|
||||
|
||||
if force or not self.initialized or self._graceful_shutdown_failed then
|
||||
@ -936,7 +938,7 @@ end
|
||||
--- @return boolean # true if client is stopped or in the process of being
|
||||
--- stopped; false otherwise
|
||||
function Client:is_stopped()
|
||||
return self.rpc.is_closing()
|
||||
return self.rpc.is_closing() or self._is_stopping
|
||||
end
|
||||
|
||||
--- Execute a lsp command, either via client command function (if available)
|
||||
|
Reference in New Issue
Block a user