Skip to content

Commit d7e8a76

Browse files
authored
Merge branch 'CopilotC-Nvim:main' into main
2 parents e9a33c5 + a89f5f1 commit d7e8a76

13 files changed

Lines changed: 98 additions & 36 deletions

File tree

.all-contributorsrc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,20 @@
375375
"avatar_url": "https://avatars.githubusercontent.com/u/810650?v=4",
376376
"profile": "https://teoljungberg.com",
377377
"contributions": ["code"]
378+
},
379+
{
380+
"login": "JPricey",
381+
"name": "Joe Price",
382+
"avatar_url": "https://avatars.githubusercontent.com/u/4826348?v=4",
383+
"profile": "https://github.com/JPricey",
384+
"contributions": ["code"]
385+
},
386+
{
387+
"login": "ouuan",
388+
"name": "Yufan You",
389+
"avatar_url": "https://avatars.githubusercontent.com/u/30581822?v=4",
390+
"profile": "https://ouuan.moe/about",
391+
"contributions": ["doc", "code"]
378392
}
379393
],
380394
"contributorsPerLine": 7,

CHANGELOG.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,27 @@
11
# Changelog
22

3+
## [3.11.0](https://github.com/CopilotC-Nvim/CopilotChat.nvim/compare/v3.10.1...v3.11.0) (2025-04-09)
4+
5+
6+
### Features
7+
8+
* add option to disable contexts in prompts ([14c78d2](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/14c78d24e1db88384dc878e870665c3a7ad61a3a))
9+
* change default selection to visual only ([a63031f](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/a63031fc706d4e34e118c46339ae2b5681fab21e)), closes [#1103](https://github.com/CopilotC-Nvim/CopilotChat.nvim/issues/1103)
10+
11+
12+
### Bug Fixes
13+
14+
* set default model to gpt-4o again ([381d5cd](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/381d5cddd25abec595c3c611e96cae2ba61d7ea5)), closes [#1105](https://github.com/CopilotC-Nvim/CopilotChat.nvim/issues/1105)
15+
16+
## [3.10.1](https://github.com/CopilotC-Nvim/CopilotChat.nvim/compare/v3.10.0...v3.10.1) (2025-04-04)
17+
18+
19+
### Bug Fixes
20+
21+
* **client:** update response_text after parsing response ([#1093](https://github.com/CopilotC-Nvim/CopilotChat.nvim/issues/1093)) ([34d1b4f](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/34d1b4fc816401c9bad88b33f71ef943a7dd2396)), closes [#1064](https://github.com/CopilotC-Nvim/CopilotChat.nvim/issues/1064)
22+
* **diff:** normalize filename ([#1095](https://github.com/CopilotC-Nvim/CopilotChat.nvim/issues/1095)) ([81754ea](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/81754ea35253c48459db5712ae60531ea2c5ef75))
23+
* handle invalid context window size in GitHub models ([#1094](https://github.com/CopilotC-Nvim/CopilotChat.nvim/issues/1094)) ([00bf27e](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/00bf27ed201b9509105afaac4d5bdcc46ce89f35))
24+
325
## [1.9.0](https://github.com/CopilotC-Nvim/CopilotChat.nvim/compare/v1.8.0...v1.9.0) (2024-02-24)
426

527

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ CopilotChat.nvim is a Neovim plugin that brings GitHub Copilot Chat capabilities
2020

2121
- 🤖 GitHub Copilot Chat integration with official model and agent support (GPT-4o, Claude 3.7 Sonnet, Gemini 2.0 Flash, and more)
2222
- 💻 Rich workspace context powered by smart embeddings system
23-
- 🔒 Explicit context sharing - only sends what you specifically request, either as context or selection
23+
- 🔒 Explicit context sharing - only sends what you specifically request, either as context or selection (by default visual selection)
2424
- 🔌 Modular provider architecture supporting both official and custom LLM backends (Ollama, LM Studio, Mistral.ai and more)
2525
- 📝 Interactive chat UI with completion, diffs and quickfix integration
2626
- 🎯 Powerful prompt system with composable templates and sticky prompts
@@ -387,7 +387,7 @@ You can set a default selection in the configuration:
387387

388388
```lua
389389
{
390-
-- Default uses visual selection or falls back to buffer
390+
-- Uses visual selection or falls back to buffer
391391
selection = function(source)
392392
return select.visual(source) or select.buffer(source)
393393
end
@@ -466,13 +466,11 @@ Below are all available configuration options with their default values:
466466

467467
-- default selection
468468
-- see select.lua for implementation
469-
selection = function(source)
470-
return select.visual(source) or select.buffer(source)
471-
end,
469+
selection = select.visual,
472470

473471
-- default window options
474472
window = {
475-
layout = 'vertical', -- 'vertical', 'horizontal', 'float', 'replace'
473+
layout = 'vertical', -- 'vertical', 'horizontal', 'float', 'replace', or a function that returns the layout
476474
width = 0.5, -- fractional width of parent, or absolute width in columns when > 1
477475
height = 0.5, -- fractional height of parent, or absolute height in rows when > 1
478476
-- Options below only apply to floating windows
@@ -883,6 +881,8 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
883881
<td align="center" valign="top" width="14.28%"><a href="https://github.com/ThisIsMani"><img src="https://avatars.githubusercontent.com/u/84711804?v=4?s=100" width="100px;" alt="Mani Chandra"/><br /><sub><b>Mani Chandra</b></sub></a><br /><a href="https://github.com/CopilotC-Nvim/CopilotChat.nvim/commits?author=ThisIsMani" title="Code">💻</a></td>
884882
<td align="center" valign="top" width="14.28%"><a href="https://nischalbasuti.github.io/"><img src="https://avatars.githubusercontent.com/u/14853910?v=4?s=100" width="100px;" alt="Nischal Basuti"/><br /><sub><b>Nischal Basuti</b></sub></a><br /><a href="https://github.com/CopilotC-Nvim/CopilotChat.nvim/commits?author=nischalbasuti" title="Documentation">📖</a></td>
885883
<td align="center" valign="top" width="14.28%"><a href="https://teoljungberg.com"><img src="https://avatars.githubusercontent.com/u/810650?v=4?s=100" width="100px;" alt="Teo Ljungberg"/><br /><sub><b>Teo Ljungberg</b></sub></a><br /><a href="https://github.com/CopilotC-Nvim/CopilotChat.nvim/commits?author=teoljungberg" title="Code">💻</a></td>
884+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/JPricey"><img src="https://avatars.githubusercontent.com/u/4826348?v=4?s=100" width="100px;" alt="Joe Price"/><br /><sub><b>Joe Price</b></sub></a><br /><a href="https://github.com/CopilotC-Nvim/CopilotChat.nvim/commits?author=JPricey" title="Code">💻</a></td>
885+
<td align="center" valign="top" width="14.28%"><a href="https://ouuan.moe/about"><img src="https://avatars.githubusercontent.com/u/30581822?v=4?s=100" width="100px;" alt="Yufan You"/><br /><sub><b>Yufan You</b></sub></a><br /><a href="https://github.com/CopilotC-Nvim/CopilotChat.nvim/commits?author=ouuan" title="Documentation">📖</a> <a href="https://github.com/CopilotC-Nvim/CopilotChat.nvim/commits?author=ouuan" title="Code">💻</a></td>
886886
</tr>
887887
</tbody>
888888
</table>

doc/CopilotChat.txt

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*CopilotChat.txt* For NVIM v0.8.0 Last change: 2025 March 26
1+
*CopilotChat.txt* For NVIM v0.8.0 Last change: 2025 April 09
22

33
==============================================================================
44
Table of Contents *CopilotChat-table-of-contents*
@@ -38,7 +38,7 @@ capabilities directly into your editor. It provides:
3838

3939
- 🤖 GitHub Copilot Chat integration with official model and agent support (GPT-4o, Claude 3.7 Sonnet, Gemini 2.0 Flash, and more)
4040
- 💻 Rich workspace context powered by smart embeddings system
41-
- 🔒 Explicit context sharing - only sends what you specifically request, either as context or selection
41+
- 🔒 Explicit context sharing - only sends what you specifically request, either as context or selection (by default visual selection)
4242
- 🔌 Modular provider architecture supporting both official and custom LLM backends (Ollama, LM Studio, Mistral.ai and more)
4343
- 📝 Interactive chat UI with completion, diffs and quickfix integration
4444
- 🎯 Powerful prompt system with composable templates and sticky prompts
@@ -437,7 +437,7 @@ You can set a default selection in the configuration:
437437

438438
>lua
439439
{
440-
-- Default uses visual selection or falls back to buffer
440+
-- Uses visual selection or falls back to buffer
441441
selection = function(source)
442442
return select.visual(source) or select.buffer(source)
443443
end
@@ -525,13 +525,11 @@ Below are all available configuration options with their default values:
525525

526526
-- default selection
527527
-- see select.lua for implementation
528-
selection = function(source)
529-
return select.visual(source) or select.buffer(source)
530-
end,
528+
selection = select.visual,
531529

532530
-- default window options
533531
window = {
534-
layout = 'vertical', -- 'vertical', 'horizontal', 'float', 'replace'
532+
layout = 'vertical', -- 'vertical', 'horizontal', 'float', 'replace', or a function that returns the layout
535533
width = 0.5, -- fractional width of parent, or absolute width in columns when > 1
536534
height = 0.5, -- fractional height of parent, or absolute height in rows when > 1
537535
-- Options below only apply to floating windows
@@ -884,7 +882,7 @@ See CONTRIBUTING.md </CONTRIBUTING.md> for detailed guidelines.
884882
Thanks goes to these wonderful people (emoji key
885883
<https://allcontributors.org/docs/en/emoji-key>):
886884

887-
gptlang💻 📖Dung Duc Huynh (Kaka)💻 📖Ahmed Haracic💻Trí Thiện Nguyễn💻He Zhizhou💻Guruprakash Rajakkannu💻kristofka💻PostCyberPunk📖Katsuhiko Nishimra💻Erno Hopearuoho💻Shaun Garwood💻neutrinoA4💻 📖Jack Muratore💻Adriel Velazquez💻 📖Tomas Slusny💻 📖Nisal📖Tobias Gårdhus📖Petr Dlouhý📖Dylan Madisetti💻Aaron Weisberg💻 📖Jose Tlacuilo💻 📖Kevin Traver💻 📖dTry💻Arata Furukawa💻Ling💻Ivan Frolov💻Folke Lemaitre💻 📖GitMurf💻Dmitrii Lipin💻jinzhongjia📖guill💻Sjon-Paul Brown💻Renzo Mondragón💻 📖fjchen7💻Radosław Woźniak💻JakubPecenka💻thomastthai📖Tomáš Janoušek💻Toddneal Stallworth📖Sergey Alexandrov💻Léopold Mebazaa💻JunKi Jin💻abdennourzahaf📖Josiah💻Tony Fischer💻 📖Kohei Wada💻Sebastian Yaghoubi📖johncming💻Rokas Brazdžionis💻Sola📖 💻Mani Chandra💻Nischal Basuti📖Teo Ljungberg💻This project follows the all-contributors
885+
gptlang💻 📖Dung Duc Huynh (Kaka)💻 📖Ahmed Haracic💻Trí Thiện Nguyễn💻He Zhizhou💻Guruprakash Rajakkannu💻kristofka💻PostCyberPunk📖Katsuhiko Nishimra💻Erno Hopearuoho💻Shaun Garwood💻neutrinoA4💻 📖Jack Muratore💻Adriel Velazquez💻 📖Tomas Slusny💻 📖Nisal📖Tobias Gårdhus📖Petr Dlouhý📖Dylan Madisetti💻Aaron Weisberg💻 📖Jose Tlacuilo💻 📖Kevin Traver💻 📖dTry💻Arata Furukawa💻Ling💻Ivan Frolov💻Folke Lemaitre💻 📖GitMurf💻Dmitrii Lipin💻jinzhongjia📖guill💻Sjon-Paul Brown💻Renzo Mondragón💻 📖fjchen7💻Radosław Woźniak💻JakubPecenka💻thomastthai📖Tomáš Janoušek💻Toddneal Stallworth📖Sergey Alexandrov💻Léopold Mebazaa💻JunKi Jin💻abdennourzahaf📖Josiah💻Tony Fischer💻 📖Kohei Wada💻Sebastian Yaghoubi📖johncming💻Rokas Brazdžionis💻Sola📖 💻Mani Chandra💻Nischal Basuti📖Teo Ljungberg💻Joe Price💻Yufan You📖 💻This project follows the all-contributors
888886
<https://github.com/all-contributors/all-contributors> specification.
889887
Contributions of any kind are welcome!
890888

lua/CopilotChat/client.lua

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -709,9 +709,6 @@ function Client:ask(prompt, opts)
709709
end
710710

711711
local response_text = response_buffer:tostring()
712-
log.trace('Response text:\n', response_text)
713-
log.debug('Response message:\n', vim.inspect(last_message))
714-
715712
if errored then
716713
error(response_text)
717714
return
@@ -727,6 +724,7 @@ function Client:ask(prompt, opts)
727724
else
728725
parse_line(response.body)
729726
end
727+
response_text = response_buffer:tostring()
730728
end
731729

732730
if utils.empty(response_text) then

lua/CopilotChat/config.lua

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
local select = require('CopilotChat.select')
22

3+
---@alias CopilotChat.config.Layout 'vertical'|'horizontal'|'float'|'replace'
4+
35
---@class CopilotChat.config.window
4-
---@field layout 'vertical'|'horizontal'|'float'|'replace'?
6+
---@field layout? CopilotChat.config.Layout|fun():CopilotChat.config.Layout
57
---@field relative 'editor'|'win'|'cursor'|'mouse'?
68
---@field border 'none'|'single'|'double'|'rounded'|'solid'|'shadow'?
79
---@field width number?
@@ -23,6 +25,7 @@ local select = require('CopilotChat.select')
2325
---@field stream nil|fun(chunk: string, source: CopilotChat.source):string
2426
---@field callback nil|fun(response: string, source: CopilotChat.source):string
2527
---@field remember_as_sticky boolean?
28+
---@field include_contexts_in_prompt boolean?
2629
---@field selection false|nil|fun(source: CopilotChat.source):CopilotChat.select.selection?
2730
---@field window CopilotChat.config.window?
2831
---@field show_help boolean?
@@ -58,7 +61,7 @@ return {
5861

5962
system_prompt = 'COPILOT_INSTRUCTIONS', -- System prompt to use (can be specified manually in prompt via /).
6063

61-
model = 'gpt-4o-2024-11-20', -- Default model to use, see ':CopilotChatModels' for available models (can be specified manually in prompt via $).
64+
model = 'gpt-4o', -- Default model to use, see ':CopilotChatModels' for available models (can be specified manually in prompt via $).
6265
agent = 'none', -- Default agent to use, see ':CopilotChatAgents' for available agents (can be specified manually in prompt via @).
6366
context = nil, -- Default context or array of contexts to use (can be specified manually in prompt via #).
6467
sticky = nil, -- Default sticky prompt or array of sticky prompts to use at start of every new chat.
@@ -69,14 +72,14 @@ return {
6972
callback = nil, -- Function called when full response is received (retuned string is stored to history)
7073
remember_as_sticky = true, -- Remember model/agent/context as sticky prompts when asking questions
7174

75+
include_contexts_in_prompt = true, -- Include contexts in prompt
76+
7277
-- default selection
73-
selection = function(source)
74-
return select.visual(source) or select.buffer(source)
75-
end,
78+
selection = select.visual,
7679

7780
-- default window options
7881
window = {
79-
layout = 'vertical', -- 'vertical', 'horizontal', 'float', 'replace'
82+
layout = 'vertical', -- 'vertical', 'horizontal', 'float', 'replace', or a function that returns the layout
8083
width = 0.5, -- fractional width of parent, or absolute width in columns when > 1
8184
height = 0.5, -- fractional height of parent, or absolute height in rows when > 1
8285
-- Options below only apply to floating windows

lua/CopilotChat/config/mappings.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ local function get_diff(block)
6464
change = block.content,
6565
reference = reference or '',
6666
filetype = filetype or '',
67-
filename = filename,
67+
filename = utils.filename(filename),
6868
start_line = start_line,
6969
end_line = end_line,
7070
bufnr = bufnr,
@@ -240,7 +240,6 @@ return {
240240

241241
local lines = vim.split(diff.change, '\n', { trimempty = false })
242242
vim.api.nvim_buf_set_lines(diff.bufnr, diff.start_line - 1, diff.end_line, false, lines)
243-
244243
copilot.set_selection(diff.bufnr, diff.start_line, diff.start_line + #lines - 1)
245244
end,
246245
},

lua/CopilotChat/config/providers.lua

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,12 +332,20 @@ M.github_models = {
332332
return vim.tbl_contains(model.inferenceTasks, 'chat-completion')
333333
end)
334334
:map(function(model)
335+
local context_window = model.modelLimits.textLimits.inputContextWindow
336+
local max_output_tokens = model.modelLimits.textLimits.maxOutputTokens
337+
local max_input_tokens = context_window - max_output_tokens
338+
if max_input_tokens <= 0 then
339+
max_output_tokens = 4096
340+
max_input_tokens = context_window - max_output_tokens
341+
end
342+
335343
return {
336344
id = model.name,
337345
name = model.displayName,
338346
tokenizer = 'o200k_base',
339-
max_input_tokens = model.modelLimits.textLimits.inputContextWindow,
340-
max_output_tokens = model.modelLimits.textLimits.maxOutputTokens,
347+
max_input_tokens = max_input_tokens,
348+
max_output_tokens = max_output_tokens,
341349
}
342350
end)
343351
:totable()

lua/CopilotChat/init.lua

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -850,9 +850,11 @@ function M.ask(prompt, config)
850850

851851
-- Resolve context name and description
852852
local contexts = {}
853-
for name, context in pairs(M.config.contexts) do
854-
if context.description then
855-
contexts[name] = context.description
853+
if config.include_contexts_in_prompt then
854+
for name, context in pairs(M.config.contexts) do
855+
if context.description then
856+
contexts[name] = context.description
857+
end
856858
end
857859
end
858860

lua/CopilotChat/ui/chat.lua

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ end
5555
---@class CopilotChat.ui.Chat : CopilotChat.ui.Overlay
5656
---@field winnr number?
5757
---@field config CopilotChat.config.shared
58+
---@field layout CopilotChat.config.Layout?
5859
---@field sections table<CopilotChat.ui.Chat.Section>
5960
---@field references table<CopilotChat.Provider.reference>
6061
---@field token_count number?
@@ -71,6 +72,7 @@ local Chat = class(function(self, question_header, answer_header, separator, hel
7172
self.winnr = nil
7273
self.sections = {}
7374
self.config = {}
75+
self.layout = nil
7476
self.references = {}
7577
self.token_count = nil
7678
self.token_max_count = nil
@@ -268,15 +270,21 @@ function Chat:open(config)
268270
self:validate()
269271

270272
local window = config.window or {}
273+
271274
local layout = window.layout
275+
if type(layout) == 'function' then
276+
layout = layout()
277+
end
278+
272279
local width = window.width > 1 and window.width or math.floor(vim.o.columns * window.width)
273280
local height = window.height > 1 and window.height or math.floor(vim.o.lines * window.height)
274281

275-
if self.config and self.config.window and self.config.window.layout ~= layout then
282+
if self.layout ~= layout then
276283
self:close()
277284
end
278285

279286
self.config = config
287+
self.layout = layout
280288

281289
if self:visible() then
282290
return
@@ -357,7 +365,7 @@ function Chat:close(bufnr)
357365
utils.return_to_normal_mode()
358366
end
359367

360-
if self.config.window and self.config.window.layout == 'replace' then
368+
if self.layout == 'replace' then
361369
if bufnr then
362370
self:restore(self.winnr, bufnr)
363371
end

0 commit comments

Comments
 (0)