From 4bb57a4b26b9d08770403f6613a227e852d51393 Mon Sep 17 00:00:00 2001 From: Tomas Slusny Date: Wed, 20 Nov 2024 12:44:21 +0100 Subject: [PATCH] refactor(prompts): improve diagnostics handling system Streamline the way diagnostics are handled in prompts by: - Move diagnostics check from general prompt into explain prompt - Split explain prompt into multiple lines for better readability - Update documentation and config to reflect these changes This creates a more focused approach where diagnostics are examined as part of code explanation rather than being a separate concern. --- README.md | 4 ++-- lua/CopilotChat/config.lua | 2 +- lua/CopilotChat/prompts.lua | 7 +++++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index ce109fdb..48a7a0e9 100644 --- a/README.md +++ b/README.md @@ -173,7 +173,7 @@ For example, to change the submit prompt mapping: You can ask Copilot to do various tasks with prompts. You can reference prompts with `/PromptName` in chat or call with command `:CopilotChat`. Default prompts are: -- `Explain` - Write an explanation for the selected code and diagnostics as paragraphs of text +- `Explain` - Write an explanation for the selected code as paragraphs of text - `Review` - Review the selected code - `Fix` - There is a problem in this code. Rewrite the code to show it with the bug fixed - `Optimize` - Optimize the selected code to improve performance and readability @@ -478,7 +478,7 @@ Also see [here](/lua/CopilotChat/config.lua): -- default prompts prompts = { Explain = { - prompt = '> /COPILOT_EXPLAIN\n\nWrite an explanation for the selected code and diagnostics as paragraphs of text.', + prompt = '> /COPILOT_EXPLAIN\n\nWrite an explanation for the selected code as paragraphs of text.', }, Review = { prompt = '> /COPILOT_REVIEW\n\nReview the selected code.', diff --git a/lua/CopilotChat/config.lua b/lua/CopilotChat/config.lua index 581258fb..835c9705 100644 --- a/lua/CopilotChat/config.lua +++ b/lua/CopilotChat/config.lua @@ -232,7 +232,7 @@ return { -- default prompts prompts = { Explain = { - prompt = '> /COPILOT_EXPLAIN\n\nWrite an explanation for the selected code and diagnostics as paragraphs of text.', + prompt = '> /COPILOT_EXPLAIN\n\nWrite an explanation for the selected code as paragraphs of text.', }, Review = { prompt = '> /COPILOT_REVIEW\n\nReview the selected code.', diff --git a/lua/CopilotChat/prompts.lua b/lua/CopilotChat/prompts.lua index 088371e0..7a7a0cb8 100644 --- a/lua/CopilotChat/prompts.lua +++ b/lua/CopilotChat/prompts.lua @@ -21,7 +21,10 @@ You are an AI programming assistant. ]] .. base M.COPILOT_EXPLAIN = [[ -You are a world-class coding tutor. Your code explanations perfectly balance high-level concepts and granular details. Your approach ensures that students not only understand how to write code, but also grasp the underlying principles that guide effective programming. +You are a world-class coding tutor. +Your code explanations perfectly balance high-level concepts and granular details. +Your approach ensures that students not only understand how to write code, but also grasp the underlying principles that guide effective programming. +When examining code pay close attention to diagnostics as well. When explaining diagnostics, include diagnostic content in your response. ]] .. base M.COPILOT_REVIEW = M.COPILOT_INSTRUCTIONS @@ -82,7 +85,7 @@ Your task is to modify the provided code according to the user's request. Follow 9. Directly above every returned code snippet, add `[file:]() line:-`. Example: `[file:copilot.lua](nvim/.config/nvim/lua/config/copilot.lua) line:1-98`. This is markdown link syntax, so make sure to follow it. -10. When examining code pay close attention to diagnostics. When fixing diagnostics, add the diagnostic message as a comment next to the line where the fix was applied. +10. When fixing code pay close attention to diagnostics as well. When fixing diagnostics, include diagnostic content in your response. Remember that Your response SHOULD CONTAIN ONLY THE MODIFIED CODE to be used as DIRECT REPLACEMENT to the original file. ]]