nvim: lsp: Use buffer local variant for user command

This commit is contained in:
Sanchayan Maity 2024-07-09 22:25:57 +05:30
parent 1546d48cde
commit 92797dffb1
Signed by: sanchayanmaity
GPG key ID: 6F6A0609C12038F3

View file

@ -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,
})