@@ -32,7 +32,6 @@ import {
3232 DocumentReference ,
3333 FileClick ,
3434 RelevantTextDocumentAddition ,
35- OpenDiff ,
3635} from './model'
3736import {
3837 AppToWebViewMessageDispatcher ,
@@ -93,7 +92,6 @@ export interface ChatControllerMessagePublishers {
9392 readonly processInsertCodeAtCursorPosition : MessagePublisher < InsertCodeAtCursorPosition >
9493 readonly processAcceptDiff : MessagePublisher < AcceptDiff >
9594 readonly processViewDiff : MessagePublisher < ViewDiff >
96- readonly processOpenDiff : MessagePublisher < OpenDiff >
9795 readonly processCopyCodeToClipboard : MessagePublisher < CopyCodeToClipboard >
9896 readonly processContextMenuCommand : MessagePublisher < EditorContextCommand >
9997 readonly processTriggerTabIDReceived : MessagePublisher < TriggerTabIDReceived >
@@ -119,7 +117,6 @@ export interface ChatControllerMessageListeners {
119117 readonly processInsertCodeAtCursorPosition : MessageListener < InsertCodeAtCursorPosition >
120118 readonly processAcceptDiff : MessageListener < AcceptDiff >
121119 readonly processViewDiff : MessageListener < ViewDiff >
122- readonly processOpenDiff : MessageListener < OpenDiff >
123120 readonly processCopyCodeToClipboard : MessageListener < CopyCodeToClipboard >
124121 readonly processContextMenuCommand : MessageListener < EditorContextCommand >
125122 readonly processTriggerTabIDReceived : MessageListener < TriggerTabIDReceived >
@@ -218,10 +215,6 @@ export class ChatController {
218215 return this . processViewDiff ( data )
219216 } )
220217
221- this . chatControllerMessageListeners . processOpenDiff . onMessage ( ( data ) => {
222- return this . processOpenDiff ( data )
223- } )
224-
225218 this . chatControllerMessageListeners . processCopyCodeToClipboard . onMessage ( ( data ) => {
226219 return this . processCopyCodeToClipboard ( data )
227220 } )
@@ -397,20 +390,6 @@ export class ChatController {
397390 } )
398391 }
399392
400- private async processOpenDiff ( message : OpenDiff ) {
401- const session = this . sessionStorage . getSession ( message . tabID )
402- const filePath = session . filePath ?? message . filePath
403- const fileExists = await fs . existsFile ( filePath )
404- // Check if fileExists=false, If yes, return instead of showing broken diff experience.
405- if ( ! session . tempFilePath ) {
406- return
407- }
408- const leftUri = fileExists ? vscode . Uri . file ( filePath ) : vscode . Uri . from ( { scheme : 'untitled' } )
409- const rightUri = vscode . Uri . file ( session . tempFilePath ?? filePath )
410- const fileName = path . basename ( filePath )
411- await vscode . commands . executeCommand ( 'vscode.diff' , leftUri , rightUri , `${ fileName } ${ amazonQTabSuffix } ` )
412- }
413-
414393 private async processAcceptCodeDiff ( message : CustomFormActionMessage ) {
415394 const session = this . sessionStorage . getSession ( message . tabID ?? '' )
416395 const filePath = session . filePath ?? ''
@@ -643,55 +622,70 @@ export class ChatController {
643622 }
644623 private async processFileClickMessage ( message : FileClick ) {
645624 const session = this . sessionStorage . getSession ( message . tabID )
646- const lineRanges = session . contexts . get ( message . filePath )
625+ // Check if user clicked on filePath in the contextList or filePath in the fileListTress and perform the functionality accordingly.
626+ if ( session . showDiffOnFileWrite ) {
627+ const filePath = session . filePath ?? message . filePath
628+ const fileExists = await fs . existsFile ( filePath )
629+ // Check if fileExists=false, If yes, return instead of showing broken diff experience.
630+ if ( ! session . tempFilePath ) {
631+ void vscode . window . showInformationMessage ( 'Generated code changes have been reviewed and processed.' )
632+ return
633+ }
634+ const leftUri = fileExists ? vscode . Uri . file ( filePath ) : vscode . Uri . from ( { scheme : 'untitled' } )
635+ const rightUri = vscode . Uri . file ( session . tempFilePath ?? filePath )
636+ const fileName = path . basename ( filePath )
637+ await vscode . commands . executeCommand ( 'vscode.diff' , leftUri , rightUri , `${ fileName } ${ amazonQTabSuffix } ` )
638+ } else {
639+ const lineRanges = session . contexts . get ( message . filePath )
647640
648- if ( ! lineRanges ) {
649- return
650- }
641+ if ( ! lineRanges ) {
642+ return
643+ }
651644
652- // Check if clicked file is in a different workspace root
653- const projectRoot =
654- session . relativePathToWorkspaceRoot . get ( message . filePath ) || workspace . workspaceFolders ?. [ 0 ] ?. uri . fsPath
655- if ( ! projectRoot ) {
656- return
657- }
658- let absoluteFilePath = path . join ( projectRoot , message . filePath )
645+ // Check if clicked file is in a different workspace root
646+ const projectRoot =
647+ session . relativePathToWorkspaceRoot . get ( message . filePath ) || workspace . workspaceFolders ?. [ 0 ] ?. uri . fsPath
648+ if ( ! projectRoot ) {
649+ return
650+ }
651+ let absoluteFilePath = path . join ( projectRoot , message . filePath )
659652
660- // Handle clicking on a user prompt outside the workspace
661- if ( message . filePath . endsWith ( promptFileExtension ) ) {
662- try {
663- await vscode . workspace . fs . stat ( vscode . Uri . file ( absoluteFilePath ) )
664- } catch {
665- absoluteFilePath = path . join ( getUserPromptsDirectory ( ) , message . filePath )
653+ // Handle clicking on a user prompt outside the workspace
654+ if ( message . filePath . endsWith ( promptFileExtension ) ) {
655+ try {
656+ await vscode . workspace . fs . stat ( vscode . Uri . file ( absoluteFilePath ) )
657+ } catch {
658+ absoluteFilePath = path . join ( getUserPromptsDirectory ( ) , message . filePath )
659+ }
666660 }
667- }
668661
669- try {
670- // Open the file in VSCode
671- const document = await workspace . openTextDocument ( absoluteFilePath )
672- const editor = await window . showTextDocument ( document , ViewColumn . Active )
673-
674- // Create multiple selections based on line ranges
675- const selections : Selection [ ] = lineRanges
676- . filter ( ( { first, second } ) => first !== - 1 && second !== - 1 )
677- . map ( ( { first, second } ) => {
678- const startPosition = new Position ( first - 1 , 0 ) // Convert 1-based to 0-based
679- const endPosition = new Position ( second - 1 , document . lineAt ( second - 1 ) . range . end . character )
680- return new Selection (
681- startPosition . line ,
682- startPosition . character ,
683- endPosition . line ,
684- endPosition . character
685- )
686- } )
662+ try {
663+ // Open the file in VSCode
664+ const document = await workspace . openTextDocument ( absoluteFilePath )
665+ const editor = await window . showTextDocument ( document , ViewColumn . Active )
666+
667+ // Create multiple selections based on line ranges
668+ const selections : Selection [ ] = lineRanges
669+ . filter ( ( { first, second } ) => first !== - 1 && second !== - 1 )
670+ . map ( ( { first, second } ) => {
671+ const startPosition = new Position ( first - 1 , 0 ) // Convert 1-based to 0-based
672+ const endPosition = new Position ( second - 1 , document . lineAt ( second - 1 ) . range . end . character )
673+ return new Selection (
674+ startPosition . line ,
675+ startPosition . character ,
676+ endPosition . line ,
677+ endPosition . character
678+ )
679+ } )
687680
688- // Apply multiple selections to the editor
689- if ( selections . length > 0 ) {
690- editor . selection = selections [ 0 ] // Set the first selection as active
691- editor . selections = selections // Apply multiple selections
692- editor . revealRange ( selections [ 0 ] , vscode . TextEditorRevealType . InCenter )
693- }
694- } catch ( error ) { }
681+ // Apply multiple selections to the editor
682+ if ( selections . length > 0 ) {
683+ editor . selection = selections [ 0 ] // Set the first selection as active
684+ editor . selections = selections // Apply multiple selections
685+ editor . revealRange ( selections [ 0 ] , vscode . TextEditorRevealType . InCenter )
686+ }
687+ } catch ( error ) { }
688+ }
695689 }
696690
697691 private processException ( e : any , tabID : string ) {
@@ -991,6 +985,7 @@ export class ChatController {
991985 private async processPromptMessageAsNewThread ( message : PromptMessage ) {
992986 const session = this . sessionStorage . getSession ( message . tabID )
993987 session . clearListOfReadFiles ( )
988+ session . setShowDiffOnFileWrite ( false )
994989 this . editorContextExtractor
995990 . extractContextForTrigger ( 'ChatMessage' )
996991 . then ( async ( context ) => {
0 commit comments