From a918e83a81b779ac99b60033b08ccd19d6f32535 Mon Sep 17 00:00:00 2001 From: laileni Date: Thu, 30 May 2024 16:40:47 -0700 Subject: [PATCH 1/7] fixing the line number on document change --- .../codescan/CodeWhispererCodeScanManager.kt | 36 ++++++++++++++++--- .../CodeWhispererCodeScanDocumentListener.kt | 10 ++++++ 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codewhisperer/codescan/CodeWhispererCodeScanManager.kt b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codewhisperer/codescan/CodeWhispererCodeScanManager.kt index 0b7a20f2d87..c458e6d7941 100644 --- a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codewhisperer/codescan/CodeWhispererCodeScanManager.kt +++ b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codewhisperer/codescan/CodeWhispererCodeScanManager.kt @@ -387,7 +387,6 @@ class CodeWhispererCodeScanManager(val project: Project) { */ fun addCodeScanUI(setSelected: Boolean = false) = runInEdt { reset() - EditorFactory.getInstance().eventMulticaster.addDocumentListener(documentListener, project) val problemsWindow = getProblemsWindow() if (!problemsWindow.contentManager.contents.contains(codeScanIssuesContent)) { problemsWindow.contentManager.addContent(codeScanIssuesContent) @@ -458,6 +457,33 @@ class CodeWhispererCodeScanManager(val project: Project) { } } + private fun offsetSuggestedFix(suggestedFix: SuggestedFix, lines: Int): SuggestedFix { + val updatedCode = suggestedFix.code.replace( + Regex("""(@@ -)(\d+)(,\d+ \+)(\d+)(,\d+ @@)""") + ) { matchResult -> + val prefix = matchResult.groupValues[1] + val startLine = matchResult.groupValues[2].toInt() + lines + val middle = matchResult.groupValues[3] + val endLine = matchResult.groupValues[4].toInt() + lines + val suffix = matchResult.groupValues[5] + "$prefix$startLine$middle$endLine$suffix" + } + + return suggestedFix.copy(code = updatedCode) + } + + fun updateScanNodesForOffSet(file: VirtualFile, lineOffset: Int, eventOffset: TextRange) { + val document = FileDocumentManager.getInstance().getDocument(file) ?: return + scanNodesLookup[file]?.forEach { node -> + val issue = node.userObject as CodeWhispererCodeScanIssue + if (document.getLineNumber(eventOffset.startOffset) <= issue.startLine) { + issue.startLine = issue.startLine + lineOffset + issue.endLine = issue.endLine + lineOffset + issue.suggestedFixes = issue.suggestedFixes.map { fix -> offsetSuggestedFix(fix, lineOffset) } + } + } + } + private fun CodeWhispererCodeScanIssue.copyRange(newRange: TextRange): CodeWhispererCodeScanIssue { val newStartLine = document.getLineNumber(newRange.startOffset) val newStartCol = newRange.startOffset - document.getLineStartOffset(newStartLine) @@ -498,7 +524,7 @@ class CodeWhispererCodeScanManager(val project: Project) { val editorFactory = EditorFactory.getInstance() editorFactory.eventMulticaster.addDocumentListener(documentListener, project) editorFactory.addEditorFactoryListener(fileListener, project) - EditorFactory.getInstance().eventMulticaster.addEditorMouseMotionListener( + editorFactory.eventMulticaster.addEditorMouseMotionListener( editorMouseListener, codeScanIssuesContent ) @@ -673,9 +699,9 @@ class CodeWhispererCodeScanManager(val project: Project) { data class CodeWhispererCodeScanIssue( val project: Project, val file: VirtualFile, - val startLine: Int, + var startLine: Int, val startCol: Int, - val endLine: Int, + var endLine: Int, val endCol: Int, val title: @InspectionMessage String, val description: Description, @@ -686,7 +712,7 @@ data class CodeWhispererCodeScanIssue( val relatedVulnerabilities: List, val severity: String, val recommendation: Recommendation, - val suggestedFixes: List, + var suggestedFixes: List, val issueSeverity: HighlightDisplayLevel = HighlightDisplayLevel.WARNING, val isInvalid: Boolean = false, var rangeHighlighter: RangeHighlighterEx? = null diff --git a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codewhisperer/codescan/listeners/CodeWhispererCodeScanDocumentListener.kt b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codewhisperer/codescan/listeners/CodeWhispererCodeScanDocumentListener.kt index cee4a8afbb6..2d51d0b0f23 100644 --- a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codewhisperer/codescan/listeners/CodeWhispererCodeScanDocumentListener.kt +++ b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codewhisperer/codescan/listeners/CodeWhispererCodeScanDocumentListener.kt @@ -22,7 +22,17 @@ internal class CodeWhispererCodeScanDocumentListener(val project: Project) : Doc val scanManager = CodeWhispererCodeScanManager.getInstance(project) val treeModel = scanManager.getScanTree().model + val oldLineDeletedCount = event.oldFragment.toString().count { it == '\n' } + val newLineInsertedCount = event.newFragment.toString().count { it == '\n' } + + val lineOffset = when { + oldLineDeletedCount == 0 && newLineInsertedCount != 0 -> newLineInsertedCount + oldLineDeletedCount != 0 && newLineInsertedCount == 0 -> -oldLineDeletedCount + else -> 0 + } + val editedTextRange = TextRange.create(event.offset, event.offset + event.oldLength) + scanManager.updateScanNodesForOffSet(file, lineOffset, editedTextRange) val nodes = scanManager.getOverlappingScanNodes(file, editedTextRange) nodes.forEach { val issue = it.userObject as CodeWhispererCodeScanIssue From ffea4cd6e5c686293fd28d1414f374f8ec1d46ca Mon Sep 17 00:00:00 2001 From: laileni Date: Thu, 30 May 2024 16:44:00 -0700 Subject: [PATCH 2/7] Text changes --- .../listeners/CodeWhispererCodeScanDocumentListener.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codewhisperer/codescan/listeners/CodeWhispererCodeScanDocumentListener.kt b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codewhisperer/codescan/listeners/CodeWhispererCodeScanDocumentListener.kt index 2d51d0b0f23..9137447792f 100644 --- a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codewhisperer/codescan/listeners/CodeWhispererCodeScanDocumentListener.kt +++ b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codewhisperer/codescan/listeners/CodeWhispererCodeScanDocumentListener.kt @@ -22,12 +22,12 @@ internal class CodeWhispererCodeScanDocumentListener(val project: Project) : Doc val scanManager = CodeWhispererCodeScanManager.getInstance(project) val treeModel = scanManager.getScanTree().model - val oldLineDeletedCount = event.oldFragment.toString().count { it == '\n' } - val newLineInsertedCount = event.newFragment.toString().count { it == '\n' } + val deletedLineCount = event.oldFragment.toString().count { it == '\n' } + val insertedLineCount = event.newFragment.toString().count { it == '\n' } val lineOffset = when { - oldLineDeletedCount == 0 && newLineInsertedCount != 0 -> newLineInsertedCount - oldLineDeletedCount != 0 && newLineInsertedCount == 0 -> -oldLineDeletedCount + deletedLineCount == 0 && insertedLineCount != 0 -> insertedLineCount + deletedLineCount != 0 && insertedLineCount == 0 -> -deletedLineCount else -> 0 } From 053f51336a6da91e4643c4473535845276eae7d2 Mon Sep 17 00:00:00 2001 From: laileni Date: Thu, 30 May 2024 19:14:36 -0700 Subject: [PATCH 3/7] Refactoring code --- .../codescan/CodeWhispererCodeScanManager.kt | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codewhisperer/codescan/CodeWhispererCodeScanManager.kt b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codewhisperer/codescan/CodeWhispererCodeScanManager.kt index c458e6d7941..4805c8ee3cd 100644 --- a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codewhisperer/codescan/CodeWhispererCodeScanManager.kt +++ b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codewhisperer/codescan/CodeWhispererCodeScanManager.kt @@ -460,23 +460,23 @@ class CodeWhispererCodeScanManager(val project: Project) { private fun offsetSuggestedFix(suggestedFix: SuggestedFix, lines: Int): SuggestedFix { val updatedCode = suggestedFix.code.replace( Regex("""(@@ -)(\d+)(,\d+ \+)(\d+)(,\d+ @@)""") - ) { matchResult -> - val prefix = matchResult.groupValues[1] - val startLine = matchResult.groupValues[2].toInt() + lines - val middle = matchResult.groupValues[3] - val endLine = matchResult.groupValues[4].toInt() + lines - val suffix = matchResult.groupValues[5] + ) { result -> + val prefix = result.groupValues[1] + val startLine = result.groupValues[2].toInt() + lines + val middle = result.groupValues[3] + val endLine = result.groupValues[4].toInt() + lines + val suffix = result.groupValues[5] "$prefix$startLine$middle$endLine$suffix" } return suggestedFix.copy(code = updatedCode) } - fun updateScanNodesForOffSet(file: VirtualFile, lineOffset: Int, eventOffset: TextRange) { + fun updateScanNodesForOffSet(file: VirtualFile, lineOffset: Int, editedTextRange: TextRange) { val document = FileDocumentManager.getInstance().getDocument(file) ?: return scanNodesLookup[file]?.forEach { node -> val issue = node.userObject as CodeWhispererCodeScanIssue - if (document.getLineNumber(eventOffset.startOffset) <= issue.startLine) { + if (document.getLineNumber(editedTextRange.startOffset) <= issue.startLine) { issue.startLine = issue.startLine + lineOffset issue.endLine = issue.endLine + lineOffset issue.suggestedFixes = issue.suggestedFixes.map { fix -> offsetSuggestedFix(fix, lineOffset) } From 70231fc2b160211c6316433a201c13052f806b67 Mon Sep 17 00:00:00 2001 From: laileni Date: Thu, 30 May 2024 19:39:58 -0700 Subject: [PATCH 4/7] Added Change log --- .../bugfix-6862d9d5-751a-40c6-a907-53478af6991c.json | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .changes/next-release/bugfix-6862d9d5-751a-40c6-a907-53478af6991c.json diff --git a/.changes/next-release/bugfix-6862d9d5-751a-40c6-a907-53478af6991c.json b/.changes/next-release/bugfix-6862d9d5-751a-40c6-a907-53478af6991c.json new file mode 100644 index 00000000000..d6a2cc6d84b --- /dev/null +++ b/.changes/next-release/bugfix-6862d9d5-751a-40c6-a907-53478af6991c.json @@ -0,0 +1,4 @@ +{ + "type" : "bugfix", + "description" : "Security Scan: Improved accuracy when applying security fixes" +} \ No newline at end of file From 0126a8e2a1bc2834955d0aad06baabad389bf58b Mon Sep 17 00:00:00 2001 From: laileni Date: Fri, 31 May 2024 10:07:19 -0700 Subject: [PATCH 5/7] Adding Test cases for offsetSuggestedFix function --- .../codescan/CodeWhispererCodeScanManager.kt | 16 +-- .../aws/toolkits/jetbrains/utils/TextUtils.kt | 16 +++ .../toolkits/jetbrains/utils/TextUtilsTest.kt | 131 ++++++++++++++++++ 3 files changed, 148 insertions(+), 15 deletions(-) diff --git a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codewhisperer/codescan/CodeWhispererCodeScanManager.kt b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codewhisperer/codescan/CodeWhispererCodeScanManager.kt index 4805c8ee3cd..4d1b1c58636 100644 --- a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codewhisperer/codescan/CodeWhispererCodeScanManager.kt +++ b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codewhisperer/codescan/CodeWhispererCodeScanManager.kt @@ -74,6 +74,7 @@ import software.aws.toolkits.jetbrains.services.codewhisperer.util.runIfIdcConne import software.aws.toolkits.jetbrains.utils.isQConnected import software.aws.toolkits.jetbrains.utils.isQExpired import software.aws.toolkits.jetbrains.utils.isRunningOnRemoteBackend +import software.aws.toolkits.jetbrains.utils.offsetSuggestedFix import software.aws.toolkits.resources.message import software.aws.toolkits.telemetry.Result import java.time.Duration @@ -457,21 +458,6 @@ class CodeWhispererCodeScanManager(val project: Project) { } } - private fun offsetSuggestedFix(suggestedFix: SuggestedFix, lines: Int): SuggestedFix { - val updatedCode = suggestedFix.code.replace( - Regex("""(@@ -)(\d+)(,\d+ \+)(\d+)(,\d+ @@)""") - ) { result -> - val prefix = result.groupValues[1] - val startLine = result.groupValues[2].toInt() + lines - val middle = result.groupValues[3] - val endLine = result.groupValues[4].toInt() + lines - val suffix = result.groupValues[5] - "$prefix$startLine$middle$endLine$suffix" - } - - return suggestedFix.copy(code = updatedCode) - } - fun updateScanNodesForOffSet(file: VirtualFile, lineOffset: Int, editedTextRange: TextRange) { val document = FileDocumentManager.getInstance().getDocument(file) ?: return scanNodesLookup[file]?.forEach { node -> diff --git a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/utils/TextUtils.kt b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/utils/TextUtils.kt index badd3e5d93b..88592d43f9c 100644 --- a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/utils/TextUtils.kt +++ b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/utils/TextUtils.kt @@ -12,6 +12,7 @@ import com.intellij.openapi.project.Project import com.intellij.openapi.util.text.StringUtil import com.intellij.psi.PsiFileFactory import com.intellij.psi.codeStyle.CodeStyleManager +import software.aws.toolkits.jetbrains.services.codewhisperer.codescan.SuggestedFix fun formatText(project: Project, language: Language, content: String): String { var result = content @@ -42,3 +43,18 @@ fun applyPatch(patch: String, fileContent: String, filePath: String): String? { val unifiedPatch = generateUnifiedPatch(patch, filePath) return PlainSimplePatchApplier.apply(fileContent, unifiedPatch.hunks) } + +fun offsetSuggestedFix(suggestedFix: SuggestedFix, lines: Int): SuggestedFix { + val updatedCode = suggestedFix.code.replace( + Regex("""(@@ -)(\d+)(,\d+ \+)(\d+)(,\d+ @@)""") + ) { result -> + val prefix = result.groupValues[1] + val startLine = result.groupValues[2].toInt() + lines + val middle = result.groupValues[3] + val endLine = result.groupValues[4].toInt() + lines + val suffix = result.groupValues[5] + "$prefix$startLine$middle$endLine$suffix" + } + + return suggestedFix.copy(code = updatedCode) +} diff --git a/plugins/toolkit/jetbrains-core/tst/software/aws/toolkits/jetbrains/utils/TextUtilsTest.kt b/plugins/toolkit/jetbrains-core/tst/software/aws/toolkits/jetbrains/utils/TextUtilsTest.kt index 66a8cc10fba..333b4dd141e 100644 --- a/plugins/toolkit/jetbrains-core/tst/software/aws/toolkits/jetbrains/utils/TextUtilsTest.kt +++ b/plugins/toolkit/jetbrains-core/tst/software/aws/toolkits/jetbrains/utils/TextUtilsTest.kt @@ -10,7 +10,9 @@ import org.assertj.core.api.Assertions.assertThat import org.intellij.lang.annotations.Language import org.junit.Rule import org.junit.Test +import org.junit.Assert.assertEquals import software.aws.toolkits.core.utils.convertMarkdownToHTML +import software.aws.toolkits.jetbrains.services.codewhisperer.codescan.SuggestedFix class TextUtilsTest { @Rule @@ -137,4 +139,133 @@ class TextUtilsTest { val inputPatchLines = inputPatch.split("\n") hunk.lines.forEachIndexed { index, patchLine -> assertThat(inputPatchLines[index + 1].substring(1)).isEqualTo(patchLine.text) } } + + @Test + fun offsetSuggestedFixUpdateLineNumbersWithInsertion() { + val originalCode = """ + fun main() { + println("Hello, World!") + } + """.trimIndent() + + val suggestedFix = SuggestedFix( + code = """ + @@ -1,3 +1,4 @@ + fun main() { + + val greeting = "Hello, World!" + println("Hello, World!") + } + """.trimIndent(), + description = "Add a variable for the greeting" + ) + + val expectedCode = """ + @@ -2,3 +2,4 @@ + fun main() { + + val greeting = "Hello, World!" + println("Hello, World!") + } + """.trimIndent() + + val result = offsetSuggestedFix(suggestedFix, 1) + assertEquals(expectedCode, result.code) + } + + @Test + fun offsetSuggestedFixUpdateMultipleLineNumbersWithInsertion() { + val originalCode = """ + fun main() { + println("Hello, World!") + } + """.trimIndent() + + val suggestedFix = SuggestedFix( + code = """ + @@ -1,3 +1,5 @@ + fun main() { + + val greeting = "Hello, World!" + println("Hello, World!") + + println("Goodbye, World!") + } + """.trimIndent(), + description = "Add a variable for the greeting and a goodbye message" + ) + + val expectedCode = """ + @@ -4,3 +4,5 @@ + fun main() { + + val greeting = "Hello, World!" + println("Hello, World!") + + println("Goodbye, World!") + } + """.trimIndent() + + val result = offsetSuggestedFix(suggestedFix, 3) + assertEquals(expectedCode, result.code) + } + + @Test + fun offsetSuggestedFixUpdateLineNumbersWithDeletion() { + val originalCode = """ + fun main() { + println("Hello, World!") + } + """.trimIndent() + + val suggestedFix = SuggestedFix( + code = """ + @@ -24,3 +24,4 @@ + fun main() { + + val greeting = "Hello, World!" + println("Hello, World!") + } + """.trimIndent(), + description = "Add a variable for the greeting" + ) + + val expectedCode = """ + @@ -19,3 +19,4 @@ + fun main() { + + val greeting = "Hello, World!" + println("Hello, World!") + } + """.trimIndent() + + val result = offsetSuggestedFix(suggestedFix, -5) + assertEquals(expectedCode, result.code) + } + + @Test + fun offsetSuggestedFixUpdateMultipleLineNumbersWithDeletion() { + val originalCode = """ + fun main() { + println("Hello, World!") + } + """.trimIndent() + + val suggestedFix = SuggestedFix( + code = """ + @@ -10,3 +10,5 @@ + fun main() { + + val greeting = "Hello, World!" + println("Hello, World!") + + println("Goodbye, World!") + } + """.trimIndent(), + description = "Add a variable for the greeting and a goodbye message" + ) + + val expectedCode = """ + @@ -8,3 +8,5 @@ + fun main() { + + val greeting = "Hello, World!" + println("Hello, World!") + + println("Goodbye, World!") + } + """.trimIndent() + + val result = offsetSuggestedFix(suggestedFix, -2) + assertEquals(expectedCode, result.code) + } + } From dfde85a5bd3ce4a62b0ff890641efefedc7ba6f3 Mon Sep 17 00:00:00 2001 From: laileni Date: Fri, 31 May 2024 10:21:27 -0700 Subject: [PATCH 6/7] Adding Text changes to Test cases --- .../toolkits/jetbrains/utils/TextUtilsTest.kt | 52 +++++++++---------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/plugins/toolkit/jetbrains-core/tst/software/aws/toolkits/jetbrains/utils/TextUtilsTest.kt b/plugins/toolkit/jetbrains-core/tst/software/aws/toolkits/jetbrains/utils/TextUtilsTest.kt index 333b4dd141e..7aff6de0d86 100644 --- a/plugins/toolkit/jetbrains-core/tst/software/aws/toolkits/jetbrains/utils/TextUtilsTest.kt +++ b/plugins/toolkit/jetbrains-core/tst/software/aws/toolkits/jetbrains/utils/TextUtilsTest.kt @@ -144,7 +144,7 @@ class TextUtilsTest { fun offsetSuggestedFixUpdateLineNumbersWithInsertion() { val originalCode = """ fun main() { - println("Hello, World!") + println("Hello, Suggested Fix is Here!") } """.trimIndent() @@ -152,8 +152,8 @@ class TextUtilsTest { code = """ @@ -1,3 +1,4 @@ fun main() { - + val greeting = "Hello, World!" - println("Hello, World!") + + val greeting = "Hello, Suggested Fix is Here!" + println("Hello, Suggested Fix is Here!") } """.trimIndent(), description = "Add a variable for the greeting" @@ -162,8 +162,8 @@ class TextUtilsTest { val expectedCode = """ @@ -2,3 +2,4 @@ fun main() { - + val greeting = "Hello, World!" - println("Hello, World!") + + val greeting = "Hello, Suggested Fix is Here!" + println("Hello, Suggested Fix is Here!") } """.trimIndent() @@ -175,7 +175,7 @@ class TextUtilsTest { fun offsetSuggestedFixUpdateMultipleLineNumbersWithInsertion() { val originalCode = """ fun main() { - println("Hello, World!") + println("Hello, Suggested Fix is Here!") } """.trimIndent() @@ -183,20 +183,20 @@ class TextUtilsTest { code = """ @@ -1,3 +1,5 @@ fun main() { - + val greeting = "Hello, World!" - println("Hello, World!") - + println("Goodbye, World!") + + val greeting = "Hello, Suggested Fix is Here!" + println("Hello, Suggested Fix is Here!")) + + println("Hello, Welcome to Amazon Q") } """.trimIndent(), - description = "Add a variable for the greeting and a goodbye message" + description = "Add a variable for the greeting with multiple lines" ) val expectedCode = """ @@ -4,3 +4,5 @@ fun main() { - + val greeting = "Hello, World!" - println("Hello, World!") - + println("Goodbye, World!") + + val greeting = "Hello, Suggested Fix is Here!" + println("Hello, Suggested Fix is Here!")) + + println("Hello, Welcome to Amazon Q") } """.trimIndent() @@ -208,7 +208,7 @@ class TextUtilsTest { fun offsetSuggestedFixUpdateLineNumbersWithDeletion() { val originalCode = """ fun main() { - println("Hello, World!") + println("Hello, Suggested Fix is Here!") } """.trimIndent() @@ -216,8 +216,8 @@ class TextUtilsTest { code = """ @@ -24,3 +24,4 @@ fun main() { - + val greeting = "Hello, World!" - println("Hello, World!") + + val greeting = "Hello, Suggested Fix is Here!" + println("Hello, Suggested Fix is Here!") } """.trimIndent(), description = "Add a variable for the greeting" @@ -226,8 +226,8 @@ class TextUtilsTest { val expectedCode = """ @@ -19,3 +19,4 @@ fun main() { - + val greeting = "Hello, World!" - println("Hello, World!") + + val greeting = "Hello, Suggested Fix is Here!" + println("Hello, Suggested Fix is Here!") } """.trimIndent() @@ -239,7 +239,7 @@ class TextUtilsTest { fun offsetSuggestedFixUpdateMultipleLineNumbersWithDeletion() { val originalCode = """ fun main() { - println("Hello, World!") + println("Hello, Suggested Fix is Here!") } """.trimIndent() @@ -247,20 +247,20 @@ class TextUtilsTest { code = """ @@ -10,3 +10,5 @@ fun main() { - + val greeting = "Hello, World!" - println("Hello, World!") - + println("Goodbye, World!") + + val greeting = "Hello, Suggested Fix is Here!" + println("Hello, Suggested Fix is Here!")) + + println("Hello, Welcome to Amazon Q") } """.trimIndent(), - description = "Add a variable for the greeting and a goodbye message" + description = "Add a variable for the greeting with multiple lines" ) val expectedCode = """ @@ -8,3 +8,5 @@ fun main() { - + val greeting = "Hello, World!" - println("Hello, World!") - + println("Goodbye, World!") + + val greeting = "Hello, Suggested Fix is Here!" + println("Hello, Suggested Fix is Here!")) + + println("Hello, Welcome to Amazon Q") } """.trimIndent() From ff3f45f1a5afad157425337c4712dfc10c56d065 Mon Sep 17 00:00:00 2001 From: laileni Date: Fri, 31 May 2024 10:59:29 -0700 Subject: [PATCH 7/7] Minor edits --- .../toolkits/jetbrains/utils/TextUtilsTest.kt | 35 +++---------------- 1 file changed, 5 insertions(+), 30 deletions(-) diff --git a/plugins/toolkit/jetbrains-core/tst/software/aws/toolkits/jetbrains/utils/TextUtilsTest.kt b/plugins/toolkit/jetbrains-core/tst/software/aws/toolkits/jetbrains/utils/TextUtilsTest.kt index 7aff6de0d86..e85fade3861 100644 --- a/plugins/toolkit/jetbrains-core/tst/software/aws/toolkits/jetbrains/utils/TextUtilsTest.kt +++ b/plugins/toolkit/jetbrains-core/tst/software/aws/toolkits/jetbrains/utils/TextUtilsTest.kt @@ -8,9 +8,9 @@ import com.intellij.testFramework.ProjectRule import com.intellij.testFramework.runInEdtAndWait import org.assertj.core.api.Assertions.assertThat import org.intellij.lang.annotations.Language +import org.junit.Assert.assertEquals import org.junit.Rule import org.junit.Test -import org.junit.Assert.assertEquals import software.aws.toolkits.core.utils.convertMarkdownToHTML import software.aws.toolkits.jetbrains.services.codewhisperer.codescan.SuggestedFix @@ -142,12 +142,6 @@ class TextUtilsTest { @Test fun offsetSuggestedFixUpdateLineNumbersWithInsertion() { - val originalCode = """ - fun main() { - println("Hello, Suggested Fix is Here!") - } - """.trimIndent() - val suggestedFix = SuggestedFix( code = """ @@ -1,3 +1,4 @@ @@ -155,7 +149,7 @@ class TextUtilsTest { + val greeting = "Hello, Suggested Fix is Here!" println("Hello, Suggested Fix is Here!") } - """.trimIndent(), + """.trimIndent(), description = "Add a variable for the greeting" ) @@ -173,12 +167,6 @@ class TextUtilsTest { @Test fun offsetSuggestedFixUpdateMultipleLineNumbersWithInsertion() { - val originalCode = """ - fun main() { - println("Hello, Suggested Fix is Here!") - } - """.trimIndent() - val suggestedFix = SuggestedFix( code = """ @@ -1,3 +1,5 @@ @@ -187,7 +175,7 @@ class TextUtilsTest { println("Hello, Suggested Fix is Here!")) + println("Hello, Welcome to Amazon Q") } - """.trimIndent(), + """.trimIndent(), description = "Add a variable for the greeting with multiple lines" ) @@ -206,12 +194,6 @@ class TextUtilsTest { @Test fun offsetSuggestedFixUpdateLineNumbersWithDeletion() { - val originalCode = """ - fun main() { - println("Hello, Suggested Fix is Here!") - } - """.trimIndent() - val suggestedFix = SuggestedFix( code = """ @@ -24,3 +24,4 @@ @@ -219,7 +201,7 @@ class TextUtilsTest { + val greeting = "Hello, Suggested Fix is Here!" println("Hello, Suggested Fix is Here!") } - """.trimIndent(), + """.trimIndent(), description = "Add a variable for the greeting" ) @@ -237,12 +219,6 @@ class TextUtilsTest { @Test fun offsetSuggestedFixUpdateMultipleLineNumbersWithDeletion() { - val originalCode = """ - fun main() { - println("Hello, Suggested Fix is Here!") - } - """.trimIndent() - val suggestedFix = SuggestedFix( code = """ @@ -10,3 +10,5 @@ @@ -251,7 +227,7 @@ class TextUtilsTest { println("Hello, Suggested Fix is Here!")) + println("Hello, Welcome to Amazon Q") } - """.trimIndent(), + """.trimIndent(), description = "Add a variable for the greeting with multiple lines" ) @@ -267,5 +243,4 @@ class TextUtilsTest { val result = offsetSuggestedFix(suggestedFix, -2) assertEquals(expectedCode, result.code) } - }