Skip to content

Commit 1b81576

Browse files
authored
fix(chat): Improve diffView UX (aws#6981)
## Notes - fix(chat): Improve diffView UX, changes include: - Remove the icon in diff view - Clean up temp files when accept or reject - Do not open the files as they generate --- - Treat all work as PUBLIC. Private `feature/x` branches will not be squash-merged at release time. - Your code changes must meet the guidelines in [CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). - License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 4ad3e92 commit 1b81576

File tree

2 files changed

+35
-27
lines changed

2 files changed

+35
-27
lines changed

packages/core/src/codewhispererChat/controllers/chat/controller.ts

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ import { OutputKind } from '../../tools/toolShared'
9797
import { ToolUtils, Tool, ToolType } from '../../tools/toolUtils'
9898
import { ChatStream } from '../../tools/chatStream'
9999
import { ChatHistoryStorage } from '../../storages/chatHistoryStorage'
100-
import { FsWriteParams } from '../../tools/fsWrite'
101100
import { tempDirPath } from '../../../shared/filesystemUtilities'
102101
import { Database } from '../../../shared/db/chatDb/chatDb'
103102
import { TabBarController } from './tabBarController'
@@ -746,13 +745,6 @@ export class ChatController {
746745
const toolResult: ToolResult = result
747746
toolResults.push(toolResult)
748747
}
749-
750-
if (toolUse.name === ToolType.FsWrite) {
751-
await vscode.commands.executeCommand(
752-
'vscode.open',
753-
vscode.Uri.file((toolUse.input as unknown as FsWriteParams).path)
754-
)
755-
}
756748
}
757749

758750
await this.generateResponse(
@@ -787,11 +779,26 @@ export class ChatController {
787779
})
788780
}
789781

790-
private async closeDiffView() {
791-
// Close the diff view if User reject the generated code changes.
782+
private async closeDiffView(message: CustomFormActionMessage) {
783+
// Close the diff view if User rejected or accepted the generated code changes.
792784
if (vscode.window.tabGroups.activeTabGroup.activeTab?.label.includes(amazonQTabSuffix)) {
793785
await vscode.commands.executeCommand('workbench.action.closeActiveEditor')
794786
}
787+
// clean up temp file
788+
const tabID = message.tabID
789+
const toolUseId = message.action.formItemValues?.toolUseId
790+
if (!tabID || !toolUseId) {
791+
return
792+
}
793+
794+
const session = this.sessionStorage.getSession(tabID)
795+
const { filePath } = session.fsWriteBackups.get(toolUseId) ?? {}
796+
if (filePath) {
797+
const tempFilePath = await this.getTempFilePath(filePath)
798+
if (await fs.existsFile(tempFilePath)) {
799+
await fs.delete(tempFilePath)
800+
}
801+
}
795802
}
796803

797804
private async rejectShellCommand(message: CustomFormActionMessage) {
@@ -825,11 +832,11 @@ export class ChatController {
825832
await this.processToolUseMessage(message)
826833
break
827834
case 'accept-code-diff':
828-
await this.closeDiffView()
835+
await this.closeDiffView(message)
829836
break
830837
case 'reject-code-diff':
831838
await this.restoreBackup(message)
832-
await this.closeDiffView()
839+
await this.closeDiffView(message)
833840
break
834841
case 'reject-shell-command':
835842
await this.rejectShellCommand(message)
@@ -873,6 +880,21 @@ export class ChatController {
873880
}
874881
}
875882

883+
private async getTempFilePath(filePath: string) {
884+
// Create a temporary file path to show the diff view
885+
const pathToArchiveDir = path.join(tempDirPath, 'q-chat')
886+
const archivePathExists = await fs.existsDir(pathToArchiveDir)
887+
if (!archivePathExists) {
888+
await fs.mkdir(pathToArchiveDir)
889+
}
890+
const resultArtifactsDir = path.join(pathToArchiveDir, 'resultArtifacts')
891+
const resultArtifactsDirExists = await fs.existsDir(resultArtifactsDir)
892+
if (!resultArtifactsDirExists) {
893+
await fs.mkdir(resultArtifactsDir)
894+
}
895+
return path.join(resultArtifactsDir, `temp-${path.basename(filePath)}`)
896+
}
897+
876898
private async processFileClickMessage(message: FileClick) {
877899
const session = this.sessionStorage.getSession(message.tabID)
878900
// Check if user clicked on filePath in the contextList or in the fileListTree and perform the functionality accordingly.
@@ -884,18 +906,7 @@ export class ChatController {
884906
}
885907

886908
try {
887-
// Create a temporary file path to show the diff view
888-
// TODO: Use amazonQDiffScheme for temp file
889-
const pathToArchiveDir = path.join(tempDirPath, 'q-chat')
890-
const archivePathExists = await fs.existsDir(pathToArchiveDir)
891-
if (archivePathExists) {
892-
await fs.delete(pathToArchiveDir, { recursive: true })
893-
}
894-
await fs.mkdir(pathToArchiveDir)
895-
const resultArtifactsDir = path.join(pathToArchiveDir, 'resultArtifacts')
896-
await fs.mkdir(resultArtifactsDir)
897-
898-
const tempFilePath = path.join(resultArtifactsDir, `temp-${path.basename(filePath)}`)
909+
const tempFilePath = await this.getTempFilePath(filePath)
899910
await fs.writeFile(tempFilePath, content)
900911

901912
const leftUri = vscode.Uri.file(tempFilePath)

packages/core/src/codewhispererChat/controllers/chat/messenger/messenger.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -591,14 +591,11 @@ export class Messenger {
591591
},
592592
]
593593
header = {
594-
icon: 'code-block' as MynahIconsType,
595594
buttons,
596595
fileList,
597596
}
598597
fullWidth = true
599598
padding = false
600-
// eslint-disable-next-line unicorn/no-null
601-
codeBlockActions = { 'insert-to-cursor': null, copy: null }
602599
}
603600

604601
this.dispatcher.sendChatMessage(

0 commit comments

Comments
 (0)