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.
This commit is contained in:
Tony Fischer (tku137) 2025-01-26 11:45:09 +01:00
parent 3147a56b0f
commit 9867d0c50d

View file

@ -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