From b1de227da4ca6baf6ba865bec75917e4b4053844 Mon Sep 17 00:00:00 2001 From: glepnir Date: Mon, 14 Oct 2024 15:17:15 +0800 Subject: fix: command LspStop can receive server name (#3367) --- plugin/lspconfig.lua | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'plugin/lspconfig.lua') diff --git a/plugin/lspconfig.lua b/plugin/lspconfig.lua index fd4631d1..e687e330 100644 --- a/plugin/lspconfig.lua +++ b/plugin/lspconfig.lua @@ -110,23 +110,31 @@ end, { api.nvim_create_user_command('LspStop', function(info) local current_buf = vim.api.nvim_get_current_buf() - local server_id, force + local server_id, force, server_name local arguments = vim.split(info.args, '%s') for _, v in pairs(arguments) do if v == '++force' then force = true elseif v:find '^[0-9]+$' then server_id = v + else + 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] then + if client.attached_buffers[current_buf] and (server_name and (server_name == client.config.name) or true) then client.stop(force) + found = true 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 client.stop(force) -- cgit v1.2.3-70-g09d2