Skip to content

Add option to disable header highlighting #502

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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