mirror of
https://github.com/neovim/nvim-lspconfig
synced 2025-03-11 04:27:36 +00:00
Add stop, start, and restart commands
This commit is contained in:
parent
97bdebef2c
commit
1dfab4f50f
@ -19,9 +19,46 @@ function M._root._setup()
|
||||
function()
|
||||
lspinfo()
|
||||
end;
|
||||
"-nargs=?";
|
||||
"-nargs=0";
|
||||
description = '`:LspInfo` Displays attached, active, and configured language servers';
|
||||
};
|
||||
LspStart = {
|
||||
function(server_name)
|
||||
require('lspconfig')[server_name].autostart()
|
||||
end;
|
||||
"-nargs=1 -complete=custom,v:lua.lsp_complete_configured_servers";
|
||||
description = '`:LspStart` Manually launches a language server.';
|
||||
};
|
||||
LspStop = {
|
||||
function(client_id)
|
||||
if not client_id then
|
||||
vim.lsp.stop_client(vim.lsp.get_active_clients())
|
||||
else
|
||||
local client = vim.lsp.get_client_by_id(tonumber(client_id))
|
||||
if client then
|
||||
client.stop()
|
||||
end
|
||||
end
|
||||
end;
|
||||
"-nargs=? -complete=customlist,v:lua.lsp_get_active_client_ids";
|
||||
description = '`:LspStop` Manually stops the given language client.';
|
||||
};
|
||||
LspRestart = {
|
||||
function(client_id)
|
||||
if client_id then
|
||||
local client = vim.lsp.get_client_by_id(tonumber(client_id))
|
||||
if client then
|
||||
local client_name = client.name
|
||||
client.stop()
|
||||
vim.defer_fn(function()
|
||||
require('lspconfig')[client_name].autostart()
|
||||
end, 500)
|
||||
end
|
||||
end
|
||||
end;
|
||||
"-nargs=? -complete=customlist,v:lua.lsp_get_active_client_ids";
|
||||
description = '`:LspRestart` Manually restart the given language client.';
|
||||
};
|
||||
};
|
||||
|
||||
M.util.create_module_commands("_root", M._root.commands)
|
||||
|
@ -4,8 +4,15 @@ endif
|
||||
let g:lspconfig = 1
|
||||
|
||||
lua << EOF
|
||||
lsp_complete_installable_servers = function()
|
||||
lsp_complete_configured_servers = function()
|
||||
return table.concat(require'lspconfig'.available_servers(), '\n')
|
||||
end
|
||||
lsp_get_active_client_ids = function()
|
||||
client_ids = {}
|
||||
for idx, client in ipairs(vim.lsp.get_active_clients()) do
|
||||
table.insert(client_ids, tostring(client.id))
|
||||
end
|
||||
return client_ids
|
||||
end
|
||||
require'lspconfig'._root._setup()
|
||||
EOF
|
||||
|
Loading…
Reference in New Issue
Block a user