Skip to content

Commit

Permalink
Automatically clear copilot diagnostics on asking new question
Browse files Browse the repository at this point in the history
Closes #362

Signed-off-by: Tomas Slusny <[email protected]>
  • Loading branch information
deathbeam committed Nov 14, 2024
1 parent e2fa814 commit 9e41a6c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lua/CopilotChat/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ return {
Review = {
prompt = '/COPILOT_REVIEW Review the selected code.',
callback = function(response, source)
local ns = vim.api.nvim_create_namespace('copilot_review')
local diagnostics = {}
for line in response:gmatch('[^\r\n]+') do
if line:find('^line=') then
Expand Down Expand Up @@ -152,7 +151,11 @@ return {
end
end
end
vim.diagnostic.set(ns, source.bufnr, diagnostics)
vim.diagnostic.set(
vim.api.nvim_create_namespace('copilot_diagnostics'),
source.bufnr,
diagnostics
)
end,
},
Fix = {
Expand Down
2 changes: 2 additions & 0 deletions lua/CopilotChat/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,8 @@ function M.ask(prompt, config, source)

M.open(config, source)

vim.diagnostic.reset(vim.api.nvim_create_namespace('copilot_diagnostics'))

if config.clear_chat_on_new_prompt then
M.stop(true, config)
end
Expand Down
2 changes: 2 additions & 0 deletions lua/CopilotChat/prompts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ line=<start_line>-<end_line>: <issue_description>
If you find multiple issues on the same line, list each issue separately within the same feedback statement, using a semicolon to separate them.
At the end of your review, add this: "**`To clear buffer highlights, please ask a different question.`**".
Example feedback:
line=3: The variable name 'x' is unclear. Comment next to variable declaration is unnecessary.
line=8: Expression is overly complex. Break down the expression into simpler components.
Expand Down

0 comments on commit 9e41a6c

Please sign in to comment.