Skip to content

Commit cebaa5e

Browse files
committed
Add support for sticky prompt section with >
- Everything in blockquote is copied to the next prompt and added at start automatically. This is useful for preserving context/agents etc. - Remove SHOW_CONTEXT prompt as with sticky its no longer necessary imo and claude works fine without additional debugging. - Use new sticky feature with default prompts so the system prompt choice is remembered automatically - Add new `toggle_sticky_line` mapping for toggling sticky line under cursor - Update README with sticky prompts, prompts and system prompts Example: ```markdown > #files explain me this --- > #files ``` Signed-off-by: Tomas Slusny <[email protected]>
1 parent ec678b0 commit cebaa5e

File tree

5 files changed

+208
-104
lines changed

5 files changed

+208
-104
lines changed

README.md

Lines changed: 51 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -108,19 +108,49 @@ Verify "[Copilot chat in the IDE](https://github.com/settings/copilot)" is enabl
108108
- `:CopilotChatModels` - View and select available models. This is reset when a new instance is made. Please set your model in `init.lua` for persistence.
109109
- `:CopilotChatAgents` - View and select available agents. This is reset when a new instance is made. Please set your agent in `init.lua` for persistence.
110110

111-
#### Commands coming from default prompts
111+
### Prompts
112112

113-
- `:CopilotChatExplain` - Write an explanation for the selected code and diagnostics as paragraphs of text
114-
- `:CopilotChatReview` - Review the selected code
115-
- `:CopilotChatFix` - There is a problem in this code. Rewrite the code to show it with the bug fixed
116-
- `:CopilotChatOptimize` - Optimize the selected code to improve performance and readability
117-
- `:CopilotChatDocs` - Please add documentation comments to the selected code
118-
- `:CopilotChatTests` - Please generate tests for my code
119-
- `:CopilotChatCommit` - Write commit message for the change with commitizen convention
113+
You can ask Copilot to do various tasks with prompts. You can reference prompts with `/PromptName` in chat or call with command `:CopilotChat<PromptName>`.
114+
Default prompts are:
120115

121-
### Models, Agents and Contexts
116+
- `Explain` - Write an explanation for the selected code and diagnostics as paragraphs of text
117+
- `Review` - Review the selected code
118+
- `Fix` - There is a problem in this code. Rewrite the code to show it with the bug fixed
119+
- `Optimize` - Optimize the selected code to improve performance and readability
120+
- `Docs` - Please add documentation comments to the selected code
121+
- `Tests` - Please generate tests for my code
122+
- `Commit` - Write commit message for the change with commitizen convention
122123

123-
#### Models
124+
### System Prompts
125+
126+
System prompts specify the behavior of the AI model. You can reference system prompts with `/PROMPT_NAME` in chat.
127+
Default system prompts are:
128+
129+
- `COPILOT_INSTRUCTIONS` - Base GitHub Copilot instructions
130+
- `COPILOT_EXPLAIN` - On top of the base instructions adds coding tutor behavior
131+
- `COPILOT_REVIEW` - On top of the base instructions adds code review behavior with instructions on how to generate diagnostics
132+
- `COPILOT_GENERATE` - On top of the base instructions adds code generation behavior, with predefined formatting and generation rules
133+
134+
### Sticky Prompts
135+
136+
You can set sticky prompt in chat by prefixing the text with `> ` using markdown blockquote syntax.
137+
The sticky prompt will be copied at start of every new prompt in chat window. You can freely edit the sticky prompt, only rule is `> ` prefix at beginning of line.
138+
This is useful for preserving stuff like context and agent selection (see below).
139+
Example usage:
140+
141+
```markdown
142+
> #files
143+
144+
List all files in the workspace
145+
```
146+
147+
```markdown
148+
> @models Using Mistral-small
149+
150+
What is 1 + 11
151+
```
152+
153+
### Models
124154

125155
You can list available models with `:CopilotChatModels` command. Model determines the AI model used for the chat.
126156
Default models are:
@@ -133,7 +163,7 @@ Default models are:
133163
For more information about models, see [here](https://docs.github.com/en/copilot/using-github-copilot/asking-github-copilot-questions-in-your-ide#ai-models-for-copilot-chat)
134164
You can use more models from [here](https://github.com/marketplace/models) by using `@models` agent from [here](https://github.com/marketplace/models-github) (example: `@models Using Mistral-small, what is 1 + 11`)
135165

136-
#### Agents
166+
### Agents
137167

138168
Agents are used to determine the AI agent used for the chat. You can list available agents with `:CopilotChatAgents` command.
139169
You can set the agent in the prompt by using `@` followed by the agent name.
@@ -142,7 +172,7 @@ Default "noop" agent is `copilot`.
142172
For more information about extension agents, see [here](https://docs.github.com/en/copilot/using-github-copilot/using-extensions-to-integrate-external-tools-with-copilot-chat)
143173
You can install more agents from [here](https://github.com/marketplace?type=apps&copilot_app=true)
144174

145-
#### Contexts
175+
### Contexts
146176

147177
Contexts are used to determine the context of the chat.
148178
You can set the context in the prompt by using `#` followed by the context name.
@@ -262,25 +292,25 @@ Also see [here](/lua/CopilotChat/config.lua):
262292
-- default prompts
263293
prompts = {
264294
Explain = {
265-
prompt = '/COPILOT_EXPLAIN Write an explanation for the selected code and diagnostics as paragraphs of text.',
295+
prompt = '> /COPILOT_EXPLAIN\n\nWrite an explanation for the selected code and diagnostics as paragraphs of text.',
266296
},
267297
Review = {
268-
prompt = '/COPILOT_REVIEW Review the selected code.',
298+
prompt = '> /COPILOT_REVIEW\n\nReview the selected code.',
269299
callback = function(response, source)
270300
-- see config.lua for implementation
271301
end,
272302
},
273303
Fix = {
274-
prompt = '/COPILOT_GENERATE There is a problem in this code. Rewrite the code to show it with the bug fixed.',
304+
prompt = '> /COPILOT_GENERATE\n\nThere is a problem in this code. Rewrite the code to show it with the bug fixed.',
275305
},
276306
Optimize = {
277-
prompt = '/COPILOT_GENERATE Optimize the selected code to improve performance and readability.',
307+
prompt = '> /COPILOT_GENERATE\n\nOptimize the selected code to improve performance and readability.',
278308
},
279309
Docs = {
280-
prompt = '/COPILOT_GENERATE Please add documentation comments to the selected code.',
310+
prompt = '> /COPILOT_GENERATE\n\nPlease add documentation comments to the selected code.',
281311
},
282312
Tests = {
283-
prompt = '/COPILOT_GENERATE Please generate tests for my code.',
313+
prompt = '> /COPILOT_GENERATE\n\nPlease generate tests for my code.',
284314
},
285315
Commit = {
286316
prompt = 'Write 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.',
@@ -321,6 +351,9 @@ Also see [here](/lua/CopilotChat/config.lua):
321351
normal = '<CR>',
322352
insert = '<C-s>'
323353
},
354+
toggle_sticky_line = {
355+
normal = 'gr',
356+
},
324357
accept_diff = {
325358
normal = '<C-y>',
326359
insert = '<C-y>'

lua/CopilotChat/chat.lua

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
---@field close fun(self: CopilotChat.Chat, bufnr: number?)
1212
---@field focus fun(self: CopilotChat.Chat)
1313
---@field follow fun(self: CopilotChat.Chat)
14-
---@field finish fun(self: CopilotChat.Chat, msg: string?)
14+
---@field finish fun(self: CopilotChat.Chat, msg: string?, offset: number?)
1515
---@field delete fun(self: CopilotChat.Chat)
1616

1717
local Overlay = require('CopilotChat.overlay')
@@ -280,11 +280,15 @@ function Chat:follow()
280280
vim.api.nvim_win_set_cursor(self.winnr, { last_line + 1, last_column })
281281
end
282282

283-
function Chat:finish(msg)
283+
function Chat:finish(msg, offset)
284284
if not self.spinner then
285285
return
286286
end
287287

288+
if not offset then
289+
offset = 0
290+
end
291+
288292
self.spinner:finish()
289293

290294
if msg and msg ~= '' then
@@ -295,7 +299,7 @@ function Chat:finish(msg)
295299
msg = self.help
296300
end
297301

298-
self:show_help(msg, -2)
302+
self:show_help(msg, -offset)
299303
if self.auto_insert and self:active() then
300304
vim.cmd('startinsert')
301305
end

lua/CopilotChat/config.lua

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ local select = require('CopilotChat.select')
5454
---@field close CopilotChat.config.mapping?
5555
---@field reset CopilotChat.config.mapping?
5656
---@field submit_prompt CopilotChat.config.mapping?
57+
---@field toggle_sticky_line CopilotChat.config.mapping?
5758
---@field accept_diff CopilotChat.config.mapping?
5859
---@field yank_diff CopilotChat.config.mapping?
5960
---@field show_diff CopilotChat.config.mapping?
@@ -125,10 +126,10 @@ return {
125126
-- default prompts
126127
prompts = {
127128
Explain = {
128-
prompt = '/COPILOT_EXPLAIN Write an explanation for the selected code and diagnostics as paragraphs of text.',
129+
prompt = '> /COPILOT_EXPLAIN\n\nWrite an explanation for the selected code and diagnostics as paragraphs of text.',
129130
},
130131
Review = {
131-
prompt = '/COPILOT_REVIEW Review the selected code.',
132+
prompt = '> /COPILOT_REVIEW\n\nReview the selected code.',
132133
callback = function(response, source)
133134
local diagnostics = {}
134135
for line in response:gmatch('[^\r\n]+') do
@@ -170,16 +171,16 @@ return {
170171
end,
171172
},
172173
Fix = {
173-
prompt = '/COPILOT_GENERATE There is a problem in this code. Rewrite the code to show it with the bug fixed.',
174+
prompt = '> /COPILOT_GENERATE\n\nThere is a problem in this code. Rewrite the code to show it with the bug fixed.',
174175
},
175176
Optimize = {
176-
prompt = '/COPILOT_GENERATE Optimize the selected code to improve performance and readability.',
177+
prompt = '> /COPILOT_GENERATE\n\nOptimize the selected code to improve performance and readability.',
177178
},
178179
Docs = {
179-
prompt = '/COPILOT_GENERATE Please add documentation comments to the selected code.',
180+
prompt = '> /COPILOT_GENERATE\n\nPlease add documentation comments to the selected code.',
180181
},
181182
Tests = {
182-
prompt = '/COPILOT_GENERATE Please generate tests for my code.',
183+
prompt = '> /COPILOT_GENERATE\n\nPlease generate tests for my code.',
183184
},
184185
Commit = {
185186
prompt = 'Write 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.',
@@ -220,6 +221,9 @@ return {
220221
normal = '<CR>',
221222
insert = '<C-s>',
222223
},
224+
toggle_sticky_line = {
225+
normal = 'gr',
226+
},
223227
accept_diff = {
224228
normal = '<C-y>',
225229
insert = '<C-y>',

0 commit comments

Comments
 (0)