mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-09-01 07:30:03 +02:00
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.
130 lines
3.3 KiB
Lua
130 lines
3.3 KiB
Lua
local M = {}
|
|
|
|
---@param kind string
|
|
function M.pick(kind)
|
|
return function()
|
|
local actions = require("CopilotChat.actions")
|
|
local items = actions[kind .. "_actions"]()
|
|
if not items then
|
|
LazyVim.warn("No " .. kind .. " found on the current line")
|
|
return
|
|
end
|
|
|
|
-- Get the picker wanted (configured) by the user
|
|
local picker = LazyVim.pick.want()
|
|
|
|
-- Map LazyVim picker names to CopilotChat integration modules
|
|
local picker_map = {
|
|
telescope = "telescope",
|
|
fzf = "fzflua", -- Map "fzf" to "fzflua"
|
|
snacks = "snacks",
|
|
}
|
|
|
|
-- 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
|
|
|
|
-- 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
|
|
|
|
return {
|
|
{
|
|
"CopilotC-Nvim/CopilotChat.nvim",
|
|
branch = "main",
|
|
cmd = "CopilotChat",
|
|
opts = function()
|
|
local user = vim.env.USER or "User"
|
|
user = user:sub(1, 1):upper() .. user:sub(2)
|
|
return {
|
|
auto_insert_mode = true,
|
|
question_header = " " .. user .. " ",
|
|
answer_header = " Copilot ",
|
|
window = {
|
|
width = 0.4,
|
|
},
|
|
}
|
|
end,
|
|
keys = {
|
|
{ "<c-s>", "<CR>", ft = "copilot-chat", desc = "Submit Prompt", remap = true },
|
|
{ "<leader>a", "", desc = "+ai", mode = { "n", "v" } },
|
|
{
|
|
"<leader>aa",
|
|
function()
|
|
return require("CopilotChat").toggle()
|
|
end,
|
|
desc = "Toggle (CopilotChat)",
|
|
mode = { "n", "v" },
|
|
},
|
|
{
|
|
"<leader>ax",
|
|
function()
|
|
return require("CopilotChat").reset()
|
|
end,
|
|
desc = "Clear (CopilotChat)",
|
|
mode = { "n", "v" },
|
|
},
|
|
{
|
|
"<leader>aq",
|
|
function()
|
|
local input = vim.fn.input("Quick Chat: ")
|
|
if input ~= "" then
|
|
require("CopilotChat").ask(input)
|
|
end
|
|
end,
|
|
desc = "Quick Chat (CopilotChat)",
|
|
mode = { "n", "v" },
|
|
},
|
|
-- Show prompts actions with telescope
|
|
{ "<leader>ap", M.pick("prompt"), desc = "Prompt Actions (CopilotChat)", mode = { "n", "v" } },
|
|
},
|
|
config = function(_, opts)
|
|
local chat = require("CopilotChat")
|
|
|
|
vim.api.nvim_create_autocmd("BufEnter", {
|
|
pattern = "copilot-chat",
|
|
callback = function()
|
|
vim.opt_local.relativenumber = false
|
|
vim.opt_local.number = false
|
|
end,
|
|
})
|
|
|
|
chat.setup(opts)
|
|
end,
|
|
},
|
|
|
|
-- Edgy integration
|
|
{
|
|
"folke/edgy.nvim",
|
|
optional = true,
|
|
opts = function(_, opts)
|
|
opts.right = opts.right or {}
|
|
table.insert(opts.right, {
|
|
ft = "copilot-chat",
|
|
title = "Copilot Chat",
|
|
size = { width = 50 },
|
|
})
|
|
end,
|
|
},
|
|
}
|