Skip to content

Commit 18590f8

Browse files
authored
fix(amazonq): enable syntax highlighting when viewing diff for generated unit tests (#5337)
* enable syntax highlighting when viewing diff for generated unit tests changelog remove unused import * lint * virtualFile always created and will not be null * use session.testFileName instead of extension * lint * create temporary virtual file * comment * Update bugfix-3b7843b4-9673-4afa-90e8-7c4278f0d0fe.json
1 parent 97bd375 commit 18590f8

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type" : "bugfix",
3+
"description" : "Enable syntax highlighting when viewing diff for /test"
4+
}

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,10 @@ class CodeTestChatController(
458458
when (message.actionID) {
459459
"utg_view_diff" -> {
460460
withContext(EDT) {
461+
// virtual file only needed for syntax highlighting when viewing diff
462+
val tempPath = Files.createTempFile(null, ".${session.testFileName.substringAfterLast('.')}")
463+
val virtualFile = tempPath.toFile().toVirtualFile()
464+
461465
(DiffManager.getInstance() as DiffManagerEx).showDiffBuiltin(
462466
context.project,
463467
SimpleDiffRequest(
@@ -466,13 +470,18 @@ class CodeTestChatController(
466470
getFileContentAtTestFilePath(
467471
session.projectRoot,
468472
session.testFileRelativePathToProjectRoot
469-
)
473+
),
474+
virtualFile
475+
),
476+
DiffContentFactory.getInstance().create(
477+
session.generatedTestDiffs.values.first(),
478+
virtualFile
470479
),
471-
DiffContentFactory.getInstance().create(session.generatedTestDiffs.values.first()),
472480
"Before",
473481
"After"
474482
)
475483
)
484+
Files.deleteIfExists(tempPath)
476485
session.openedDiffFile = FileEditorManager.getInstance(context.project).selectedEditor?.file
477486
ApplicationManager.getApplication().runReadAction {
478487
generatedFileContent = getGeneratedFileContent(session)

0 commit comments

Comments
 (0)