Skip to content

Commit 242e3e2

Browse files
feat(amazonq): improve explain functionality (#6014)
* feat(amazonq): improve explain functionality * fix(amazonq): fix detekt errors * fix(amazonq): add changelog --------- Co-authored-by: Blake Lazarine <[email protected]>
1 parent 785a39e commit 242e3e2

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type" : "feature",
3+
"description" : "Improve the explain and apply fix messages"
4+
}

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/cwc/commands/codescan/actions/HandleIssueCommandAction.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ class HandleIssueCommandAction : AnAction(), DumbAware {
2424
val contextDataKey = DataKey.create<MutableMap<String, String>>("amazonq.codescan.handleIssueCommandContext")
2525
val actionDataKey = DataKey.create<String>("amazonq.codescan.handleIssueCommandAction")
2626

27+
private val explainContextPrompt = "Provide a small description of the issue. You must not attempt to fix the issue. " +
28+
"You should only give a small summary of it to the user. " +
29+
"You must start with the information stored in the recommendation.text field if it is present."
30+
private val applyFixContextPrompt = "Generate a fix for the following code issue." +
31+
" You must not explain the issue, just generate and explain the fix. " +
32+
"The user should have the option to accept or reject the fix before any code is changed."
33+
2734
override fun getActionUpdateThread() = ActionUpdateThread.BGT
2835

2936
override fun update(e: AnActionEvent) {
@@ -62,11 +69,11 @@ class HandleIssueCommandAction : AnAction(), DumbAware {
6269
// https://github.com/aws/aws-toolkit-vscode/blob/master/packages/amazonq/src/lsp/chat/commands.ts#L30
6370
val codeSelection = "\n```\n${context["code"]?.trimIndent()?.trim()}\n```\n"
6471
val actionString = if (action == "explainIssue") "Explain" else "Fix"
72+
val contextPrompt = if (action == "explainIssue") explainContextPrompt else applyFixContextPrompt
6573

6674
val prompt = "$actionString ${context["title"]} issue in ${context["fileName"]} at ${createLineRangeText(context)}"
6775

68-
val modelPrompt = "$actionString ${context["title"]} issue in ${context["fileName"]} at ${createLineRangeText(context)}" +
69-
"Issue: \"${context}\" \n"
76+
val modelPrompt = "$contextPrompt Issue: \"${context}\" \n"
7077

7178
val params = SendToPromptParams(
7279
selection = codeSelection,

0 commit comments

Comments
 (0)