Skip to content

Commit 1929831

Browse files
committed
fix: improve references display in chat UI
The references section in the chat UI has been improved by moving it above the help section and displaying it with proper highlighting using virtual lines. This change also fixes a diagnostic warning in the sticky prompt handling code. Changes: - Move references section above help section - Use virtual lines with highlighting for references display - Add diagnostic disable comment for param-type-mismatch warning Signed-off-by: Tomas Slusny <[email protected]>
1 parent 18fb0de commit 1929831

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

lua/CopilotChat/init.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ local function finish(start_of_chat)
7777
local last_prompt = state.last_prompt or ''
7878

7979
if type(M.config.sticky) == 'table' then
80+
---@diagnostic disable-next-line: param-type-mismatch
8081
for _, sticky in ipairs(M.config.sticky) do
8182
last_prompt = last_prompt .. '\n> ' .. sticky
8283
end

lua/CopilotChat/ui/chat.lua

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,17 +252,23 @@ function Chat:render()
252252
msg = msg .. self.token_count .. '/' .. self.token_max_count .. ' tokens used'
253253
end
254254

255+
self:show_help(msg, last_section.start_line - last_section.end_line - 1)
256+
255257
if self.references and #self.references > 0 then
256-
if msg ~= '' then
257-
msg = msg .. '\n'
258-
end
259-
msg = msg .. '\nReferences:\n'
258+
msg = 'References:\n'
260259
for _, ref in ipairs(self.references) do
261260
msg = msg .. ' ' .. ref.name .. '\n'
262261
end
263-
end
264262

265-
self:show_help(msg, last_section.start_line - last_section.end_line - 1)
263+
vim.api.nvim_buf_set_extmark(self.bufnr, self.header_ns, last_section.start_line - 2, 0, {
264+
hl_mode = 'combine',
265+
priority = 100,
266+
virt_lines_above = true,
267+
virt_lines = vim.tbl_map(function(t)
268+
return { { t, 'CopilotChatHelp' } }
269+
end, vim.split(msg, '\n')),
270+
})
271+
end
266272
else
267273
self:clear_help()
268274
end

0 commit comments

Comments
 (0)