Skip to content

Commit

Permalink
Add option to disable header highlighting
Browse files Browse the repository at this point in the history
Good with plugins like render-markdown.nvim

Signed-off-by: Tomas Slusny <[email protected]>
  • Loading branch information
deathbeam committed Nov 17, 2024
1 parent f0edb56 commit ec678b0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ Also see [here](/lua/CopilotChat/config.lua):
answer_header = '## Copilot ', -- Header to use for AI answers
error_header = '## Error ', -- Header to use for errors
separator = '───', -- Separator to use in chat
highlight_headers = true, -- Highlight headers in chat, disable if using markdown renderers (like render-markdown.nvim)

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

```lua
-- Registers copilot-chat filetype for markdown rendering
require('render-markdown').setup({
file_types = { 'markdown', 'copilot-chat' },
})

-- You might also want to disable default header highlighting for copilot chat when doing this
require('CopilotChat').setup({
highlight_headers = false,
-- rest of your config
})
```

![image](https://github.com/user-attachments/assets/d8dc16f8-3f61-43fa-bfb9-83f240ae30e8)
Expand Down
5 changes: 4 additions & 1 deletion lua/CopilotChat/chat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ local Chat = class(function(self, help, auto_insert, on_buf_create)
self.spinner = nil
self.separator = nil
self.auto_follow_cursor = true
self.highlight_headers = true
self.layout = nil

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

function Chat:render()
if not self:visible() then
if not self.highlight_headers or not self:visible() then
return
end

vim.api.nvim_buf_clear_namespace(self.bufnr, self.header_ns, 0, -1)
local lines = vim.api.nvim_buf_get_lines(self.bufnr, 0, -1, false)
for l, line in ipairs(lines) do
Expand Down Expand Up @@ -219,6 +221,7 @@ function Chat:open(config)
self.layout = layout
self.separator = config.separator
self.auto_follow_cursor = config.auto_follow_cursor
self.highlight_headers = config.highlight_headers

vim.wo[self.winnr].wrap = true
vim.wo[self.winnr].linebreak = true
Expand Down
1 change: 1 addition & 0 deletions lua/CopilotChat/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ return {
answer_header = '## Copilot ', -- Header to use for AI answers
error_header = '## Error ', -- Header to use for errors
separator = '───', -- Separator to use in chat
highlight_headers = true, -- Highlight headers in chat, disable if using markdown renderers (like render-markdown.nvim)

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

0 comments on commit ec678b0

Please sign in to comment.