diff --git a/README.md b/README.md index d70e31a4..c35320a4 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lua/CopilotChat/ui/chat.lua b/lua/CopilotChat/ui/chat.lua index fe70feff..8b22c32e 100644 --- a/lua/CopilotChat/ui/chat.lua +++ b/lua/CopilotChat/ui/chat.lua @@ -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 @@ -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 diff --git a/plugin/CopilotChat.lua b/plugin/CopilotChat.lua index de5e0158..e59ee49e 100644 --- a/plugin/CopilotChat.lua +++ b/plugin/CopilotChat.lua @@ -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 }) @@ -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)