forked from CopilotC-Nvim/CopilotChat.nvim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCopilotChat.txt
More file actions
376 lines (281 loc) · 13.2 KB
/
Copy pathCopilotChat.txt
File metadata and controls
376 lines (281 loc) · 13.2 KB
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
*CopilotChat.txt* For NVIM v0.8.0 Last change: 2024 February 11
==============================================================================
Table of Contents *CopilotChat-table-of-contents*
1. Copilot Chat for Neovim |CopilotChat-copilot-chat-for-neovim|
- Prerequisites |CopilotChat-copilot-chat-for-neovim-prerequisites|
- Authentication |CopilotChat-copilot-chat-for-neovim-authentication|
- Installation |CopilotChat-copilot-chat-for-neovim-installation|
- Usage |CopilotChat-copilot-chat-for-neovim-usage|
- Tips |CopilotChat-copilot-chat-for-neovim-tips|
- Roadmap (Wishlist)|CopilotChat-copilot-chat-for-neovim-roadmap-(wishlist)|
- Development |CopilotChat-copilot-chat-for-neovim-development|
- Contributors ✨ |CopilotChat-copilot-chat-for-neovim-contributors-✨|
==============================================================================
1. Copilot Chat for Neovim *CopilotChat-copilot-chat-for-neovim*
|CopilotChat-|
[!NOTE] A new command, `CopilotChatInPlace` has been introduced. It functions
like the ChatGPT plugin. Please run ":UpdateRemotePlugins" command and restart
Neovim before starting a chat with Copilot. To stay updated on our roadmap,
please join our Discord <https://discord.gg/vy6hJsTWaZ> community.
PREREQUISITES *CopilotChat-copilot-chat-for-neovim-prerequisites*
Ensure you have the following installed:
- Python 3.10 or later
AUTHENTICATION *CopilotChat-copilot-chat-for-neovim-authentication*
It will prompt you with instructions on your first start. If you already have
`Copilot.vim` or `Copilot.lua`, it will work automatically.
INSTALLATION *CopilotChat-copilot-chat-for-neovim-installation*
LAZY.NVIM ~
1. `pip install python-dotenv requests pynvim==0.5.0 prompt-toolkit`
2. `pip install tiktoken` (optional for displaying prompt token counts)
3. Put it in your lazy setup
>lua
return {
{
"CopilotC-Nvim/CopilotChat.nvim",
opts = {
show_help = "yes", -- Show help text for CopilotChatInPlace, default: yes
debug = false, -- Enable or disable debug mode, the log file will be in ~/.local/state/nvim/CopilotChat.nvim.log
disable_extra_info = 'no', -- Disable extra information (e.g: system prompt) in the response.
-- proxy = "socks5://127.0.0.1:3000", -- 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 = {
{ "<leader>cce", "<cmd>CopilotChatExplain<cr>", desc = "CopilotChat - Explain code" },
{ "<leader>cct", "<cmd>CopilotChatTests<cr>", desc = "CopilotChat - Generate tests" },
{
"<leader>ccv",
":CopilotChatVisual",
mode = "x",
desc = "CopilotChat - Open in vertical split",
},
{
"<leader>ccx",
":CopilotChatInPlace<cr>",
mode = "x",
desc = "CopilotChat - Run in-place code",
},
},
},
}
<
1. Run command `:UpdateRemotePlugins`, then inspect the file `~/.local/share/nvim/rplugin.vim` for additional details. You will notice that the commands have been registered.
For example:
>vim
" python3 plugins
call remote#host#RegisterPlugin('python3', '/Users/huynhdung/.local/share/nvim/lazy/CopilotChat.nvim/rplugin/python3/copilot-plugin.py', [
\ {'sync': v:false, 'name': 'CopilotChat', 'type': 'command', 'opts': {'nargs': '1'}},
\ {'sync': v:false, 'name': 'CopilotChatVisual', 'type': 'command', 'opts': {'nargs': '1', 'range': ''}},
\ {'sync': v:false, 'name': 'CopilotChatInPlace', 'type': 'command', 'opts': {'nargs': '*', 'range': ''}},
\ {'sync': v:false, 'name': 'CopilotChatAutocmd', 'type': 'command', 'opts': {'nargs': '*'}},
\ {'sync': v:false, 'name': 'CopilotChatMapping', 'type': 'command', 'opts': {'nargs': '*'}},
\ ])
<
1. Restart `neovim`
MANUAL ~
1. Put the files in the right place
>
$ git clone https://github.com/CopilotC-Nvim/CopilotChat.nvim
$ cd CopilotChat.nvim
$ cp -r --backup=nil rplugin ~/.config/nvim/
<
1. Install dependencies
>
$ pip install -r requirements.txt
<
1. Open up Neovim and run `:UpdateRemotePlugins`
2. Restart Neovim
USAGE *CopilotChat-copilot-chat-for-neovim-usage*
CONFIGURATION ~
You have the ability to tailor this plugin to your specific needs using the
configuration options outlined below:
>lua
{
debug = false, -- Enable or disable debug mode
show_help = 'yes', -- Show help text for CopilotChatInPlace
prompts = { -- Set dynamic prompts for CopilotChat commands
Explain = 'Explain how it works.',
Tests = 'Briefly explain how the selected code works, then generate unit tests.',
}
}
<
You have the capability to expand the prompts to create more versatile
commands:
>lua
return {
"CopilotC-Nvim/CopilotChat.nvim",
opts = {
debug = true,
show_help = "yes",
prompts = {
Explain = "Explain how it works.",
Review = "Review the following code and provide concise suggestions.",
Tests = "Briefly explain how the selected code works, then generate unit tests.",
Refactor = "Refactor the code to improve clarity and readability.",
},
},
build = function()
vim.notify("Please update the remote plugins by running ':UpdateRemotePlugins', then restart Neovim.")
end,
event = "VeryLazy",
keys = {
{ "<leader>cce", "<cmd>CopilotChatExplain<cr>", desc = "CopilotChat - Explain code" },
{ "<leader>cct", "<cmd>CopilotChatTests<cr>", desc = "CopilotChat - Generate tests" },
{ "<leader>ccr", "<cmd>CopilotChatReview<cr>", desc = "CopilotChat - Review code" },
{ "<leader>ccR", "<cmd>CopilotChatRefactor<cr>", desc = "CopilotChat - Refactor code" },
}
}
<
For further reference, you can view @jellydn’s configuration
<https://github.com/jellydn/lazy-nvim-ide/blob/main/lua/plugins/extras/copilot-chat.lua>.
CHAT WITH GITHUB COPILOT ~
1. Copy some code into the unnamed register using the `y` command.
2. Run the command `:CopilotChat` followed by your question. For example, `:CopilotChat What does this code do?`
CODE EXPLANATION ~
1. Copy some code into the unnamed register using the `y` command.
2. Run the command `:CopilotChatExplain`.
GENERATE TESTS ~
1. Copy some code into the unnamed register using the `y` command.
2. Run the command `:CopilotChatTests`.
<https://gyazo.com/f285467d4b8d8f8fd36aa777305312ae>
TOKEN COUNT & FOLD WITH VISUAL MODE ~
1. Select some code using visual mode.
2. Run the command `:CopilotChatVisual` with your question.
<https://gyazo.com/766fb3b6ffeb697e650fc839882822a8>
IN-PLACE CHAT POPUP ~
1. Select some code using visual mode.
2. Run the command `:CopilotChatInPlace` and type your prompt. For example, `What does this code do?`
3. Press `Enter` to send your question to Github Copilot.
4. Press `q` to quit. There is help text at the bottom of the screen. You can also press `?` to toggle the help text.
<https://gyazo.com/4a5badaa109cd483c1fc23d296325cb0>
TIPS *CopilotChat-copilot-chat-for-neovim-tips*
DEBUGGING WITH :MESSAGES AND :COPILOTCHATDEBUGINFO ~
If you encounter any issues, you can run the command `:messages` to inspect the
log. You can also run the command `:CopilotChatDebugInfo` to inspect the debug
information.
<https://gyazo.com/bf00e700bcee1b77bcbf7b516b552521>
HOW TO SETUP WITH WHICH-KEY.NVIM ~
A special thanks to @ecosse3 for the configuration of which-key
<https://github.com/jellydn/CopilotChat.nvim/issues/30>.
>lua
{
"CopilotC-Nvim/CopilotChat.nvim",
event = "VeryLazy",
opts = {
prompts = {
Explain = "Explain how it works.",
Review = "Review the following code and provide concise suggestions.",
Tests = "Briefly explain how the selected code works, then generate unit tests.",
Refactor = "Refactor the code to improve clarity and readability.",
},
},
build = function()
vim.notify("Please update the remote plugins by running ':UpdateRemotePlugins', then restart Neovim.")
end,
config = function()
local present, wk = pcall(require, "which-key")
if not present then
return
end
wk.register({
c = {
c = {
name = "Copilot Chat",
}
}
}, {
mode = "n",
prefix = "<leader>",
silent = true,
noremap = true,
nowait = false,
})
end,
keys = {
{ "<leader>ccc", ":CopilotChat ", desc = "CopilotChat - Prompt" },
{ "<leader>cce", ":CopilotChatExplain ", desc = "CopilotChat - Explain code" },
{ "<leader>cct", "<cmd>CopilotChatTests<cr>", desc = "CopilotChat - Generate tests" },
{ "<leader>ccr", "<cmd>CopilotChatReview<cr>", desc = "CopilotChat - Review code" },
{ "<leader>ccR", "<cmd>CopilotChatRefactor<cr>", desc = "CopilotChat - Refactor code" },
}
},
<
CREATE A SIMPLE INPUT FOR COPILOTCHAT ~
Follow the example below to create a simple input for CopilotChat.
>lua
-- Create input for CopilotChat
{
"<leader>cci",
function()
local input = vim.fn.input("Ask Copilot: ")
if input ~= "" then
vim.cmd("CopilotChat " .. input)
end
end,
desc = "CopilotChat - Ask input",
},
<
ADD SAME KEYBINDS IN BOTH VISUAL AND NORMAL MODE ~
>lua
{
"CopilotC-Nvim/CopilotChat.nvim",
keys =
function()
local keybinds={
--add your custom keybinds here
}
-- change prompt and keybinds as per your need
local my_prompts = {
{prompt = "In Neovim.",desc = "Neovim",key = "n"},
{prompt = "Help with this",desc = "Help",key = "h"},
{prompt = "Simplify and imporve readablilty",desc = "Simplify",key = "s"},
{prompt = "Optimize the code to improve perfomance and readablilty.",desc = "Optimize",key = "o"},
{prompt = "Find possible errors and fix them for me",desc = "Fix",key = "f"},
{prompt = "Explain in detail",desc = "Explain",key = "e"},
{prompt = "Write a shell scirpt",desc = "Shell",key = "S"},
}
-- you can change <leader>cc to your desired keybind prefix
for _,v in pairs(my_prompts) do
table.insert(keybinds,{ "<leader>cc"..v.key, ":CopilotChatVisual "..v.prompt.."<cr>", mode = "x", desc = "CopilotChat - "..v.desc })
table.insert(keybinds,{ "<leader>cc"..v.key, "<cmd>CopilotChat "..v.prompt.."<cr>", desc = "CopilotChat - "..v.desc })
end
return keybinds
end,
},
<
ROADMAP (WISHLIST) *CopilotChat-copilot-chat-for-neovim-roadmap-(wishlist)*
- Use vector encodings to automatically select code
- Treesitter integration for function definitions
- General QOL improvements
DEVELOPMENT *CopilotChat-copilot-chat-for-neovim-development*
INSTALLING PRE-COMMIT TOOL ~
For development, you can use the provided Makefile command to install the
pre-commit tool:
>bash
make install-pre-commit
<
This will install the pre-commit tool and the pre-commit hooks.
CONTRIBUTORS ✨ *CopilotChat-copilot-chat-for-neovim-contributors-✨*
Thanks goes to these wonderful people (emoji key
<https://allcontributors.org/docs/en/emoji-key>):
gptlang💻 📖Dung Duc Huynh (Kaka)💻 📖Ahmed Haracic💻Trí Thiện Nguyễn💻He Zhizhou💻Guruprakash Rajakkannu💻kristofka💻PostCyberPunk📖Katsuhiko Nishimra💻This project follows the all-contributors
<https://github.com/all-contributors/all-contributors> specification.
Contributions of any kind are welcome!
STARGAZERS OVER TIME ~
<https://starchart.cc/CopilotC-Nvim/CopilotChat.nvim>
==============================================================================
2. Links *CopilotChat-links*
1. *All Contributors*: https://img.shields.io/badge/all_contributors-9-orange.svg?style=flat-square
2. *@jellydn*:
3. *Chat Demo*: https://i.gyazo.com/10fbd1543380d15551791c1a6dcbcd46.gif
4. *Explain Code Demo*: https://i.gyazo.com/e5031f402536a1a9d6c82b2c38d469e3.gif
5. *Generate tests*: https://i.gyazo.com/f285467d4b8d8f8fd36aa777305312ae.gif
6. *Fold Demo*: https://i.gyazo.com/766fb3b6ffeb697e650fc839882822a8.gif
7. *In-place Demo*: https://i.gyazo.com/4a5badaa109cd483c1fc23d296325cb0.gif
8. *Debug Info*: https://i.gyazo.com/bf00e700bcee1b77bcbf7b516b552521.gif
9. *@ecosse3*:
10. *Stargazers over time*: https://starchart.cc/CopilotC-Nvim/CopilotChat.nvim.svg
Generated by panvimdoc <https://github.com/kdheepak/panvimdoc>
vim:tw=78:ts=8:noet:ft=help:norl: