diff options
| author | Olivia Kinnear <account@superatomic.dev> | 2025-10-23 09:01:08 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-10-23 07:01:08 -0700 |
| commit | 0d90bb9bfb8e8b6b64f4a19b7dd3619f5d2788b5 (patch) | |
| tree | a3180c11afac302b475fd332a9ff2c850809390f /plugin | |
| parent | docs: update configs.md (diff) | |
| download | nvim-lspconfig-0d90bb9bfb8e8b6b64f4a19b7dd3619f5d2788b5.tar nvim-lspconfig-0d90bb9bfb8e8b6b64f4a19b7dd3619f5d2788b5.tar.gz nvim-lspconfig-0d90bb9bfb8e8b6b64f4a19b7dd3619f5d2788b5.tar.bz2 nvim-lspconfig-0d90bb9bfb8e8b6b64f4a19b7dd3619f5d2788b5.tar.lz nvim-lspconfig-0d90bb9bfb8e8b6b64f4a19b7dd3619f5d2788b5.tar.xz nvim-lspconfig-0d90bb9bfb8e8b6b64f4a19b7dd3619f5d2788b5.tar.zst nvim-lspconfig-0d90bb9bfb8e8b6b64f4a19b7dd3619f5d2788b5.zip | |
feat: force-stop server with :LspStop! (bang) #4140
Problem:
Some servers don't stop properly.
Calling `:LspStop` _twice_ will induce a force-stop, but that is not easy to
discover: https://github.com/neovim/neovim/blob/b67eff38fe19876ab228007897224ec04b58aa40/runtime/lua/vim/lsp/client.lua#L864-L866
> By default, it will just request the server to shutdown without force. If
> you request to stop a client which has previously been requested to
> shutdown, it will automatically escalate and force shutdown.
Solution:
Nvim should automatically force-stop after X seconds, but until that is
supported, adding a bang "!" variant is reasonable.
Diffstat (limited to 'plugin')
| -rw-r--r-- | plugin/lspconfig.lua | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/plugin/lspconfig.lua b/plugin/lspconfig.lua index 550f92e7..574945a3 100644 --- a/plugin/lspconfig.lua +++ b/plugin/lspconfig.lua @@ -128,33 +128,31 @@ if vim.fn.has('nvim-0.11.2') == 1 then -- Default to restarting all active servers if #clients == 0 then - clients = vim - .iter(vim.lsp.get_clients()) - :map(function(client) - return client.name - end) - :totable() + clients = vim.lsp.get_clients() end - for _, name in ipairs(clients) do + for client in vim.iter(clients) do + local name = client.name if vim.lsp.config[name] == nil then vim.notify(("Invalid server name '%s'"):format(name)) else vim.lsp.enable(name, false) + if info.bang then + client:stop(true) + end end end local timer = assert(vim.uv.new_timer()) timer:start(500, 0, function() - for _, name in ipairs(clients) do - vim.schedule_wrap(function(x) - vim.lsp.enable(x) - end)(name) + for client in vim.iter(clients) do + vim.schedule_wrap(vim.lsp.enable)(client.name) end end) end, { desc = 'Restart the given client', nargs = '?', + bang = true, complete = complete_client, }) @@ -163,24 +161,24 @@ if vim.fn.has('nvim-0.11.2') == 1 then -- Default to disabling all servers on current buffer if #clients == 0 then - clients = vim - .iter(vim.lsp.get_clients({ bufnr = vim.api.nvim_get_current_buf() })) - :map(function(client) - return client.name - end) - :totable() + clients = vim.lsp.get_clients({ bufnr = vim.api.nvim_get_current_buf() }) end - for _, name in ipairs(clients) do + for client in vim.iter(clients) do + local name = client.name if vim.lsp.config[name] == nil then vim.notify(("Invalid server name '%s'"):format(name)) else vim.lsp.enable(name, false) + if info.bang then + client:stop(true) + end end end end, { desc = 'Disable and stop the given client', nargs = '?', + bang = true, complete = complete_client, }) |
