Skip to content

Commit

Permalink
refactor(prompts): improve diagnostics handling system
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
deathbeam committed Nov 20, 2024
1 parent ce98707 commit 4bb57a4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<PromptName>`.
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
Expand Down Expand Up @@ -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.',
Expand Down
2 changes: 1 addition & 1 deletion lua/CopilotChat/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand Down
7 changes: 5 additions & 2 deletions lua/CopilotChat/prompts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:<file_name>](<file_path>) line:<start_line>-<end_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.
]]
Expand Down

0 comments on commit 4bb57a4

Please sign in to comment.