change ai plugin to CopilotChat.nvim

This commit is contained in:
Alexander Navarro 2024-11-25 10:46:43 -03:00
parent 1366b1d7b0
commit ec750a0e89
3 changed files with 73 additions and 50 deletions

View file

@ -6,7 +6,7 @@ return {
-- dependencies = { 'nvim-treesitter/nvim-treesitter', 'echasnovski/mini.icons' }, -- if you use standalone mini plugins
dependencies = { "nvim-treesitter/nvim-treesitter", "nvim-tree/nvim-web-devicons" }, -- if you prefer nvim-web-devicons
opts = {
file_types = { 'markdown', 'codecompanion' },
file_types = { 'markdown', 'copilot-chat' },
sign = {
enabled = false,
},

View file

@ -1,8 +1,10 @@
return {
"olimorris/codecompanion.nvim",
"CopilotC-Nvim/CopilotChat.nvim",
branch = "canary",
build = "make tiktoken",
cmd = "CopilotChat",
dependencies = {
"nvim-lua/plenary.nvim",
"nvim-treesitter/nvim-treesitter",
{
"zbirenbaum/copilot.lua",
cmd = "Copilot",
@ -14,71 +16,93 @@ return {
})
end,
},
"hrsh7th/nvim-cmp", -- Optional: For using slash commands and variables in the chat buffer
"nvim-telescope/telescope.nvim", -- Optional: For using slash commands
{ "stevearc/dressing.nvim", opts = {} }, -- Optional: Improves `vim.ui.select`
},
opts = {
strategies = {
chat = {
adapter = "copilot",
},
inline = {
adapter = "copilot",
},
agent = { adapter = "copilot" },
},
display = {
action_palette = {
prompt = ""
},
chat = {
window = {
layout = "float",
height = 0.8,
width = 0.8,
opts = function()
local user = vim.env.USER or "User"
user = user:sub(1, 1):upper() .. user:sub(2)
return {
prompts = {
Explain = {
prompt = '> /COPILOT_EXPLAIN\n\nWrite an explanation for the selected code as paragraphs of text.',
},
}
Review = {
prompt = '> /COPILOT_REVIEW\n\nReview the selected code.',
-- see config.lua for implementation
},
Fix = {
prompt =
'> /COPILOT_GENERATE\n\nThere is a problem in this code. Rewrite the code to show it with the bug fixed.',
},
Optimize = {
prompt = '> /COPILOT_GENERATE\n\nOptimize the selected code to improve performance and readability.',
},
Docs = {
prompt = '> /COPILOT_GENERATE\n\nPlease add documentation comments to the selected code.',
},
Tests = {
prompt = '> /COPILOT_GENERATE\n\nPlease generate tests for my code.',
},
Commit = {
prompt =
'> #git:staged\n\nWrite commit message for the change with commitizen convention. Make sure the title has maximum 50 characters and message is wrapped at 72 characters. Wrap the whole message in code block with language gitcommit.',
},
},
question_header = "" .. user .. " ",
answer_header = " Copilot ",
window = {
layout = 'float', -- 'vertical', 'horizontal', 'float', 'replace'
width = 0.8, -- fractional width of parent, or absolute width in columns when > 1
height = 0.8, -- fractional height of parent, or absolute height in rows when > 1
-- Options below only apply to floating windows
relative = 'editor', -- 'editor', 'win', 'cursor', 'mouse'
border = 'rounded', -- 'none', single', 'double', 'rounded', 'solid', 'shadow'
title = '', -- title of chat window
zindex = 1, -- determines if window is on top or below other floating windows
},
}
},
end,
keys = {
{
"<leader>at",
function()
require("codecompanion").toggle()
require("CopilotChat").toggle()
end,
desc = "Toggle AI chat",
mode = { "n", "v" }
desc = "Toggle window",
mode = { "n", "v" },
},
{
"<leader>aa",
"<CMD>CodeCompanion<CR>",
desc = "Run an inline prompt",
mode = { "n", "v" }
function()
local input = vim.fn.input("Quick Chat: ")
if input ~= "" then
require("CopilotChat").ask(input)
end
end,
desc = "Quick chat",
mode = { "n", "v" },
},
{
"<leader>aA",
function()
require("codecompanion").actions()
-- Pick a prompt using vim.ui.select
local actions = require("CopilotChat.actions")
-- Pick prompt actions
actions.pick(actions.prompt_actions({
selection = require("CopilotChat.select").visual,
}))
end,
desc = "Open AI actions",
mode = { "n", "v" }
desc = "Select action",
mode = { "n", "v" },
},
{
"<leader>av",
"<leader>ax",
function()
require("codecompanion").add()
return require("CopilotChat").reset()
end,
desc = "Add visual selection to chat",
mode = "v"
},
{
"<leader>ae",
function()
require("codecompanion").prompt("explain")
end,
desc = "Explain code",
mode = "v"
desc = "Clear chat",
mode = { "n", "v" },
},
}
}