From 9867d0c50daec84f20713ebe2f71d26d941afa3f Mon Sep 17 00:00:00 2001 From: "Tony Fischer (tku137)" Date: Sun, 26 Jan 2025 11:45:09 +0100 Subject: [PATCH] fix(copilot-chat): map naming discrepancies between modules This mainly fixes naming discrepancies between LazyVim picker names and CopilotChat integration names. It should also make this easily extendable in the future. Also, since it might be possible that the user completely disables fzf-lua and thus the default fzf picker is not available, we should capture that rare scenario, which also makes it future-proof. --- .../plugins/extras/ai/copilot-chat.lua | 38 ++++++++++++++----- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/lua/lazyvim/plugins/extras/ai/copilot-chat.lua b/lua/lazyvim/plugins/extras/ai/copilot-chat.lua index df3e4252..04d2a487 100644 --- a/lua/lazyvim/plugins/extras/ai/copilot-chat.lua +++ b/lua/lazyvim/plugins/extras/ai/copilot-chat.lua @@ -11,23 +11,41 @@ function M.pick(kind) end -- Get the picker wanted (configured) by the user - local configured_picker = LazyVim.pick.want() + local picker = LazyVim.pick.want() - -- Sanity check if a valid picker for CopilotChat is configured - local valid_pickers = { "telescope", "fzf", "snacks" } + -- Map LazyVim picker names to CopilotChat integration modules + local picker_map = { + telescope = "telescope", + fzf = "fzflua", -- Map "fzf" to "fzflua" + snacks = "snacks", + } - if not vim.tbl_contains(valid_pickers, configured_picker) then - LazyVim.error( - ("Invalid picker: '%s'. Ensure one of the following is installed and configured: %s"):format( - configured_picker, - table.concat(valid_pickers, ", ") + -- Get the corresponding CopilotChat integration module + local integration = picker_map[picker] + + if not integration then + LazyVim.warn( + ("No integration available for picker '%s'. Ensure a supported picker is installed and configured."):format( + picker ) ) return end - -- Use the valid picker - require("CopilotChat.integrations." .. configured_picker).pick(items) + -- Check if the integration module is available + local ok, picker_module = pcall(require, "CopilotChat.integrations." .. integration) + if not ok then + LazyVim.warn( + ("Integration module '%s' for picker '%s' is not available. Ensure it is installed and enabled."):format( + integration, + picker + ) + ) + return + end + + -- Use the selected picker module + picker_module.pick(items) end end