@@ -32,7 +32,6 @@ import {
32
32
DocumentReference ,
33
33
FileClick ,
34
34
RelevantTextDocumentAddition ,
35
- OpenDiff ,
36
35
} from './model'
37
36
import {
38
37
AppToWebViewMessageDispatcher ,
@@ -94,7 +93,6 @@ export interface ChatControllerMessagePublishers {
94
93
readonly processInsertCodeAtCursorPosition : MessagePublisher < InsertCodeAtCursorPosition >
95
94
readonly processAcceptDiff : MessagePublisher < AcceptDiff >
96
95
readonly processViewDiff : MessagePublisher < ViewDiff >
97
- readonly processOpenDiff : MessagePublisher < OpenDiff >
98
96
readonly processCopyCodeToClipboard : MessagePublisher < CopyCodeToClipboard >
99
97
readonly processContextMenuCommand : MessagePublisher < EditorContextCommand >
100
98
readonly processTriggerTabIDReceived : MessagePublisher < TriggerTabIDReceived >
@@ -120,7 +118,6 @@ export interface ChatControllerMessageListeners {
120
118
readonly processInsertCodeAtCursorPosition : MessageListener < InsertCodeAtCursorPosition >
121
119
readonly processAcceptDiff : MessageListener < AcceptDiff >
122
120
readonly processViewDiff : MessageListener < ViewDiff >
123
- readonly processOpenDiff : MessageListener < OpenDiff >
124
121
readonly processCopyCodeToClipboard : MessageListener < CopyCodeToClipboard >
125
122
readonly processContextMenuCommand : MessageListener < EditorContextCommand >
126
123
readonly processTriggerTabIDReceived : MessageListener < TriggerTabIDReceived >
@@ -219,10 +216,6 @@ export class ChatController {
219
216
return this . processViewDiff ( data )
220
217
} )
221
218
222
- this . chatControllerMessageListeners . processOpenDiff . onMessage ( ( data ) => {
223
- return this . processOpenDiff ( data )
224
- } )
225
-
226
219
this . chatControllerMessageListeners . processCopyCodeToClipboard . onMessage ( ( data ) => {
227
220
return this . processCopyCodeToClipboard ( data )
228
221
} )
@@ -398,20 +391,6 @@ export class ChatController {
398
391
} )
399
392
}
400
393
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
-
415
394
private async processAcceptCodeDiff ( message : CustomFormActionMessage ) {
416
395
const session = this . sessionStorage . getSession ( message . tabID ?? '' )
417
396
const filePath = session . filePath ?? ''
@@ -644,55 +623,70 @@ export class ChatController {
644
623
}
645
624
private async processFileClickMessage ( message : FileClick ) {
646
625
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 )
648
641
649
- if ( ! lineRanges ) {
650
- return
651
- }
642
+ if ( ! lineRanges ) {
643
+ return
644
+ }
652
645
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 )
660
653
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
+ }
667
661
}
668
- }
669
662
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
+ } )
688
681
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
+ }
696
690
}
697
691
698
692
private processException ( e : any , tabID : string ) {
@@ -971,6 +965,7 @@ export class ChatController {
971
965
private async processPromptMessageAsNewThread ( message : PromptMessage ) {
972
966
const session = this . sessionStorage . getSession ( message . tabID )
973
967
session . clearListOfReadFiles ( )
968
+ session . setShowDiffOnFileWrite ( false )
974
969
this . editorContextExtractor
975
970
. extractContextForTrigger ( 'ChatMessage' )
976
971
. then ( async ( context ) => {
0 commit comments