diff --git a/CHANGELOG.md b/CHANGELOG.md index 12e31352..d3a05ec4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,17 @@ # Changelog +## [4.1.0](https://github.com/CopilotC-Nvim/CopilotChat.nvim/compare/v4.0.0...v4.1.0) (2025-08-03) + + +### Features + +* **ui:** improve keyword highlights accuracy and performance ([#1260](https://github.com/CopilotC-Nvim/CopilotChat.nvim/issues/1260)) ([0d64e26](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/0d64e267a5aef3bd7d580a2c488bcc8b66d374a4)) + + +### Bug Fixes + +* **functions:** do not filter schema enum when entering input ([#1264](https://github.com/CopilotC-Nvim/CopilotChat.nvim/issues/1264)) ([8510f30](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/8510f30ff8c338482e7c8a2a7d102519cc57315f)), closes [#1263](https://github.com/CopilotC-Nvim/CopilotChat.nvim/issues/1263) + ## [4.0.0](https://github.com/CopilotC-Nvim/CopilotChat.nvim/compare/v3.12.2...v4.0.0) (2025-08-02) 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/doc/CopilotChat.txt b/doc/CopilotChat.txt index c23f2808..f49db7f1 100644 --- a/doc/CopilotChat.txt +++ b/doc/CopilotChat.txt @@ -1,4 +1,4 @@ -*CopilotChat.txt* For NVIM v0.8.0 Last change: 2025 August 02 +*CopilotChat.txt* For NVIM v0.8.0 Last change: 2025 August 03 ============================================================================== Table of Contents *CopilotChat-table-of-contents* @@ -325,9 +325,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) diff --git a/lua/CopilotChat/functions.lua b/lua/CopilotChat/functions.lua index 6e936a3d..e63b63a3 100644 --- a/lua/CopilotChat/functions.lua +++ b/lua/CopilotChat/functions.lua @@ -114,15 +114,16 @@ function M.match_uri(uri, pattern) return result end ----@param tool CopilotChat.config.functions.Function -function M.parse_schema(tool) - local schema = tool.schema +--- Parse function schema and return a JSON schema object +---@param fn CopilotChat.config.functions.Function +function M.parse_schema(fn) + local schema = fn.schema -- If schema is missing but uri is present, generate a default schema from uri - if not schema and tool.uri then + if not schema and fn.uri then -- Extract parameter names from the uri pattern, e.g. file://{path} local param_names = {} - for param in tool.uri:gmatch(URI_PARAM_PATTERN) do + for param in fn.uri:gmatch(URI_PARAM_PATTERN) do table.insert(param_names, param) end if #param_names > 0 then @@ -138,26 +139,22 @@ function M.parse_schema(tool) end end - if schema then - schema = filter_schema(schema, true) - end - return schema end ---- Prepare the schema for use ----@param tools table +--- Prepare functions for tool use +---@param functions table ---@return table -function M.parse_tools(tools) - local tool_names = vim.tbl_keys(tools) +function M.parse_tools(functions) + local tool_names = vim.tbl_keys(functions) table.sort(tool_names) return vim.tbl_map(function(name) - local tool = tools[name] + local tool = functions[name] return { name = name, description = tool.description, - schema = M.parse_schema(tool), + schema = filter_schema(M.parse_schema(tool), true), } end, tool_names) end 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) diff --git a/version.txt b/version.txt index fcdb2e10..ee74734a 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -4.0.0 +4.1.0