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.", Docstring = "Please use a Sphinx format to write a docstring for this object. Is very important that you respect the Sphinx format.", -- 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 { { "CopilotC-Nvim/CopilotChat.nvim", branch = "canary", -- Use the canary branch if you want to test the latest features but it might be unstable -- version = "v2.10.0", -- Do not use branch and version together, either use branch or version dependencies = { { "zbirenbaum/copilot.lua" }, { "nvim-lua/plenary.nvim" }, }, opts = { model = 'gpt-4o-2024-05-13', highlight_selection = true, question_header = "## User ", answer_header = "## Copilot ", error_header = "## Error ", prompts = prompts, auto_follow_cursor = false, -- Don't follow the cursor after getting response show_help = false, -- Show help in virtual text, set to true if that's 1st time using Copilot Chat 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", register = '"', }, -- Show the diff show_diff = { normal = "gmd", }, -- Show the prompt show_system_prompt = { normal = "gmp", }, -- Show the user selection show_user_selection = { normal = "gms", }, -- 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 local user = vim.env.USER or "User" user = user:sub(1, 1):upper() .. user:sub(2) opts.question_header = " " .. user .. " " opts.answer_header = " Copilot " -- Override the git prompts message opts.prompts.Commit = { prompt = 'Write commit message with commitizen convention. Write clear, informative commit messages that explain the "what" and "why" behind changes, not just the "how". Returning the answer in portuguese.', selection = select.gitdiff, } opts.prompts.CommitStaged = { prompt = 'Write commit message with commitizen convention. Write clear, informative commit messages that explain the "what" and "why" behind changes, not just the "how". Returning the answer in portuguese.', selection = function(source) return select.gitdiff(source, true) end, } chat.setup(opts) -- Setup CMP integration -- require("CopilotChat.integrations.cmp").setup() -- -- 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 help actions { "ah", function() local actions = require("CopilotChat.actions") require("CopilotChat.integrations.telescope").pick(actions.help_actions()) end, desc = "CopilotChat - Help actions", }, -- Show prompts actions { "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", }, { "aM", "CopilotChatCommitStaged", desc = "CopilotChat - Generate commit message for staged 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" }, }, }, { "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, }, }