♻️ New organization
refactor: modularização da configuração do Neovim- Removido o texto introdutório do Kickstart para simplificar o arquivo init.lua.- Separado as configurações de opções e keymaps em arquivos dedicados ( e ).- Adicionado o arquivo para gerenciar a instalação do plugin .- Movido a configuração de plugins para um arquivo separado ().- Atualizado o arquivo de configuração de lint para simplificar a definição de linters e adicionar um mapeamento de tecla para acionar a lintagem manualmente.- Adicionado um aviso no arquivo de configuração de debug indicando a necessidade de aprendizado prévio para uso do pacote.Essas mudanças visam modularizar a configuração do Neovim, tornando-a mais organizada e fácil de manter. A separação de responsabilidades em arquivos distintos facilita a leitura e a modificação das configurações, além de permitir uma melhor escalabilidade para futuras adições e ajustes.
This commit is contained in:
parent
9d8686a0aa
commit
ce804e1a1a
30 changed files with 1595 additions and 981 deletions
253
lua/kickstart/plugins/copilot-chat.lua
Normal file
253
lua/kickstart/plugins/copilot-chat.lua
Normal file
|
|
@ -0,0 +1,253 @@
|
|||
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 @<Tab> or /<Tab> for options.",
|
||||
insert = "<Tab>",
|
||||
},
|
||||
-- Close the chat
|
||||
close = {
|
||||
normal = "q",
|
||||
insert = "<C-c>",
|
||||
},
|
||||
-- Reset the chat buffer
|
||||
reset = {
|
||||
normal = "<C-x>",
|
||||
insert = "<C-x>",
|
||||
},
|
||||
-- Submit the prompt to Copilot
|
||||
submit_prompt = {
|
||||
normal = "<CR>",
|
||||
insert = "<C-CR>",
|
||||
},
|
||||
-- Accept the diff
|
||||
accept_diff = {
|
||||
normal = "<C-y>",
|
||||
insert = "<C-y>",
|
||||
},
|
||||
-- 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
|
||||
{
|
||||
"<leader>ah",
|
||||
function()
|
||||
local actions = require("CopilotChat.actions")
|
||||
require("CopilotChat.integrations.telescope").pick(actions.help_actions())
|
||||
end,
|
||||
desc = "CopilotChat - Help actions",
|
||||
},
|
||||
-- Show prompts actions
|
||||
{
|
||||
"<leader>ap",
|
||||
function()
|
||||
local actions = require("CopilotChat.actions")
|
||||
require("CopilotChat.integrations.telescope").pick(actions.prompt_actions())
|
||||
end,
|
||||
desc = "CopilotChat - Prompt actions",
|
||||
},
|
||||
{
|
||||
"<leader>ap",
|
||||
":lua require('CopilotChat.integrations.telescope').pick(require('CopilotChat.actions').prompt_actions({selection = require('CopilotChat.select').visual}))<CR>",
|
||||
mode = "x",
|
||||
desc = "CopilotChat - Prompt actions",
|
||||
},
|
||||
-- Code related commands
|
||||
{ "<leader>ae", "<cmd>CopilotChatExplain<cr>", desc = "CopilotChat - Explain code" },
|
||||
{ "<leader>at", "<cmd>CopilotChatTests<cr>", desc = "CopilotChat - Generate tests" },
|
||||
{ "<leader>ar", "<cmd>CopilotChatReview<cr>", desc = "CopilotChat - Review code" },
|
||||
{ "<leader>aR", "<cmd>CopilotChatRefactor<cr>", desc = "CopilotChat - Refactor code" },
|
||||
{ "<leader>an", "<cmd>CopilotChatBetterNamings<cr>", desc = "CopilotChat - Better Naming" },
|
||||
-- Chat with Copilot in visual mode
|
||||
{
|
||||
"<leader>av",
|
||||
":CopilotChatVisual",
|
||||
mode = "x",
|
||||
desc = "CopilotChat - Open in vertical split",
|
||||
},
|
||||
{
|
||||
"<leader>ax",
|
||||
":CopilotChatInline<cr>",
|
||||
mode = "x",
|
||||
desc = "CopilotChat - Inline chat",
|
||||
},
|
||||
-- Custom input for CopilotChat
|
||||
{
|
||||
"<leader>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
|
||||
{
|
||||
"<leader>am",
|
||||
"<cmd>CopilotChatCommit<cr>",
|
||||
desc = "CopilotChat - Generate commit message for all changes",
|
||||
},
|
||||
{
|
||||
"<leader>aM",
|
||||
"<cmd>CopilotChatCommitStaged<cr>",
|
||||
desc = "CopilotChat - Generate commit message for staged changes",
|
||||
},
|
||||
-- Quick chat with Copilot
|
||||
{
|
||||
"<leader>aq",
|
||||
function()
|
||||
local input = vim.fn.input("Quick Chat: ")
|
||||
if input ~= "" then
|
||||
vim.cmd("CopilotChatBuffer " .. input)
|
||||
end
|
||||
end,
|
||||
desc = "CopilotChat - Quick chat",
|
||||
},
|
||||
-- Debug
|
||||
{ "<leader>ad", "<cmd>CopilotChatDebugInfo<cr>", desc = "CopilotChat - Debug Info" },
|
||||
-- Fix the issue with diagnostic
|
||||
{ "<leader>af", "<cmd>CopilotChatFixDiagnostic<cr>", desc = "CopilotChat - Fix Diagnostic" },
|
||||
-- Clear buffer and chat history
|
||||
{ "<leader>al", "<cmd>CopilotChatReset<cr>", desc = "CopilotChat - Clear buffer and chat history" },
|
||||
-- Toggle Copilot Chat Vsplit
|
||||
{ "<leader>av", "<cmd>CopilotChatToggle<cr>", 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,
|
||||
},
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue