generated from LazyVim/starter
-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcopilot-chat.lua
157 lines (153 loc) · 5.9 KB
/
copilot-chat.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
local IS_DEV = false
--- Get all the changes in the git repository
---@param staged? boolean
---@return string
local function get_git_diff(staged)
local cmd = staged and "git diff --staged" or "git diff"
local handle = io.popen(cmd)
if not handle then
return ""
end
local result = handle:read("*a")
handle:close()
return result
end
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" },
{
dir = IS_DEV and "~/Projects/research/CopilotChat.nvim" or nil,
"CopilotC-Nvim/CopilotChat.nvim",
version = "1.9.1",
dependencies = {
{ "nvim-telescope/telescope.nvim" }, -- Use telescope for help actions
{ "nvim-lua/plenary.nvim" },
},
opts = {
show_help = "no",
prompts = prompts,
debug = false, -- Set to true to see response from Github Copilot API. The log file will be in ~/.local/state/nvim/CopilotChat.nvim.log.
disable_extra_info = "no", -- Disable extra information (e.g: system prompt, token count) in the response.
hide_system_prompt = "yes", -- Show user prompts only and hide system prompts.
proxy = "", -- Proxies requests via https or socks
},
build = function()
vim.notify("Please update the remote plugins by running ':UpdateRemotePlugins', then restart Neovim.")
end,
event = "VeryLazy",
keys = {
-- Show help actions with telescope
{
"<leader>ah",
function()
require("CopilotChat.code_actions").show_help_actions()
end,
desc = "CopilotChat - Help actions",
},
-- Show prompts actions with telescope
{
"<leader>ap",
function()
require("CopilotChat.code_actions").show_prompt_actions()
end,
desc = "CopilotChat - Prompt actions",
},
{
"<leader>ap",
":lua require('CopilotChat.code_actions').show_prompt_actions(true)<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",
":CopilotChatInPlace<cr>",
mode = "x",
desc = "CopilotChat - Run in-place code",
},
-- 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",
function()
local diff = get_git_diff()
if diff ~= "" then
vim.fn.setreg('"', diff)
vim.cmd("CopilotChat Write commit message for the change with commitizen convention.")
end
end,
desc = "CopilotChat - Generate commit message for all changes",
},
{
"<leader>aM",
function()
local diff = get_git_diff(true)
if diff ~= "" then
vim.fn.setreg('"', diff)
vim.cmd("CopilotChat Write commit message for the change with commitizen convention.")
end
end,
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" },
{ "<leader>aF", "<cmd>CopilotChatFixError<cr>", desc = "CopilotChat - Fix Error" },
-- Clear buffer and chat history
{ "<leader>al", "<cmd>CopilotChatReset<cr>", desc = "CopilotChat - Clear buffer and chat history" },
-- Toggle Copilot Chat Vsplit
{ "<leader>av", "<cmd>CopilotChatVsplitToggle<cr>", desc = "CopilotChat - Toggle Vsplit" },
},
},
}