aboutsummaryrefslogtreecommitdiffstats
path: root/lua/lspconfig/configs.lua
diff options
context:
space:
mode:
authorRanjith Hegde <ranjithshegde@gmail.com>2022-08-23 16:03:20 +0200
committerGitHub <noreply@github.com>2022-08-23 07:03:20 -0700
commitfe7a6f41e59654db6bbc9eb2d084decc54b295e4 (patch)
treec7967bb5b649ad7f8f00c697bedc2f60db9e507a /lua/lspconfig/configs.lua
parentRevert "docs: vim.lsp.buf.formatting() is deprecated #2077 (diff)
downloadnvim-lspconfig-fe7a6f41e59654db6bbc9eb2d084decc54b295e4.tar
nvim-lspconfig-fe7a6f41e59654db6bbc9eb2d084decc54b295e4.tar.gz
nvim-lspconfig-fe7a6f41e59654db6bbc9eb2d084decc54b295e4.tar.bz2
nvim-lspconfig-fe7a6f41e59654db6bbc9eb2d084decc54b295e4.tar.lz
nvim-lspconfig-fe7a6f41e59654db6bbc9eb2d084decc54b295e4.tar.xz
nvim-lspconfig-fe7a6f41e59654db6bbc9eb2d084decc54b295e4.tar.zst
nvim-lspconfig-fe7a6f41e59654db6bbc9eb2d084decc54b295e4.zip
feat!: 0.7 API update (#1984)
* switch to lua api for autocommands * switch to nvim_create_user_command * move to lua plugin initialization NOTICE: Defining commands in server configurations will be deprecated in future releases. See `:help lspconfig.txt` to setup the same in an `on_attach` function. Co-authored-by: Michael Lingelbach <m.j.lbach@gmail.com>
Diffstat (limited to 'lua/lspconfig/configs.lua')
-rw-r--r--lua/lspconfig/configs.lua61
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