@@ -13,6 +13,8 @@ import com.intellij.diff.util.DiffUserDataKeys
13
13
import com.intellij.ide.BrowserUtil
14
14
import com.intellij.openapi.application.runInEdt
15
15
import com.intellij.openapi.fileEditor.FileEditorManager
16
+ import com.intellij.openapi.fileEditor.TextEditorWithPreview
17
+ import com.intellij.openapi.vfs.LocalFileSystem
16
18
import com.intellij.openapi.vfs.VfsUtil
17
19
import com.intellij.openapi.wm.ToolWindowManager
18
20
import com.intellij.testFramework.LightVirtualFile
@@ -298,8 +300,11 @@ class DocController(
298
300
messenger.sendChatInputEnabledMessage(message.tabId, false )
299
301
}
300
302
303
+ private val diffVirtualFiles = mutableMapOf<String , ChainDiffVirtualFile >()
304
+
301
305
private suspend fun acceptChanges (message : IncomingDocMessage .FollowupClicked ) {
302
306
insertCode(message.tabId)
307
+ previewReadmeFile(message.tabId)
303
308
}
304
309
305
310
private suspend fun promptForDocTarget (tabId : String ) {
@@ -420,6 +425,8 @@ class DocController(
420
425
request.putUserData(DiffUserDataKeys .FORCE_READ_ONLY , true )
421
426
422
427
val newDiff = ChainDiffVirtualFile (SimpleDiffRequestChain (request), message.filePath)
428
+
429
+ diffVirtualFiles[message.filePath] = newDiff
423
430
DiffEditorTabFilesManager .getInstance(context.project).showDiffFile(newDiff, true )
424
431
}
425
432
}
@@ -1047,6 +1054,34 @@ class DocController(
1047
1054
session.sendDocTelemetryEvent(null , docAcceptanceEvent)
1048
1055
}
1049
1056
1057
+ private fun previewReadmeFile (tabId : String ) {
1058
+ val session = getSessionInfo(tabId)
1059
+ var filePaths: List <NewFileZipInfo > = emptyList()
1060
+
1061
+ when (val state = session.sessionState) {
1062
+ is PrepareDocGenerationState -> {
1063
+ filePaths = state.filePaths
1064
+ }
1065
+ }
1066
+
1067
+ if (filePaths.isNotEmpty()) {
1068
+ val filePath = filePaths[0 ].zipFilePath
1069
+ val existingDiff = diffVirtualFiles[filePath]
1070
+
1071
+ val newFilePath = session.context.addressableRoot.toNioPath().resolve(filePath)
1072
+ val readmeVirtualFile = LocalFileSystem .getInstance().refreshAndFindFileByPath(newFilePath.toString())
1073
+
1074
+ runInEdt {
1075
+ if (existingDiff != null ) {
1076
+ FileEditorManager .getInstance(getProject()).closeFile(existingDiff)
1077
+ }
1078
+ if (readmeVirtualFile != null ) {
1079
+ TextEditorWithPreview .openPreviewForFile(getProject(), readmeVirtualFile)
1080
+ }
1081
+ }
1082
+ }
1083
+ }
1084
+
1050
1085
fun getProject () = context.project
1051
1086
1052
1087
private fun getSessionInfo (tabId : String ) = chatSessionStorage.getSession(tabId, context.project)
0 commit comments