You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(context): rewrite context system with input and resolving
Now contexts are defined in configuration with input and resolve functions. This
allows for more flexible and extensible context system. It also makes the system
more robust and easier to understand.
The changes include:
- Add context inputs (with `:` after context) for additional parameters
- Add proper model selection (with `$` prefix)
- Move context resolution logic to config.lua
- Extract git diff to context.gitdiff
- Simplify outline/files logic, make it more modular
- Improve pattern matching for context/model/agent parsing
- Add truncation for large selections
Signed-off-by: Tomas Slusny <[email protected]>
Copy file name to clipboardExpand all lines: README.md
+42-12Lines changed: 42 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -153,6 +153,7 @@ What is 1 + 11
153
153
### Models
154
154
155
155
You can list available models with `:CopilotChatModels` command. Model determines the AI model used for the chat.
156
+
You can set the model in the prompt by using `$` followed by the model name.
156
157
Default models are:
157
158
158
159
-`gpt-4o` - This is the default Copilot Chat model. It is a versatile, multimodal model that excels in both text and image processing and is designed to provide fast, reliable responses. It also has superior performance in non-English languages. Gpt-4o is hosted on Azure.
@@ -176,11 +177,14 @@ You can install more agents from [here](https://github.com/marketplace?type=apps
176
177
177
178
Contexts are used to determine the context of the chat.
178
179
You can set the context in the prompt by using `#` followed by the context name.
179
-
Supported contexts are:
180
+
If context supports input, you can set the input in the prompt by using `:` followed by the input (or pressing `complete` key after `:`).
181
+
Default contexts are:
180
182
183
+
-`buffer` - Includes only the current buffer in chat context. Supports input.
181
184
-`buffers` - Includes all open buffers in chat context
182
-
-`buffer` - Includes only the current buffer in chat context
183
-
-`files` - Includes all non-hidden filenames in the current workspace in chat context
185
+
-`file` - Includes content of provided file in chat context. Supports input.
186
+
-`files` - Includes all non-hidden filenames in the current workspace in chat context. Supports input.
187
+
-`git` - Includes current git diff in chat context. Supports input.
184
188
185
189
### API
186
190
@@ -261,17 +265,16 @@ Also see [here](/lua/CopilotChat/config.lua):
261
265
proxy=nil, -- [protocol://]host[:port] Use this proxy
262
266
allow_insecure=false, -- Allow insecure server connections
263
267
264
-
system_prompt=prompts.COPILOT_INSTRUCTIONS, -- System prompt to use
265
-
model='gpt-4o', -- Default model to use, see ':CopilotChatModels' for available models
268
+
system_prompt=prompts.COPILOT_INSTRUCTIONS, -- System prompt to use (can be specified manually in prompt via /).
269
+
model='gpt-4o', -- Default model to use, see ':CopilotChatModels' for available models (can be specified manually in prompt via $).
266
270
agent='copilot', -- Default agent to use, see ':CopilotChatAgents' for available agents (can be specified manually in prompt via @).
267
-
context=nil, -- Default context to use, 'buffers', 'buffer', 'files' or none (can be specified manually in prompt via #).
271
+
context=nil, -- Default context to use (can be specified manually in prompt via #).
268
272
temperature=0.1, -- GPT result temperature
269
273
270
274
question_header='## User ', -- Header to use for user questions
271
275
answer_header='## Copilot ', -- Header to use for AI answers
272
276
error_header='## Error ', -- Header to use for errors
273
277
separator='───', -- Separator to use in chat
274
-
highlight_headers=true, -- Highlight headers in chat, disable if using markdown renderers (like render-markdown.nvim)
275
278
276
279
show_folds=true, -- Shows folds for sections in chat
277
280
show_help=true, -- Shows help message as virtual lines when waiting for user input
@@ -280,6 +283,7 @@ Also see [here](/lua/CopilotChat/config.lua):
280
283
insert_at_end=false, -- Move cursor to end of buffer when inserting text
281
284
clear_chat_on_new_prompt=false, -- Clears chat on every new prompt
282
285
highlight_selection=true, -- Highlight selection in the source buffer when in the chat window
286
+
highlight_headers=true, -- Highlight headers in chat, disable if using markdown renderers (like render-markdown.nvim)
283
287
284
288
history_path=vim.fn.stdpath('data') ..'/copilotchat_history', -- Default path to stored history
285
289
callback=nil, -- Callback to use when ask response is received
@@ -289,16 +293,43 @@ Also see [here](/lua/CopilotChat/config.lua):
prompt='> /COPILOT_EXPLAIN\n\nWrite an explanation for the selected code and diagnostics as paragraphs of text.',
296
328
},
297
329
Review= {
330
+
-- see config.lua for implementation
298
331
prompt='> /COPILOT_REVIEW\n\nReview the selected code.',
299
-
callback=function(response, source)
300
-
-- see config.lua for implementation
301
-
end,
332
+
callback=function(response, source) end,
302
333
},
303
334
Fix= {
304
335
prompt='> /COPILOT_GENERATE\n\nThere is a problem in this code. Rewrite the code to show it with the bug fixed.',
@@ -313,8 +344,7 @@ Also see [here](/lua/CopilotChat/config.lua):
313
344
prompt='> /COPILOT_GENERATE\n\nPlease generate tests for my code.',
314
345
},
315
346
Commit= {
316
-
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.',
317
-
selection=select.gitdiff,
347
+
prompt='> #git:staged\n\nWrite 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.',
description='Includes content of provided file in chat context. Supports input.',
162
+
input=function(callback)
163
+
localfiles=vim.tbl_filter(function(file)
164
+
returnvim.fn.isdirectory(file) ==0
165
+
end, vim.fn.glob('**/*', false, true))
166
+
167
+
vim.ui.select(files, {
168
+
prompt='Select a file> ',
169
+
}, callback)
170
+
end,
171
+
resolve=function(input)
172
+
return {
173
+
context.file(input),
174
+
}
175
+
end,
176
+
},
177
+
files= {
178
+
description='Includes all non-hidden filenames in the current workspace in chat context. Supports input.',
179
+
input=function(callback)
180
+
vim.ui.input({
181
+
prompt='Enter a file pattern> ',
182
+
default='**/*',
183
+
}, callback)
184
+
end,
185
+
resolve=function(input)
186
+
returncontext.files(input)
187
+
end,
188
+
},
189
+
git= {
190
+
description='Includes current git diff in chat context. Supports input.',
191
+
input=function(callback)
192
+
vim.ui.select({ 'unstaged', 'staged' }, {
193
+
prompt='Select diff type> ',
194
+
}, callback)
195
+
end,
196
+
resolve=function(input, source)
197
+
return {
198
+
context.gitdiff(input, source.bufnr),
199
+
}
200
+
end,
201
+
},
202
+
},
203
+
126
204
-- default prompts
127
205
prompts= {
128
206
Explain= {
@@ -183,8 +261,7 @@ return {
183
261
prompt='> /COPILOT_GENERATE\n\nPlease generate tests for my code.',
184
262
},
185
263
Commit= {
186
-
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.',
187
-
selection=select.gitdiff,
264
+
prompt='> #git:staged\n\nWrite 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.',
0 commit comments