Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,13 @@ Types of copilot highlights:
- `CopilotChatHeader` - Header highlight in chat buffer
- `CopilotChatSeparator` - Separator highlight in chat buffer
- `CopilotChatStatus` - Status and spinner in chat buffer
- `CopilotChatHelp` - Help messages in chat buffer (help, references)
- `CopilotChatHelp` - Help text in chat buffer
- `CopilotChatResource` - Resource highlight in chat buffer (e.g. `#file`, `#gitdiff`)
- `CopilotChatTool` - Tool call highlight in chat buffer (e.g. `@copilot`)
- `CopilotChatPrompt` - Prompt highlight in chat buffer (e.g. `/Explain`, `/Review`)
- `CopilotChatModel` - Model highlight in chat buffer (e.g. `$gpt-4.1`)
- `CopilotChatUri` - URI highlight in chat buffer (e.g. `##https://...`)
- `CopilotChatSelection` - Selection highlight in source buffer
- `CopilotChatKeyword` - Keyword highlight in chat buffer (e.g. prompts, tools)
- `CopilotChatAnnotation` - Annotation highlight in chat buffer (file headers, tool call headers, tool call body)

## Prompts
Expand Down
19 changes: 3 additions & 16 deletions lua/CopilotChat/ui/chat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,9 @@ function Chat:open(config)
vim.wo[self.winnr].foldcolumn = '0'
end

local ns = vim.api.nvim_create_namespace('copilot-chat-local-hl')
vim.api.nvim_set_hl(ns, '@markup.quote.markdown', {})
vim.api.nvim_win_set_hl_ns(self.winnr, ns)
vim.api.nvim_win_set_buf(self.winnr, self.bufnr)
self:render()
end
Expand Down Expand Up @@ -678,22 +681,6 @@ function Chat:render()
end
end

-- Keywords
if current_message and current_message.role == 'user' then
-- FIXME: This is not optimal, but i cant figure out how to do it better as treesitter keeps overriding it
local patterns = {
'()#?#[^ ]+()',
'()@[^ ]+()',
'()%$[^ ]+()',
'()/[^ ]+()',
}
for _, pattern in ipairs(patterns) do
for s, e in line:gmatch(pattern) do
vim.api.nvim_buf_add_highlight(self.bufnr, highlight_ns, 'CopilotChatKeyword', l - 1, s - 1, e - 1)
end
end
end

-- If last line, finish last message
if l == #lines and current_message then
current_message.section.end_line = l
Expand Down
20 changes: 18 additions & 2 deletions plugin/CopilotChat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ local function setup_highlights()
vim.api.nvim_set_hl(0, 'CopilotChatSeparator', { link = '@punctuation.special.markdown', default = true })
vim.api.nvim_set_hl(0, 'CopilotChatStatus', { link = 'DiagnosticHint', default = true })
vim.api.nvim_set_hl(0, 'CopilotChatHelp', { link = 'DiagnosticInfo', default = true })
vim.api.nvim_set_hl(0, 'CopilotChatKeyword', { link = 'Keyword', default = true })
vim.api.nvim_set_hl(0, 'CopilotChatResource', { link = 'Constant', default = true })
vim.api.nvim_set_hl(0, 'CopilotChatTool', { link = 'Function', default = true })
vim.api.nvim_set_hl(0, 'CopilotChatPrompt', { link = 'Statement', default = true })
vim.api.nvim_set_hl(0, 'CopilotChatModel', { link = 'Type', default = true })
vim.api.nvim_set_hl(0, 'CopilotChatUri', { link = 'Underlined', default = true })
vim.api.nvim_set_hl(0, 'CopilotChatSelection', { link = 'Visual', default = true })
vim.api.nvim_set_hl(0, 'CopilotChatAnnotation', { link = 'ColorColumn', default = true })

vim.api.nvim_set_hl(0, 'CopilotChatAnnotation', { link = 'ColorColumn', default = true })
local fg = vim.api.nvim_get_hl(0, { name = 'CopilotChatStatus', link = false }).fg
local bg = vim.api.nvim_get_hl(0, { name = 'CopilotChatAnnotation', link = false }).bg
vim.api.nvim_set_hl(0, 'CopilotChatAnnotationHeader', { fg = fg, bg = bg })
Expand Down Expand Up @@ -75,6 +79,18 @@ vim.api.nvim_create_user_command('CopilotChatReset', function()
chat.reset()
end, { force = true })

vim.api.nvim_create_autocmd('FileType', {
pattern = 'copilot-chat',
group = group,
callback = vim.schedule_wrap(function()
vim.cmd.syntax('match CopilotChatResource "#\\S\\+"')
vim.cmd.syntax('match CopilotChatTool "@\\S\\+"')
vim.cmd.syntax('match CopilotChatPrompt "/\\S\\+"')
vim.cmd.syntax('match CopilotChatModel "\\$\\S\\+"')
vim.cmd.syntax('match CopilotChatUri "##\\S\\+"')
end),
})

local function complete_load()
local chat = require('CopilotChat')
local options = vim.tbl_map(function(file)
Expand Down
Loading