mirror of
https://github.com/neovim/neovim.git
synced 2026-02-20 01:09:56 +10:00
fix(lsp): wait for exit_timeout on quit #37597
Problem:
When quitting Nvim, LSP servers will not be force-stopped, even if
ClientConfig.exit_timeout is set to an integer.
pkill emmylua_ls; VIMRUNTIME=runtime/ nvim --clean -u repro.lua repro.lua ; waitpid $(pgrep emmylua_ls)
vim.lsp.config('foo', { cmd = { 'emmylua_ls' }, exit_timeout = 1000 })
vim.lsp.enable('foo')
vim.defer_fn(vim.cmd.quit, 500)
Solution:
On VimExit, wait up to `exit_timeout:integer` milliseconds for servers
to exit. Do this with an explicit `vim.wait()`, because the actual
force-stop is deferred, and won't be attempted if Nvim exits before
then.
Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
This commit is contained in:
@@ -1132,9 +1132,25 @@ api.nvim_create_autocmd('VimLeavePre', {
|
||||
local active_clients = lsp.get_clients()
|
||||
log.info('exit_handler', active_clients)
|
||||
|
||||
local max_timeout = 0
|
||||
for _, client in pairs(active_clients) do
|
||||
max_timeout = math.max(max_timeout, tonumber(client.exit_timeout) or 0)
|
||||
client:stop(client.exit_timeout)
|
||||
end
|
||||
if max_timeout > 10 then
|
||||
api.nvim_echo({
|
||||
{
|
||||
string.format('Waiting %ss for lsp exit (Press Ctrl-C to force exit)', max_timeout / 1e3),
|
||||
'WarningMsg',
|
||||
},
|
||||
}, true, {})
|
||||
end
|
||||
|
||||
vim.wait(max_timeout, function()
|
||||
return vim.iter(active_clients):all(function(client)
|
||||
return client.rpc.is_closing()
|
||||
end)
|
||||
end)
|
||||
end,
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user