From 9e41a6c3525d8e47d61601e0fd98fcbc091e487a Mon Sep 17 00:00:00 2001 From: Tomas Slusny Date: Thu, 14 Nov 2024 20:50:42 +0100 Subject: [PATCH] Automatically clear copilot diagnostics on asking new question Closes #362 Signed-off-by: Tomas Slusny --- lua/CopilotChat/config.lua | 7 +++++-- lua/CopilotChat/init.lua | 2 ++ lua/CopilotChat/prompts.lua | 2 ++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lua/CopilotChat/config.lua b/lua/CopilotChat/config.lua index a6e1ac02..e8993d9e 100644 --- a/lua/CopilotChat/config.lua +++ b/lua/CopilotChat/config.lua @@ -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 @@ -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 = { diff --git a/lua/CopilotChat/init.lua b/lua/CopilotChat/init.lua index b5397899..4e1a1151 100644 --- a/lua/CopilotChat/init.lua +++ b/lua/CopilotChat/init.lua @@ -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 diff --git a/lua/CopilotChat/prompts.lua b/lua/CopilotChat/prompts.lua index d18a4ada..e12b0ff1 100644 --- a/lua/CopilotChat/prompts.lua +++ b/lua/CopilotChat/prompts.lua @@ -90,6 +90,8 @@ line=-: 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.