Skip to content

Commit 484e436

Browse files
committed
feat(ui): add option to control references display mode
Add new configuration option `references_display` that allows users to control how references are displayed in chat responses. Two modes are supported: - 'virtual': displays references as virtual text (default) - 'write': writes references directly into the chat buffer as markdown links This gives users more flexibility in how reference information is presented and interacted with in the chat interface.
1 parent 7399e02 commit 484e436

4 files changed

Lines changed: 15 additions & 5 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,7 @@ Below are all available configuration options with their default values:
477477
show_folds = true, -- Shows folds for sections in chat
478478
highlight_selection = true, -- Highlight selection
479479
highlight_headers = true, -- Highlight headers in chat, disable if using markdown renderers (like render-markdown.nvim)
480+
references_display = 'virtual', -- 'virtual', 'write', Display references in chat as virtual text or write to buffer
480481
auto_follow_cursor = true, -- Auto-follow cursor in chat
481482
auto_insert_mode = false, -- Automatically enter insert mode when opening window and on new prompt
482483
insert_at_end = false, -- Move cursor to end of buffer when inserting text

lua/CopilotChat/config.lua

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ local prompts = require('CopilotChat.config.prompts')
22
local select = require('CopilotChat.select')
33

44
---@class CopilotChat.config.window
5-
---@field layout string?
6-
---@field relative string?
7-
---@field border string?
5+
---@field layout 'vertical'|'horizontal'|'float'|'replace'?
6+
---@field relative 'editor'|'win'|'cursor'|'mouse'?
7+
---@field border 'none'|'single'|'double'|'rounded'|'solid'|'shadow'?
88
---@field width number?
99
---@field height number?
1010
---@field row number?
@@ -28,6 +28,7 @@ local select = require('CopilotChat.select')
2828
---@field show_folds boolean?
2929
---@field highlight_selection boolean?
3030
---@field highlight_headers boolean?
31+
---@field references_display 'virtual'|'write'?
3132
---@field auto_follow_cursor boolean?
3233
---@field auto_insert_mode boolean?
3334
---@field insert_at_end boolean?
@@ -36,7 +37,7 @@ local select = require('CopilotChat.select')
3637
--- CopilotChat default configuration
3738
---@class CopilotChat.config : CopilotChat.config.shared
3839
---@field debug boolean?
39-
---@field log_level string?
40+
---@field log_level 'trace'|'debug'|'info'|'warn'|'error'|'fatal'?
4041
---@field proxy string?
4142
---@field allow_insecure boolean?
4243
---@field chat_autocomplete boolean?
@@ -89,6 +90,7 @@ return {
8990
show_folds = true, -- Shows folds for sections in chat
9091
highlight_selection = true, -- Highlight selection
9192
highlight_headers = true, -- Highlight headers in chat, disable if using markdown renderers (like render-markdown.nvim)
93+
references_display = 'virtual', -- 'virtual', 'write', Display references in chat as virtual text or write to buffer
9294
auto_follow_cursor = true, -- Auto-follow cursor in chat
9395
auto_insert_mode = false, -- Automatically enter insert mode when opening window and on new prompt
9496
insert_at_end = false, -- Move cursor to end of buffer when inserting text

lua/CopilotChat/init.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,13 @@ function M.ask(prompt, config)
761761
end
762762

763763
if not config.headless then
764+
if not utils.empty(references) and config.references_display == 'write' then
765+
state.chat:append('\n\n**`References`**:')
766+
for _, ref in ipairs(references) do
767+
state.chat:append(string.format('\n[%s](%s)', ref.name, ref.url))
768+
end
769+
end
770+
764771
finish()
765772
end
766773
if config.callback then

lua/CopilotChat/ui/chat.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ function Chat:render()
252252

253253
self:show_help(msg, last_section.start_line - last_section.end_line - 1)
254254

255-
if not utils.empty(self.references) then
255+
if not utils.empty(self.references) and self.config.references_display == 'virtual' then
256256
msg = 'References:\n'
257257
for _, ref in ipairs(self.references) do
258258
msg = msg .. ' ' .. ref.name .. '\n'

0 commit comments

Comments
 (0)