@@ -90,9 +90,9 @@ import { ChatSession } from '../../clients/chat/v0/chat'
9090import { ChatHistoryManager } from '../../storages/chatHistory'
9191import { amazonQTabSuffix } from '../../../shared/constants'
9292import { OutputKind } from '../../tools/toolShared'
93- import { ToolUtils , Tool } from '../../tools/toolUtils'
93+ import { ToolUtils , Tool , ToolType } from '../../tools/toolUtils'
9494import { ChatStream } from '../../tools/chatStream'
95- import { FsWriteParams } from '../../tools/fsWrite'
95+ import { FsWrite , FsWriteParams } from '../../tools/fsWrite'
9696import { tempDirPath } from '../../../shared/filesystemUtilities'
9797
9898export interface ChatControllerMessagePublishers {
@@ -661,10 +661,6 @@ export class ChatController {
661661 toolUseId : toolUse . toolUseId ,
662662 status : ToolResultStatus . SUCCESS ,
663663 } )
664- // Close the diff view if User accept the generated code changes.
665- if ( vscode . window . tabGroups . activeTabGroup . activeTab ?. label . includes ( amazonQTabSuffix ) ) {
666- await vscode . commands . executeCommand ( 'workbench.action.closeActiveEditor' )
667- }
668664 } catch ( e : any ) {
669665 toolResults . push ( {
670666 content : [ { text : e . message } ] ,
@@ -677,6 +673,13 @@ export class ChatController {
677673 toolResults . push ( toolResult )
678674 }
679675
676+ if ( toolUse . name === ToolType . FsWrite ) {
677+ await vscode . commands . executeCommand (
678+ 'vscode.open' ,
679+ vscode . Uri . file ( ( toolUse . input as unknown as FsWriteParams ) . path )
680+ )
681+ }
682+
680683 await this . generateResponse (
681684 {
682685 message : '' ,
@@ -710,6 +713,13 @@ export class ChatController {
710713 } )
711714 }
712715
716+ private async closeDiffView ( ) {
717+ // Close the diff view if User reject the generated code changes.
718+ if ( vscode . window . tabGroups . activeTabGroup . activeTab ?. label . includes ( amazonQTabSuffix ) ) {
719+ await vscode . commands . executeCommand ( 'workbench.action.closeActiveEditor' )
720+ }
721+ }
722+
713723 private async processCustomFormAction ( message : CustomFormActionMessage ) {
714724 switch ( message . action . id ) {
715725 case 'submit-create-prompt' :
@@ -718,15 +728,11 @@ export class ChatController {
718728 case 'accept-code-diff' :
719729 case 'confirm-tool-use' :
720730 case 'generic-tool-execution' :
731+ await this . closeDiffView ( )
721732 await this . processToolUseMessage ( message )
722733 break
723734 case 'reject-code-diff' :
724- // Close the diff view if User reject the generated code changes.
725- if ( vscode . window . tabGroups . activeTabGroup . activeTab ?. label . includes ( amazonQTabSuffix ) ) {
726- await vscode . commands . executeCommand ( 'workbench.action.closeActiveEditor' )
727- }
728- // TODO: Do session cleanUp.
729- getLogger ( ) . info ( 'Generated response is rejected' )
735+ await this . closeDiffView ( )
730736 break
731737 default :
732738 getLogger ( ) . warn ( `Unhandled action: ${ message . action . id } ` )
@@ -771,13 +777,9 @@ export class ChatController {
771777 }
772778 const input = clonedToolUse . input as unknown as FsWriteParams
773779 input . path = tempFilePath
774- const result = ToolUtils . tryFromToolUse ( clonedToolUse )
775- if ( ! ( 'type' in result ) ) {
776- return
777- }
778- const tool : Tool = result
779- await ToolUtils . validate ( tool )
780- await ToolUtils . invoke ( tool )
780+
781+ const fsWrite = new FsWrite ( input )
782+ await fsWrite . invoke ( )
781783
782784 // Check if fileExists=false, If yes, return instead of showing broken diff experience.
783785 if ( ! tempFilePath ) {
0 commit comments