From 92797dffb1dcde6893f9cd32d7a8be8d4814cc98 Mon Sep 17 00:00:00 2001 From: Sanchayan Maity Date: Tue, 9 Jul 2024 22:25:57 +0530 Subject: [PATCH] nvim: lsp: Use buffer local variant for user command --- nvim/.config/nvim/lua/lsp.lua | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/nvim/.config/nvim/lua/lsp.lua b/nvim/.config/nvim/lua/lsp.lua index a4dff01..d9a07fe 100644 --- a/nvim/.config/nvim/lua/lsp.lua +++ b/nvim/.config/nvim/lua/lsp.lua @@ -157,13 +157,13 @@ local switch_source_header = function() end end -local client_custom_setup = function(client) +local client_custom_setup = function(client, bufnr) if client.name == 'clangd' then - vim.api.nvim_create_user_command("ClangdSwitchSourceHeader", switch_source_header, {desc = 'Switch between source/header'}) + vim.api.nvim_buf_create_user_command(bufnr, "ClangdSwitchSourceHeader", switch_source_header, {desc = 'Switch between source/header'}) end if client.name == 'rust-analyzer' then - vim.api.nvim_create_user_command("CargoReload", cargo_reload_workspace, {desc = 'Reload current cargo workspace'}) + vim.api.nvim_buf_create_user_command(bufnr, "CargoReload", cargo_reload_workspace, {desc = 'Reload current cargo workspace'}) end if client.name == 'tsserver' then @@ -173,13 +173,13 @@ local client_custom_setup = function(client) end end -local client_custom_cleanup = function(client) +local client_custom_cleanup = function(client, bufnr) if client.name == 'clangd' then - vim.api.nvim_del_user_command("ClangdSwitchSourceHeader") + vim.api.nvim_buf_del_user_command(bufnr, "ClangdSwitchSourceHeader") end if client.name == 'rust-analyzer' then - vim.api.nvim_del_user_command("CargoReload") + vim.api.nvim_buf_del_user_command(bufnr, "CargoReload") end end @@ -193,7 +193,7 @@ local on_attach = function(client, bufnr) local opts = { noremap=true, silent=true } - client_custom_setup(client) + client_custom_setup(client, bufnr) for _, mappings in pairs(lsp_key_mappings) do local capability, mode, lhs, rhs = unpack(mappings) @@ -280,7 +280,7 @@ vim.api.nvim_create_autocmd("LspDetach", { end end - client_custom_cleanup(client) + client_custom_cleanup(client, bufnr) end, })