diff options
Diffstat (limited to 'lua/lspconfig/configs.lua')
| -rw-r--r-- | lua/lspconfig/configs.lua | 61 |
1 files changed, 33 insertions, 28 deletions
diff --git a/lua/lspconfig/configs.lua b/lua/lspconfig/configs.lua index 07672a33..a0129776 100644 --- a/lua/lspconfig/configs.lua +++ b/lua/lspconfig/configs.lua @@ -31,6 +31,8 @@ function configs.__newindex(t, config_name, config_def) default_config.name = config_name function M.setup(config) + local lsp_group = vim.api.nvim_create_augroup('lspconfig', { clear = false }) + validate { cmd = { config.cmd, 't', true }, root_dir = { config.root_dir, 'f', true }, @@ -64,14 +66,17 @@ function configs.__newindex(t, config_name, config_def) event = 'BufReadPost' pattern = '*' end - api.nvim_command( - string.format( - "autocmd %s %s unsilent lua require'lspconfig'[%q].manager.try_add()", - event, - pattern, + vim.api.nvim_create_autocmd(event, { + pattern = pattern, + callback = function() + M.manager.try_add() + end, + group = lsp_group, + desc = string.format( + 'Checks whether server %s should start a new instance or attach to an existing one.', config.name - ) - ) + ), + }) end local get_root_dir = config.root_dir @@ -88,15 +93,18 @@ function configs.__newindex(t, config_name, config_def) end if root_dir then - -- Lazy-launching: attach when a buffer in this directory is opened. - api.nvim_command( - string.format( - "autocmd BufReadPost %s/* unsilent lua require'lspconfig'[%q].manager.try_add_wrapper()", - vim.fn.fnameescape(root_dir), - config.name - ) - ) - -- Attach for all existing buffers in this directory. + vim.api.nvim_create_autocmd('BufReadPost', { + pattern = vim.fn.fnameescape(root_dir) .. '/*', + callback = function() + M.manager.try_add_wrapper() + end, + group = lsp_group, + desc = string.format( + 'Checks whether server %s should attach to a newly opened buffer inside workspace %q.', + config.name, + root_dir + ), + }) for _, bufnr in ipairs(vim.api.nvim_list_bufs()) do local bufname = api.nvim_buf_get_name(bufnr) if util.bufname_valid(bufname) then @@ -183,15 +191,15 @@ function configs.__newindex(t, config_name, config_def) M._setup_buffer(client.id, bufnr) else if vim.api.nvim_buf_is_valid(bufnr) then - api.nvim_command( - string.format( - "autocmd BufEnter <buffer=%d> ++once lua require'lspconfig'[%q]._setup_buffer(%d,%d)", - bufnr, - config_name, - client.id, - bufnr - ) - ) + vim.api.nvim_create_autocmd('BufEnter', { + callback = function() + M._setup_buffer(client.id, bufnr) + end, + group = lsp_group, + buffer = bufnr, + once = true, + desc = 'Reattaches the server with the updated configurations if changed.', + }) end end end) @@ -283,13 +291,10 @@ function configs.__newindex(t, config_name, config_def) M.commands = vim.tbl_deep_extend('force', M.commands, client.config.commands) end if not M.commands_created and not vim.tbl_isempty(M.commands) then - -- Create the module commands util.create_module_commands(config_name, M.commands) - M.commands_created = true end end - M.commands_created = false M.commands = config_def.commands M.name = config_name M.document_config = config_def |
