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 configured_picker = LazyVim.pick.want() -- Sanity check if a valid picker for CopilotChat is configured local valid_pickers = { "telescope", "fzf", "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, ", ") ) ) return end -- Use the valid picker require("CopilotChat.integrations." .. configured_picker).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 = { { "", "", ft = "copilot-chat", desc = "Submit Prompt", remap = true }, { "a", "", desc = "+ai", mode = { "n", "v" } }, { "aa", function() return require("CopilotChat").toggle() end, desc = "Toggle (CopilotChat)", mode = { "n", "v" }, }, { "ax", function() return require("CopilotChat").reset() end, desc = "Clear (CopilotChat)", mode = { "n", "v" }, }, { "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 { "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, }, }