Skip to content

Commit 494364f

Browse files
committed
feat: improve chat buffer syntax highlighting
Add dedicated highlight group for input contexts and update existing highlight groups to better organize visual elements in the chat buffer. CopilotChatSpinner is now renamed to CopilotChatStatus for better semantics. Syntax matching is improved to handle input contexts with proper containment rules.
1 parent 494d7ea commit 494364f

3 files changed

Lines changed: 14 additions & 7 deletions

File tree

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -619,12 +619,13 @@ vim.api.nvim_create_autocmd('BufEnter', {
619619

620620
Types of copilot highlights:
621621

622-
- `CopilotChatSpinner` - Spinner in chat buffer
622+
- `CopilotChatHeader` - Header highlight in chat buffer
623+
- `CopilotChatSeparator` - Separator highlight in chat buffer
624+
- `CopilotChatStatus` - Status and spinner in chat buffer
623625
- `CopilotChatHelp` - Help messages in chat buffer (help, references)
624626
- `CopilotChatSelection` - Selection highlight in source buffer
625627
- `CopilotChatKeyword` - Keyword highlight in chat buffer (e.g. prompts, contexts)
626-
- `CopilotChatHeader` - Header highlight in chat buffer
627-
- `CopilotChatSeparator` - Separator highlight in chat buffer
628+
- `CopilotChatInput` - Input highlight in chat buffer (for contexts)
628629

629630
# API Reference
630631

lua/CopilotChat/init.lua

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,14 @@ local function update_highlights()
4444
M.complete_items(function(items)
4545
for _, item in ipairs(items) do
4646
local pattern = vim.fn.escape(item.word, '.-$^*[]')
47-
vim.cmd.syntax('match CopilotChatKeyword "' .. pattern .. '"')
47+
if vim.startswith(item.word, '#') then
48+
vim.cmd('syntax match CopilotChatKeyword "' .. pattern .. '\\(:.\\+\\)\\?" containedin=ALL')
49+
else
50+
vim.cmd('syntax match CopilotChatKeyword "' .. pattern .. '" containedin=ALL')
51+
end
4852
end
4953

54+
vim.cmd('syntax match CopilotChatInput ":\\(.\\+\\)" contained containedin=CopilotChatKeyword')
5055
state.highlights_loaded = true
5156
end)
5257
end
@@ -870,10 +875,11 @@ function M.setup(config)
870875
M.log_level(M.config.log_level)
871876
end
872877

873-
vim.api.nvim_set_hl(0, 'CopilotChatSpinner', { link = 'DiagnosticHint', default = true })
878+
vim.api.nvim_set_hl(0, 'CopilotChatStatus', { link = 'DiagnosticHint', default = true })
874879
vim.api.nvim_set_hl(0, 'CopilotChatHelp', { link = 'DiagnosticInfo', default = true })
875-
vim.api.nvim_set_hl(0, 'CopilotChatSelection', { link = 'Visual', default = true })
876880
vim.api.nvim_set_hl(0, 'CopilotChatKeyword', { link = 'Keyword', default = true })
881+
vim.api.nvim_set_hl(0, 'CopilotChatInput', { link = 'Special', default = true })
882+
vim.api.nvim_set_hl(0, 'CopilotChatSelection', { link = 'Visual', default = true })
877883
vim.api.nvim_set_hl(
878884
0,
879885
'CopilotChatHeader',

lua/CopilotChat/ui/spinner.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function Spinner:start()
6363
hl_mode = 'combine',
6464
priority = 100,
6565
virt_text = {
66-
{ frame, 'CopilotChatSpinner' },
66+
{ frame, 'CopilotChatStatus' },
6767
},
6868
}
6969
)

0 commit comments

Comments
 (0)