diff options
Diffstat (limited to 'plugin/lspconfig.lua')
| -rw-r--r-- | plugin/lspconfig.lua | 47 |
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 = '?', |
