Skip to content

Commit f06bab3

Browse files
Telemetry(amazonq): Discrepancy between NumOfUnitTestCasesGenerated with LinesGenerated and CharsGenerated (#5254)
* lint * fix the issue about the discrepancy between NumOfUnitTestCasesGenerated with LinesGenerated and CharsGenerated * fix format issue * remove print command
1 parent 52d7701 commit f06bab3

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
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
@@ -524,6 +524,8 @@ class CodeWhispererUTGChatManager(val project: Project, private val cs: Coroutin
524524
try {
525525
launchTestGenFlow(prompt, codeTestChatHelper, previousIterationContext, selectionRange)
526526
} catch (e: Exception) {
527+
// reset number of unitTestGenerated to null
528+
session.numberOfUnitTestCasesGenerated = null
527529
// Add an answer for displaying error message
528530
val errorMessage = when {
529531
e is CodeTestException &&

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import com.intellij.diff.DiffManagerEx
99
import com.intellij.diff.requests.SimpleDiffRequest
1010
import com.intellij.ide.BrowserUtil
1111
import com.intellij.openapi.application.ApplicationManager
12-
import com.intellij.openapi.fileEditor.FileDocumentManager
1312
import com.intellij.openapi.fileEditor.FileEditorManager
1413
import com.intellij.openapi.project.Project
1514
import com.intellij.openapi.project.guessProjectDir
@@ -473,16 +472,14 @@ class CodeTestChatController(
473472
)
474473
session.openedDiffFile = FileEditorManager.getInstance(context.project).selectedEditor?.file
475474
ApplicationManager.getApplication().runReadAction {
476-
generatedFileContent = getFileContentAtTestFilePath(
477-
session.projectRoot,
478-
session.testFileRelativePathToProjectRoot
479-
)
480-
val selectedFile = FileEditorManager.getInstance(context.project).selectedEditor?.file
481-
selectedFileContent = selectedFile?.let {
482-
FileDocumentManager.getInstance().getDocument(it)?.text
483-
}.orEmpty()
475+
generatedFileContent = getGeneratedFileContent(session)
484476
}
485477

478+
selectedFileContent = getFileContentAtTestFilePath(
479+
session.projectRoot,
480+
session.testFileRelativePathToProjectRoot,
481+
)
482+
486483
// Line difference calculation: linesOfCodeGenerated = number of lines in generated test file - number of lines in original test file
487484
numberOfLinesGenerated = generatedFileContent.lines().size
488485
numberOfLinesSelected = selectedFileContent.lines().size
@@ -1070,6 +1067,12 @@ class CodeTestChatController(
10701067
}
10711068
}
10721069

1070+
// Return generated test file content
1071+
private fun getGeneratedFileContent(session: Session): String {
1072+
val generateFileContent = session.generatedTestDiffs[session.testFileRelativePathToProjectRoot].toString()
1073+
return generateFileContent
1074+
}
1075+
10731076
/*
10741077
If shortAnswer has buildCommand, use it, if it doesn't hardcode it according to the user type(internal or not)
10751078
private fun getBuildCommand(tabId: String): String {

0 commit comments

Comments
 (0)