Reproducer:
nvim x.md
- add two lines:
- go to the "x" line and comment it using the gc mapping
- observe that "/b" is suddenly highlighted as CopilotChatPrompt despite this being a normal markdown buffer
Cause:
|
vim.treesitter.language.register('markdown', 'copilot-chat') |
|
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), |
|
}) |
https://github.com/neovim/neovim/blob/release-0.12/runtime/lua/vim/_comment.lua#L47-L49
vim.filetype.get_option triggers FileType autocommands the first time it's called for a given filetype, so the first markdown buffer where gc is used will have syntax rules for copilot-chat unfortunately.
One might argue that this is a neovim bug actually - using all filetypes associated with markdown, even if we know the exact filetype in that buffer, seems quite stupid. I'm not sure what the right way to fix this is, yet.
Reproducer:
nvim x.mdCause:
CopilotChat.nvim/plugin/CopilotChat.lua
Line 127 in 2025f92
CopilotChat.nvim/plugin/CopilotChat.lua
Lines 39 to 49 in 2025f92
https://github.com/neovim/neovim/blob/release-0.12/runtime/lua/vim/_comment.lua#L47-L49
vim.filetype.get_optiontriggers FileType autocommands the first time it's called for a given filetype, so the first markdown buffer where gc is used will have syntax rules for copilot-chat unfortunately.One might argue that this is a neovim bug actually - using all filetypes associated with markdown, even if we know the exact filetype in that buffer, seems quite stupid. I'm not sure what the right way to fix this is, yet.