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 end
-- Get the picker wanted (configured) by the user -- 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 -- Map LazyVim picker names to CopilotChat integration modules
local valid_pickers = { "telescope", "fzf", "snacks" } local picker_map = {
telescope = "telescope",
fzf = "fzflua", -- Map "fzf" to "fzflua"
snacks = "snacks",
}
if not vim.tbl_contains(valid_pickers, configured_picker) then -- Get the corresponding CopilotChat integration module
LazyVim.error( local integration = picker_map[picker]
("Invalid picker: '%s'. Ensure one of the following is installed and configured: %s"):format(
configured_picker, if not integration then
table.concat(valid_pickers, ", ") LazyVim.warn(
("No integration available for picker '%s'. Ensure a supported picker is installed and configured."):format(
picker
) )
) )
return return
end end
-- Use the valid picker -- Check if the integration module is available
require("CopilotChat.integrations." .. configured_picker).pick(items) 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
end end