Skip to content

Commit 2ee3b8c

Browse files
committed
draft POC of suppress findings
1 parent c9dd554 commit 2ee3b8c

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/codescan/listeners/CodeWhispererCodeScanEditorMouseMotionListener.kt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,16 @@ class CodeWhispererCodeScanEditorMouseMotionListener(private val project: Projec
258258
handleApplyFix(issue)
259259
button.isVisible = false
260260
}
261+
262+
val buttonSuppressFinding = JButton("Suppress Finding").apply {
263+
toolTipText = "Suppress Finding"
264+
putClientProperty(DarculaButtonUI.DEFAULT_STYLE_KEY, true)
265+
}
266+
buttonSuppressFinding.addActionListener {
267+
handleSupressFinding(issue)
268+
buttonSuppressFinding.isVisible = false
269+
}
270+
261271
val nextButton = JButton(AllIcons.Actions.ArrowExpand).apply {
262272
preferredSize = Dimension(30, this.height)
263273
addActionListener {
@@ -288,6 +298,8 @@ class CodeWhispererCodeScanEditorMouseMotionListener(private val project: Projec
288298
if (issue.suggestedFixes.isNotEmpty()) {
289299
add(button)
290300
}
301+
302+
add(buttonSuppressFinding)
291303
}
292304

293305
val containerPane = JPanel().apply {
@@ -389,6 +401,26 @@ class CodeWhispererCodeScanEditorMouseMotionListener(private val project: Projec
389401
private val LOG = getLogger<CodeWhispererCodeScanEditorMouseMotionListener>()
390402
}
391403

404+
private fun handleSupressFinding(issue: CodeWhispererCodeScanIssue) {
405+
try{
406+
WriteCommandAction.runWriteCommandAction(issue.project) {
407+
val document = FileDocumentManager.getInstance().getDocument(issue.file) ?: return@runWriteCommandAction
408+
409+
val documentContent = document.text
410+
411+
document.insertString(document.getLineStartOffset(issue.startLine - 1),"## AmazonQ: Suppress This Finding\n")
412+
PsiDocumentManager.getInstance(issue.project).commitDocument(document)
413+
hidePopup()
414+
if (CodeWhispererExplorerActionManager.getInstance().isAutoEnabledForCodeScan()) {
415+
CodeWhispererCodeScanManager.getInstance(issue.project).removeIssueByFindingId(issue.file, issue.findingId)
416+
}
417+
}
418+
// TODO: Add telemetry for Suppress Finding
419+
} catch (err: Error) {
420+
LOG.error { "Suppress Finding command failed. $err" }
421+
}
422+
}
423+
392424
private fun handleApplyFix(issue: CodeWhispererCodeScanIssue) {
393425
try {
394426
WriteCommandAction.runWriteCommandAction(issue.project) {

0 commit comments

Comments
 (0)