From 636e7b7691db49f541585d429ee14f9ca68a845d Mon Sep 17 00:00:00 2001 From: Gary Murray Date: Wed, 1 Jan 2025 02:43:29 -0700 Subject: [PATCH 1/2] feat(lsp): add filetype-based LSP keymap ignore Add `vim.g.keymaps_lsp_ignore_ft` option to allow disabling LSP keymaps for specific filetypes --- lua/lazyvim/config/options.lua | 3 +++ lua/lazyvim/plugins/lsp/keymaps.lua | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lua/lazyvim/config/options.lua b/lua/lazyvim/config/options.lua index 0bbaacba..ea2fc180 100644 --- a/lua/lazyvim/config/options.lua +++ b/lua/lazyvim/config/options.lua @@ -42,6 +42,9 @@ vim.g.root_spec = { "lsp", { ".git", "lua" }, "cwd" } -- for detecting the LSP root vim.g.root_lsp_ignore = { "copilot" } +-- Filetypes to ignore LSP keymaps +vim.g.keymaps_lsp_ignore_ft = {} + -- Hide deprecation warnings vim.g.deprecation_warnings = false diff --git a/lua/lazyvim/plugins/lsp/keymaps.lua b/lua/lazyvim/plugins/lsp/keymaps.lua index 1b62a911..328e86da 100644 --- a/lua/lazyvim/plugins/lsp/keymaps.lua +++ b/lua/lazyvim/plugins/lsp/keymaps.lua @@ -6,6 +6,13 @@ M._keys = nil ---@alias LazyKeysLspSpec LazyKeysSpec|{has?:string|string[], cond?:fun():boolean} ---@alias LazyKeysLsp LazyKeys|{has?:string|string[], cond?:fun():boolean} +---@param buffer integer +---@return boolean +function M.is_ignored(buffer) + local ft = vim.bo[buffer].filetype + return vim.tbl_contains(vim.g.keymaps_lsp_ignore_ft or {}, ft) +end + ---@return LazyKeysLspSpec[] function M.get() if M._keys then @@ -64,7 +71,7 @@ end ---@return LazyKeysLsp[] function M.resolve(buffer) local Keys = require("lazy.core.handler.keys") - if not Keys.resolve then + if M.is_ignored(buffer) or not Keys.resolve then return {} end local spec = vim.tbl_extend("force", {}, M.get()) From 3c7f2798dc51bbc44eebcc8c3784f423d543838b Mon Sep 17 00:00:00 2001 From: Gary Murray Date: Wed, 1 Jan 2025 02:48:39 -0700 Subject: [PATCH 2/2] fix(copilot-chat): ignore LSP keymaps in chat window The copilot-chat filetype is added to the global list of filetypes that should ignore LSP keymaps, preventing keymap conflicts in the chat interface. --- lua/lazyvim/plugins/extras/ai/copilot-chat.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lua/lazyvim/plugins/extras/ai/copilot-chat.lua b/lua/lazyvim/plugins/extras/ai/copilot-chat.lua index e71f4db1..f1dcf0c3 100644 --- a/lua/lazyvim/plugins/extras/ai/copilot-chat.lua +++ b/lua/lazyvim/plugins/extras/ai/copilot-chat.lua @@ -75,6 +75,9 @@ return { end, }) + -- Add copilot-chat to the list of filetypes that should ignore LSP keymaps + vim.g.keymaps_lsp_ignore_ft = vim.list_extend(vim.g.keymaps_lsp_ignore_ft or {}, { "copilot-chat" }) + chat.setup(opts) end, },