local IS_DEV = false local prompts = { -- Code related prompts Explain = "Please explain how the following code works.", Review = "Please review the following code and provide suggestions for improvement.", Tests = "Please explain how the selected code works, then generate unit tests for it.", Refactor = "Please refactor the following code to improve its clarity and readability.", FixCode = "Please fix the following code to make it work as intended.", FixError = "Please explain the error in the following text and provide a solution.", BetterNamings = "Please provide better names for the following variables and functions.", Documentation = "Please provide documentation for the following code.", SwaggerApiDocs = "Please provide documentation for the following API using Swagger.", SwaggerJsDocs = "Please write JSDoc for the following API using Swagger.", -- Text related prompts Summarize = "Please summarize the following text.", Spelling = "Please correct any grammar and spelling errors in the following text.", Wording = "Please improve the grammar and wording of the following text.", Concise = "Please rewrite the following text to make it more concise.", } return { -- { import = "plugins.extras.copilot-vim" }, -- Or use { import = "lazyvim.plugins.extras.coding.copilot" }, { "folke/which-key.nvim", optional = true, opts = { spec = { { "a", group = "ai" }, { "gm", group = "+Copilot chat" }, { "gmh", desc = "Show help" }, { "gmd", desc = "Show diff" }, { "gmp", desc = "Show system prompt" }, { "gms", desc = "Show selection" }, { "gmy", desc = "Yank diff" }, }, }, }, { dir = IS_DEV and "~/Projects/research/CopilotChat.nvim" or nil, "CopilotC-Nvim/CopilotChat.nvim", -- version = "v3.3.0", -- Use a specific version to prevent breaking changes dependencies = { { "nvim-telescope/telescope.nvim" }, -- Use telescope for help actions { "nvim-lua/plenary.nvim" }, { "zbirenbaum/copilot.lua" }, -- or github/copilot.vim }, opts = { question_header = "## User ", answer_header = "## Copilot ", error_header = "## Error ", prompts = prompts, auto_follow_cursor = false, -- Don't follow the cursor after getting response mappings = { -- Use tab for completion complete = { detail = "Use @ or / for options.", insert = "", }, -- Close the chat close = { normal = "q", insert = "", }, -- Reset the chat buffer reset = { normal = "", insert = "", }, -- Submit the prompt to Copilot submit_prompt = { normal = "", insert = "", }, -- Accept the diff accept_diff = { normal = "", insert = "", }, -- Yank the diff in the response to register yank_diff = { normal = "gmy", }, -- Show the diff show_diff = { normal = "gmd", }, -- Show the info show_info = { normal = "gmi", }, -- Show the context show_context = { normal = "gmc", }, -- Show help show_help = { normal = "gmh", }, }, }, config = function(_, opts) local chat = require("CopilotChat") local select = require("CopilotChat.select") -- Use unnamed register for the selection opts.selection = select.unnamed chat.setup(opts) vim.api.nvim_create_user_command("CopilotChatVisual", function(args) chat.ask(args.args, { selection = select.visual }) end, { nargs = "*", range = true }) -- Inline chat with Copilot vim.api.nvim_create_user_command("CopilotChatInline", function(args) chat.ask(args.args, { selection = select.visual, window = { layout = "float", relative = "cursor", width = 1, height = 0.4, row = 1, }, }) end, { nargs = "*", range = true }) -- Restore CopilotChatBuffer vim.api.nvim_create_user_command("CopilotChatBuffer", function(args) chat.ask(args.args, { selection = select.buffer }) end, { nargs = "*", range = true }) -- Custom buffer for CopilotChat vim.api.nvim_create_autocmd("BufEnter", { pattern = "copilot-*", callback = function() vim.opt_local.relativenumber = true vim.opt_local.number = true -- Get current filetype and set it to markdown if the current filetype is copilot-chat local ft = vim.bo.filetype if ft == "copilot-chat" then vim.bo.filetype = "markdown" end end, }) end, event = "VeryLazy", keys = { -- Show prompts actions with telescope { "ap", function() local actions = require("CopilotChat.actions") require("CopilotChat.integrations.telescope").pick(actions.prompt_actions()) end, desc = "CopilotChat - Prompt actions", }, { "ap", ":lua require('CopilotChat.integrations.telescope').pick(require('CopilotChat.actions').prompt_actions({selection = require('CopilotChat.select').visual}))", mode = "x", desc = "CopilotChat - Prompt actions", }, -- Code related commands { "ae", "CopilotChatExplain", desc = "CopilotChat - Explain code" }, { "at", "CopilotChatTests", desc = "CopilotChat - Generate tests" }, { "ar", "CopilotChatReview", desc = "CopilotChat - Review code" }, { "aR", "CopilotChatRefactor", desc = "CopilotChat - Refactor code" }, { "an", "CopilotChatBetterNamings", desc = "CopilotChat - Better Naming" }, -- Chat with Copilot in visual mode { "av", ":CopilotChatVisual", mode = "x", desc = "CopilotChat - Open in vertical split", }, { "ax", ":CopilotChatInline", mode = "x", desc = "CopilotChat - Inline chat", }, -- Custom input for CopilotChat { "ai", function() local input = vim.fn.input("Ask Copilot: ") if input ~= "" then vim.cmd("CopilotChat " .. input) end end, desc = "CopilotChat - Ask input", }, -- Generate commit message based on the git diff { "am", "CopilotChatCommit", desc = "CopilotChat - Generate commit message for all changes", }, -- Quick chat with Copilot { "aq", function() local input = vim.fn.input("Quick Chat: ") if input ~= "" then vim.cmd("CopilotChatBuffer " .. input) end end, desc = "CopilotChat - Quick chat", }, -- Debug { "ad", "CopilotChatDebugInfo", desc = "CopilotChat - Debug Info" }, -- Fix the issue with diagnostic { "af", "CopilotChatFixDiagnostic", desc = "CopilotChat - Fix Diagnostic" }, -- Clear buffer and chat history { "al", "CopilotChatReset", desc = "CopilotChat - Clear buffer and chat history" }, -- Toggle Copilot Chat Vsplit { "av", "CopilotChatToggle", desc = "CopilotChat - Toggle" }, -- Copilot Chat Models { "a?", "CopilotChatModels", desc = "CopilotChat - Select Models" }, }, }, }