aboutsummaryrefslogtreecommitdiffstats
path: root/plugin
diff options
context:
space:
mode:
authorGuilherme Soares <48023091+guilhas07@users.noreply.github.com>2024-10-18 10:46:51 +0100
committerGitHub <noreply@github.com>2024-10-18 02:46:51 -0700
commitdda84e6dd99c7d67fd3f9b68ea2162521a2312a7 (patch)
treea5e16f8b40b11fd0dbe3c3c9a1b107fc882e0ea4 /plugin
parentdocs(lsp_ai): description string instead of table (#3374) (diff)
downloadnvim-lspconfig-dda84e6dd99c7d67fd3f9b68ea2162521a2312a7.tar
nvim-lspconfig-dda84e6dd99c7d67fd3f9b68ea2162521a2312a7.tar.gz
nvim-lspconfig-dda84e6dd99c7d67fd3f9b68ea2162521a2312a7.tar.bz2
nvim-lspconfig-dda84e6dd99c7d67fd3f9b68ea2162521a2312a7.tar.lz
nvim-lspconfig-dda84e6dd99c7d67fd3f9b68ea2162521a2312a7.tar.xz
nvim-lspconfig-dda84e6dd99c7d67fd3f9b68ea2162521a2312a7.tar.zst
nvim-lspconfig-dda84e6dd99c7d67fd3f9b68ea2162521a2312a7.zip
fix(LspStop): correctly stop servers and notify user #3378
## Problem The current `LspStop` behavior is confusing and wrong: **Server name:** - If the server with the given `server_name` is **not attached**: - No notification is shown, and **all** LSP servers are stopped. - If the server with the given `server_name` is **attached**: - **Incorrectly** closes all LSP servers. - If no servers are attached: - `server_name` is notified as missing. **Server ID:** - If the server with the given `server_id` is **not attached**: - Uses `get_managed_clients()` function https://github.com/neovim/nvim-lspconfig/blob/541f3a2781de481bb84883889e4d9f0904250a56/plugin/lspconfig.lua#L45-L47 Which doesn't return all servers (e.g., `null-ls`), so it doesn't close all LSP clients. - If the server with the given `server_id` is **attached**: - The correct LSP server is stopped (including `null-ls`). **No arguments:** - If servers are **attached**: - Stops all servers. - If no servers are attached: - **Incorrectly** notifies the user with: `config "" not found`. ## Solution **Server name:** - If the server with the given `server_name` is **not attached**: - Notify the user, but **do not close** any servers. - If the server with the given `server_name` is **attached**: - Close the specified server. **Server ID:** - If the server with the given `server_id` is **not attached**: - Notify the user, but **do not close** any servers. - If the server with the given `server_id` is **attached**: - Close the specified server. **No arguments:** - If servers are **attached**: - Stops all servers. - If no servers are attached: - No-op.
Diffstat (limited to 'plugin')
-rw-r--r--plugin/lspconfig.lua47
1 files changed, 29 insertions, 18 deletions
diff --git a/plugin/lspconfig.lua b/plugin/lspconfig.lua
index e687e330..f9f22e5f 100644
--- a/plugin/lspconfig.lua
+++ b/plugin/lspconfig.lua
@@ -110,36 +110,47 @@ end, {
api.nvim_create_user_command('LspStop', function(info)
local current_buf = vim.api.nvim_get_current_buf()
- local server_id, force, server_name
+ local server_id, force, server_name, err_msg
local arguments = vim.split(info.args, '%s')
+
+ local filter = function()
+ return true
+ end
+ local found = true
+
for _, v in pairs(arguments) do
if v == '++force' then
force = true
elseif v:find '^[0-9]+$' then
- server_id = v
- else
+ server_id = tonumber(v)
+ ---@param client vim.lsp.Client
+ filter = function(client)
+ return server_id == client.id
+ end
+ found = false
+ err_msg = ('nvim-lspconfig: client id "%s" not found'):format(server_id)
+ elseif v ~= '' then
server_name = v
- end
- end
-
- if not server_id then
- local servers_on_buffer = require('lspconfig.util').get_lsp_clients { bufnr = current_buf }
- local found = false
- for _, client in ipairs(servers_on_buffer) do
- if client.attached_buffers[current_buf] and (server_name and (server_name == client.config.name) or true) then
- client.stop(force)
- found = true
+ ---@param client vim.lsp.Client
+ filter = function(client)
+ return server_name == client.config.name
end
+ err_msg = ('nvim-lspconfig: config "%s" not found'):format(server_name)
+ found = false
end
+ end
- if server_name and not found then
- vim.notify(('nvim-lspconfig: config "%s" not found'):format(server_name), vim.log.levels.WARN)
- end
- else
- for _, client in ipairs(get_clients_from_cmd_args(server_id)) do
+ local servers_on_buffer = require('lspconfig.util').get_lsp_clients { bufnr = current_buf }
+ for _, client in ipairs(servers_on_buffer) do
+ if client.attached_buffers[current_buf] and filter(client) then
client.stop(force)
+ found = true
end
end
+
+ if not found then
+ vim.notify(err_msg, vim.log.levels.WARN)
+ end
end, {
desc = 'Manually stops the given language client(s)',
nargs = '?',