Skip to content

Commit ec678b0

Browse files
committed
Add option to disable header highlighting
Good with plugins like render-markdown.nvim Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
1 parent f0edb56 commit ec678b0

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ Also see [here](/lua/CopilotChat/config.lua):
241241
answer_header = '## Copilot ', -- Header to use for AI answers
242242
error_header = '## Error ', -- Header to use for errors
243243
separator = '───', -- Separator to use in chat
244+
highlight_headers = true, -- Highlight headers in chat, disable if using markdown renderers (like render-markdown.nvim)
244245

245246
show_folds = true, -- Shows folds for sections in chat
246247
show_help = true, -- Shows help message as virtual lines when waiting for user input
@@ -546,9 +547,16 @@ require('CopilotChat').setup({
546547
Requires [render-markdown](https://github.com/MeanderingProgrammer/render-markdown.nvim) plugin to be installed.
547548

548549
```lua
550+
-- Registers copilot-chat filetype for markdown rendering
549551
require('render-markdown').setup({
550552
file_types = { 'markdown', 'copilot-chat' },
551553
})
554+
555+
-- You might also want to disable default header highlighting for copilot chat when doing this
556+
require('CopilotChat').setup({
557+
highlight_headers = false,
558+
-- rest of your config
559+
})
552560
```
553561

554562
![image](https://github.com/user-attachments/assets/d8dc16f8-3f61-43fa-bfb9-83f240ae30e8)

lua/CopilotChat/chat.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ local Chat = class(function(self, help, auto_insert, on_buf_create)
4040
self.spinner = nil
4141
self.separator = nil
4242
self.auto_follow_cursor = true
43+
self.highlight_headers = true
4344
self.layout = nil
4445

4546
vim.treesitter.language.register('markdown', 'copilot-chat')
@@ -72,9 +73,10 @@ function Chat:visible()
7273
end
7374

7475
function Chat:render()
75-
if not self:visible() then
76+
if not self.highlight_headers or not self:visible() then
7677
return
7778
end
79+
7880
vim.api.nvim_buf_clear_namespace(self.bufnr, self.header_ns, 0, -1)
7981
local lines = vim.api.nvim_buf_get_lines(self.bufnr, 0, -1, false)
8082
for l, line in ipairs(lines) do
@@ -219,6 +221,7 @@ function Chat:open(config)
219221
self.layout = layout
220222
self.separator = config.separator
221223
self.auto_follow_cursor = config.auto_follow_cursor
224+
self.highlight_headers = config.highlight_headers
222225

223226
vim.wo[self.winnr].wrap = true
224227
vim.wo[self.winnr].linebreak = true

lua/CopilotChat/config.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ return {
104104
answer_header = '## Copilot ', -- Header to use for AI answers
105105
error_header = '## Error ', -- Header to use for errors
106106
separator = '───', -- Separator to use in chat
107+
highlight_headers = true, -- Highlight headers in chat, disable if using markdown renderers (like render-markdown.nvim)
107108

108109
show_folds = true, -- Shows folds for sections in chat
109110
show_help = true, -- Shows help message as virtual lines when waiting for user input

0 commit comments

Comments
 (0)