Skip to content

Commit de8ccf0

Browse files
committed
docs: improve README with better examples and cleaner structure
Previously, the documentation for custom prompts, system prompts and contexts was scattered and duplicated across multiple sections. This change consolidates and improves the documentation by: - Moving examples next to their relevant sections - Adding clearer and more concise examples for custom prompts, system prompts and contexts - Removing duplicate content that was spread across multiple sections - Making github/copilot.vim the primary recommended Copilot backend Signed-off-by: Tomas Slusny <[email protected]>
1 parent a2934a1 commit de8ccf0

File tree

2 files changed

+66
-63
lines changed

2 files changed

+66
-63
lines changed

README.md

Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ return {
3232
"CopilotC-Nvim/CopilotChat.nvim",
3333
branch = "canary",
3434
dependencies = {
35-
{ "zbirenbaum/copilot.lua" }, -- or github/copilot.vim
35+
{ "github/copilot.vim" }, -- or zbirenbaum/copilot.lua
3636
{ "nvim-lua/plenary.nvim" }, -- for curl, log wrapper
3737
},
3838
build = "make tiktoken", -- Only on MacOS or Linux
@@ -52,7 +52,7 @@ Similar to the lazy setup, you can use the following configuration:
5252

5353
```vim
5454
call plug#begin()
55-
Plug 'zbirenbaum/copilot.lua'
55+
Plug 'github/copilot.vim'
5656
Plug 'nvim-lua/plenary.nvim'
5757
Plug 'CopilotC-Nvim/CopilotChat.nvim', { 'branch': 'canary' }
5858
call plug#end()
@@ -72,7 +72,7 @@ EOF
7272
mkdir -p ~/.config/nvim/pack/copilotchat/start
7373
cd ~/.config/nvim/pack/copilotchat/start
7474
75-
git clone https://github.com/zbirenbaum/copilot.lua
75+
git clone https://github.com/github/copilot.vim
7676
git clone https://github.com/nvim-lua/plenary.nvim
7777
7878
git clone -b canary https://github.com/CopilotC-Nvim/CopilotChat.nvim
@@ -121,6 +121,21 @@ Default prompts are:
121121
- `Tests` - Please generate tests for my code
122122
- `Commit` - Write commit message for the change with commitizen convention
123123

124+
You can define custom prompts like this (only `prompt` is required):
125+
126+
```lua
127+
{
128+
prompts = {
129+
MyCustomPrompt = {
130+
prompt = 'Explain how it works.',
131+
system_prompt = 'You are very good at explaining stuff',
132+
mapping = '<leader>ccmc',
133+
description = 'My custom prompt description',
134+
}
135+
}
136+
}
137+
```
138+
124139
### System Prompts
125140

126141
System prompts specify the behavior of the AI model. You can reference system prompts with `/PROMPT_NAME` in chat.
@@ -131,6 +146,18 @@ Default system prompts are:
131146
- `COPILOT_REVIEW` - On top of the base instructions adds code review behavior with instructions on how to generate diagnostics
132147
- `COPILOT_GENERATE` - On top of the base instructions adds code generation behavior, with predefined formatting and generation rules
133148

149+
You can define custom system prompts like this (works same as `prompts` so you can combine prompt and system prompt definitions):
150+
151+
```lua
152+
{
153+
prompts = {
154+
Yarrr = {
155+
system_prompt = 'You are fascinated by pirates, so please respond in pirate speak.',
156+
}
157+
}
158+
}
159+
```
160+
134161
### Sticky Prompts
135162

136163
You can set sticky prompt in chat by prefixing the text with `> ` using markdown blockquote syntax.
@@ -186,6 +213,39 @@ Default contexts are:
186213
- `files` - Includes all non-hidden filenames in the current workspace in chat context. Supports input.
187214
- `git` - Includes current git diff in chat context (default unstaged). Supports input.
188215

216+
You can define custom contexts like this:
217+
218+
```lua
219+
{
220+
contexts = {
221+
birthday = {
222+
input = function(callback)
223+
vim.ui.select({ 'user', 'napoleon' }, {
224+
prompt = 'Select birthday> ',
225+
}, callback)
226+
end,
227+
resolve = function(input)
228+
input = input or 'user'
229+
local birthday = input
230+
if input == 'user' then
231+
birthday = birthday .. ' birthday is April 1, 1990'
232+
elseif input == 'napoleon' then
233+
birthday = birthday .. ' birthday is August 15, 1769'
234+
end
235+
236+
return {
237+
{
238+
content = birthday,
239+
filename = input .. '_birthday',
240+
filetype = 'text',
241+
}
242+
}
243+
end
244+
}
245+
}
246+
}
247+
```
248+
189249
### API
190250

191251
```lua
@@ -396,66 +456,6 @@ Also see [here](/lua/CopilotChat/config.lua):
396456
}
397457
```
398458

399-
For further reference, you can view @jellydn's [configuration](https://github.com/jellydn/lazy-nvim-ide/blob/main/lua/plugins/extras/copilot-chat-v2.lua).
400-
401-
### Defining a prompt with command and keymap
402-
403-
This will define prompt that you can reference with `/MyCustomPrompt` in chat, call with `:CopilotChatMyCustomPrompt` or use the keymap `<leader>ccmc`.
404-
It will use visual selection as default selection. If you are using `lazy.nvim` and are already lazy loading based on `Commands` make sure to include the prompt
405-
commands and keymaps in `cmd` and `keys` respectively.
406-
407-
```lua
408-
{
409-
prompts = {
410-
MyCustomPrompt = {
411-
prompt = 'Explain how it works.',
412-
mapping = '<leader>ccmc',
413-
description = 'My custom prompt description',
414-
selection = require('CopilotChat.select').visual,
415-
},
416-
},
417-
}
418-
```
419-
420-
### Referencing system or user prompts
421-
422-
You can reference system or user prompts in your configuration or in chat with `/PROMPT_NAME` slash notation.
423-
For collection of default `COPILOT_` (system) and `USER_` (user) prompts, see [here](/lua/CopilotChat/prompts.lua).
424-
425-
```lua
426-
{
427-
prompts = {
428-
MyCustomPrompt = {
429-
prompt = '/COPILOT_EXPLAIN Explain how it works.',
430-
},
431-
MyCustomPrompt2 = {
432-
prompt = '/MyCustomPrompt Include some additional context.',
433-
},
434-
},
435-
}
436-
```
437-
438-
### Custom system prompts
439-
440-
You can define custom system prompts by using `system_prompt` property when passing config around.
441-
442-
```lua
443-
{
444-
system_prompt = 'Your name is Github Copilot and you are a AI assistant for developers.',
445-
prompts = {
446-
Johnny = {
447-
system_prompt = 'Your name is Johny Microsoft and you are not an AI assistant for developers.',
448-
prompt = 'Explain how it works.',
449-
},
450-
Yarrr = {
451-
system_prompt = 'You are fascinated by pirates, so please respond in pirate speak.'
452-
},
453-
},
454-
}
455-
```
456-
457-
To use any of your custom prompts, simply do `:CopilotChat<prompt name>`. E.g. `:CopilotChatJohnny` or `:CopilotChatYarrr What is a sorting algo?`. Tab autocomplete will help you out.
458-
459459
### Customizing buffers
460460

461461
You can set local options for the buffers that are created by this plugin: `copilot-diff`, `copilot-system-prompt`, `copilot-user-selection`, `copilot-chat`.

lua/CopilotChat/init.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,9 @@ function M.ask(prompt, config)
570570
local context_name = table.remove(split, 1)
571571
local context_input = table.concat(split, ':')
572572
local context_value = config.contexts[context_name]
573+
if vim.trim(context_input) == '' then
574+
context_input = nil
575+
end
573576

574577
if context_value then
575578
for _, embedding in ipairs(context_value.resolve(context_input, state.source)) do

0 commit comments

Comments
 (0)