diff options
| author | Elvis Claros Castro <elvis@claros.ar> | 2025-01-09 10:33:28 -0300 |
|---|---|---|
| committer | Elvis Claros Castro <elvis@claros.ar> | 2025-01-09 10:33:28 -0300 |
| commit | f27115f7c053d1d8e4b2af4b7506210fffc51c95 (patch) | |
| tree | 7eb8b43a6b4f9bb5555eeec9073cf339ccb580b6 /lua/plugins/copilot-chat.lua | |
| parent | 4439edc5a91582f570551e5e849347a80bde40ee (diff) | |
| download | nvim-conf-f27115f7c053d1d8e4b2af4b7506210fffc51c95.tar.gz nvim-conf-f27115f7c053d1d8e4b2af4b7506210fffc51c95.zip | |
Feat: agrego más plugins
Diffstat (limited to 'lua/plugins/copilot-chat.lua')
| -rw-r--r-- | lua/plugins/copilot-chat.lua | 95 |
1 files changed, 92 insertions, 3 deletions
diff --git a/lua/plugins/copilot-chat.lua b/lua/plugins/copilot-chat.lua index dc31b32..d389d2f 100644 --- a/lua/plugins/copilot-chat.lua +++ b/lua/plugins/copilot-chat.lua @@ -1,8 +1,35 @@ +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 { { + "nvim-treesitter/nvim-treesitter", + opts = { ensure_installed = { "diff", "markdown" } }, + }, + { + dir = IS_DEV and "~/research/CopilotChat.nvim" or nil, "CopilotC-Nvim/CopilotChat.nvim", + -- version = "v3.3.0", dependencies = { - { "nvim-lua/plenary.nvim", branch = "master" }, -- for curl, log and async functions + { "nvim-lua/plenary.nvim" }, { "ibhagwan/fzf-lua", config = function() @@ -11,8 +38,70 @@ return { }, }, opts = { - -- See Configuration section for options + model = 'claude-3.5-sonnet', + -- question_header = "## User ", + -- answer_header = "## Copilot ", + -- error_header = "## Error ", + prompts = prompts, + -- Turn off Claude model as it's not working well + -- model = "claude-3.5-sonnet", + auto_follow_cursor = false, -- Don't follow the cursor after getting response + }, - -- See Commands section for default commands if you want to lazy load on them + config = function(_, opts) + local chat = require("CopilotChat") + local select = require("CopilotChat.select") + -- Use unnamed register for the selection + opts.selection = select.unnamed + + -- local hostname = io.popen("hostname"):read("*a"):gsub("%s+", "") + -- local user = hostname or vim.env.USER or "User" + -- opts.question_header = " " .. user .. " " + -- opts.answer_header = " Copilot " + -- Override the git prompts message + opts.prompts.Commit = { + prompt = '> #git:staged\n\nWrite commit message with commitizen convention. Write clear, informative commit messages that explain the "what" and "why" behind changes, not just the "how".', + } + + 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, }, } |