Skip to content

Commit 6fa3c9d

Browse files
committed
fix the issue about the discrepancy between NumOfUnitTestCasesGenerated with LinesGenerated and CharsGenerated
1 parent da94667 commit 6fa3c9d

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqCodeTest/CodeWhispererUTGChatManager.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,8 @@ class CodeWhispererUTGChatManager(val project: Project, private val cs: Coroutin
492492
try {
493493
launchTestGenFlow(prompt, codeTestChatHelper, previousIterationContext, selectionRange)
494494
} catch (e: Exception) {
495+
//reset number of unitTestGenerated to null
496+
session.numberOfUnitTestCasesGenerated = null
495497
// Add an answer for displaying error message
496498
var errorMessage = e.message
497499
if (e is JsonParseException) {

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqCodeTest/controller/CodeTestChatController.kt

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -474,16 +474,14 @@ class CodeTestChatController(
474474
)
475475
session.openedDiffFile = FileEditorManager.getInstance(context.project).selectedEditor?.file
476476
ApplicationManager.getApplication().runReadAction {
477-
generatedFileContent = getFileContentAtTestFilePath(
478-
session.projectRoot,
479-
session.testFileRelativePathToProjectRoot
480-
)
481-
val selectedFile = FileEditorManager.getInstance(context.project).selectedEditor?.file
482-
selectedFileContent = selectedFile?.let {
483-
FileDocumentManager.getInstance().getDocument(it)?.text
484-
}.orEmpty()
477+
generatedFileContent = getGeneratedFileContent(session)
485478
}
486479

480+
selectedFileContent = getFileContentAtTestFilePath(
481+
session.projectRoot,
482+
session.testFileRelativePathToProjectRoot,
483+
)
484+
487485
// Line difference calculation: linesOfCodeGenerated = number of lines in generated test file - number of lines in original test file
488486
numberOfLinesGenerated = generatedFileContent.lines().size
489487
numberOfLinesSelected = selectedFileContent.lines().size
@@ -1076,6 +1074,11 @@ class CodeTestChatController(
10761074
}
10771075
}
10781076

1077+
// Return generated test file content
1078+
private fun getGeneratedFileContent( session: Session): String {
1079+
return session.generatedTestDiffs[session.testFileRelativePathToProjectRoot].toString()
1080+
}
1081+
10791082
/*
10801083
If shortAnswer has buildCommand, use it, if it doesn't hardcode it according to the user type(internal or not)
10811084
private fun getBuildCommand(tabId: String): String {

0 commit comments

Comments
 (0)