@@ -32,7 +32,6 @@ import {
3232 DocumentReference ,
3333 FileClick ,
3434 RelevantTextDocumentAddition ,
35- OpenDiff ,
3635} from './model'
3736import {
3837 AppToWebViewMessageDispatcher ,
@@ -94,7 +93,6 @@ export interface ChatControllerMessagePublishers {
9493 readonly processInsertCodeAtCursorPosition : MessagePublisher < InsertCodeAtCursorPosition >
9594 readonly processAcceptDiff : MessagePublisher < AcceptDiff >
9695 readonly processViewDiff : MessagePublisher < ViewDiff >
97- readonly processOpenDiff : MessagePublisher < OpenDiff >
9896 readonly processCopyCodeToClipboard : MessagePublisher < CopyCodeToClipboard >
9997 readonly processContextMenuCommand : MessagePublisher < EditorContextCommand >
10098 readonly processTriggerTabIDReceived : MessagePublisher < TriggerTabIDReceived >
@@ -120,7 +118,6 @@ export interface ChatControllerMessageListeners {
120118 readonly processInsertCodeAtCursorPosition : MessageListener < InsertCodeAtCursorPosition >
121119 readonly processAcceptDiff : MessageListener < AcceptDiff >
122120 readonly processViewDiff : MessageListener < ViewDiff >
123- readonly processOpenDiff : MessageListener < OpenDiff >
124121 readonly processCopyCodeToClipboard : MessageListener < CopyCodeToClipboard >
125122 readonly processContextMenuCommand : MessageListener < EditorContextCommand >
126123 readonly processTriggerTabIDReceived : MessageListener < TriggerTabIDReceived >
@@ -219,10 +216,6 @@ export class ChatController {
219216 return this . processViewDiff ( data )
220217 } )
221218
222- this . chatControllerMessageListeners . processOpenDiff . onMessage ( ( data ) => {
223- return this . processOpenDiff ( data )
224- } )
225-
226219 this . chatControllerMessageListeners . processCopyCodeToClipboard . onMessage ( ( data ) => {
227220 return this . processCopyCodeToClipboard ( data )
228221 } )
@@ -398,20 +391,6 @@ export class ChatController {
398391 } )
399392 }
400393
401- private async processOpenDiff ( message : OpenDiff ) {
402- const session = this . sessionStorage . getSession ( message . tabID )
403- const filePath = session . filePath ?? message . filePath
404- const fileExists = await fs . existsFile ( filePath )
405- // Check if fileExists=false, If yes, return instead of showing broken diff experience.
406- if ( ! session . tempFilePath ) {
407- return
408- }
409- const leftUri = fileExists ? vscode . Uri . file ( filePath ) : vscode . Uri . from ( { scheme : 'untitled' } )
410- const rightUri = vscode . Uri . file ( session . tempFilePath ?? filePath )
411- const fileName = path . basename ( filePath )
412- await vscode . commands . executeCommand ( 'vscode.diff' , leftUri , rightUri , `${ fileName } ${ amazonQTabSuffix } ` )
413- }
414-
415394 private async processAcceptCodeDiff ( message : CustomFormActionMessage ) {
416395 const session = this . sessionStorage . getSession ( message . tabID ?? '' )
417396 const filePath = session . filePath ?? ''
@@ -644,55 +623,70 @@ export class ChatController {
644623 }
645624 private async processFileClickMessage ( message : FileClick ) {
646625 const session = this . sessionStorage . getSession ( message . tabID )
647- const lineRanges = session . contexts . get ( message . filePath )
626+ // Check if user clicked on filePath in the contextList or in the fileListTree and perform the functionality accordingly.
627+ if ( session . showDiffOnFileWrite ) {
628+ const filePath = session . filePath ?? message . filePath
629+ const fileExists = await fs . existsFile ( filePath )
630+ // Check if fileExists=false, If yes, return instead of showing broken diff experience.
631+ if ( ! session . tempFilePath ) {
632+ void vscode . window . showInformationMessage ( 'Generated code changes have been reviewed and processed.' )
633+ return
634+ }
635+ const leftUri = fileExists ? vscode . Uri . file ( filePath ) : vscode . Uri . from ( { scheme : 'untitled' } )
636+ const rightUri = vscode . Uri . file ( session . tempFilePath ?? filePath )
637+ const fileName = path . basename ( filePath )
638+ await vscode . commands . executeCommand ( 'vscode.diff' , leftUri , rightUri , `${ fileName } ${ amazonQTabSuffix } ` )
639+ } else {
640+ const lineRanges = session . contexts . get ( message . filePath )
648641
649- if ( ! lineRanges ) {
650- return
651- }
642+ if ( ! lineRanges ) {
643+ return
644+ }
652645
653- // Check if clicked file is in a different workspace root
654- const projectRoot =
655- session . relativePathToWorkspaceRoot . get ( message . filePath ) || workspace . workspaceFolders ?. [ 0 ] ?. uri . fsPath
656- if ( ! projectRoot ) {
657- return
658- }
659- let absoluteFilePath = path . join ( projectRoot , message . filePath )
646+ // Check if clicked file is in a different workspace root
647+ const projectRoot =
648+ session . relativePathToWorkspaceRoot . get ( message . filePath ) || workspace . workspaceFolders ?. [ 0 ] ?. uri . fsPath
649+ if ( ! projectRoot ) {
650+ return
651+ }
652+ let absoluteFilePath = path . join ( projectRoot , message . filePath )
660653
661- // Handle clicking on a user prompt outside the workspace
662- if ( message . filePath . endsWith ( promptFileExtension ) ) {
663- try {
664- await vscode . workspace . fs . stat ( vscode . Uri . file ( absoluteFilePath ) )
665- } catch {
666- absoluteFilePath = path . join ( getUserPromptsDirectory ( ) , message . filePath )
654+ // Handle clicking on a user prompt outside the workspace
655+ if ( message . filePath . endsWith ( promptFileExtension ) ) {
656+ try {
657+ await vscode . workspace . fs . stat ( vscode . Uri . file ( absoluteFilePath ) )
658+ } catch {
659+ absoluteFilePath = path . join ( getUserPromptsDirectory ( ) , message . filePath )
660+ }
667661 }
668- }
669662
670- try {
671- // Open the file in VSCode
672- const document = await workspace . openTextDocument ( absoluteFilePath )
673- const editor = await window . showTextDocument ( document , ViewColumn . Active )
674-
675- // Create multiple selections based on line ranges
676- const selections : Selection [ ] = lineRanges
677- . filter ( ( { first, second } ) => first !== - 1 && second !== - 1 )
678- . map ( ( { first, second } ) => {
679- const startPosition = new Position ( first - 1 , 0 ) // Convert 1-based to 0-based
680- const endPosition = new Position ( second - 1 , document . lineAt ( second - 1 ) . range . end . character )
681- return new Selection (
682- startPosition . line ,
683- startPosition . character ,
684- endPosition . line ,
685- endPosition . character
686- )
687- } )
663+ try {
664+ // Open the file in VSCode
665+ const document = await workspace . openTextDocument ( absoluteFilePath )
666+ const editor = await window . showTextDocument ( document , ViewColumn . Active )
667+
668+ // Create multiple selections based on line ranges
669+ const selections : Selection [ ] = lineRanges
670+ . filter ( ( { first, second } ) => first !== - 1 && second !== - 1 )
671+ . map ( ( { first, second } ) => {
672+ const startPosition = new Position ( first - 1 , 0 ) // Convert 1-based to 0-based
673+ const endPosition = new Position ( second - 1 , document . lineAt ( second - 1 ) . range . end . character )
674+ return new Selection (
675+ startPosition . line ,
676+ startPosition . character ,
677+ endPosition . line ,
678+ endPosition . character
679+ )
680+ } )
688681
689- // Apply multiple selections to the editor
690- if ( selections . length > 0 ) {
691- editor . selection = selections [ 0 ] // Set the first selection as active
692- editor . selections = selections // Apply multiple selections
693- editor . revealRange ( selections [ 0 ] , vscode . TextEditorRevealType . InCenter )
694- }
695- } catch ( error ) { }
682+ // Apply multiple selections to the editor
683+ if ( selections . length > 0 ) {
684+ editor . selection = selections [ 0 ] // Set the first selection as active
685+ editor . selections = selections // Apply multiple selections
686+ editor . revealRange ( selections [ 0 ] , vscode . TextEditorRevealType . InCenter )
687+ }
688+ } catch ( error ) { }
689+ }
696690 }
697691
698692 private processException ( e : any , tabID : string ) {
@@ -971,6 +965,7 @@ export class ChatController {
971965 private async processPromptMessageAsNewThread ( message : PromptMessage ) {
972966 const session = this . sessionStorage . getSession ( message . tabID )
973967 session . clearListOfReadFiles ( )
968+ session . setShowDiffOnFileWrite ( false )
974969 this . editorContextExtractor
975970 . extractContextForTrigger ( 'ChatMessage' )
976971 . then ( async ( context ) => {
0 commit comments