@@ -69,8 +69,6 @@ import {
6969} from '@aws/language-server-runtimes/protocol'
7070import { v4 as uuidv4 } from 'uuid'
7171import * as vscode from 'vscode'
72- import * as path from 'path'
73- import * as os from 'os'
7472import { Disposable , LanguageClient , Position , TextDocumentIdentifier } from 'vscode-languageclient'
7573import { AmazonQChatViewProvider } from './webviewProvider'
7674import {
@@ -83,9 +81,22 @@ import {
8381 SecurityIssueTreeViewProvider ,
8482 CodeWhispererConstants ,
8583} from 'aws-core-vscode/codewhisperer'
86- import { AmazonQPromptSettings , messages , openUrl , isTextEditor , globals , setContext } from 'aws-core-vscode/shared'
87- import { DefaultAmazonQAppInitContext , messageDispatcher , referenceLogText } from 'aws-core-vscode/amazonq'
88- import { fs } from 'aws-core-vscode/shared'
84+ import {
85+ amazonQDiffScheme ,
86+ AmazonQPromptSettings ,
87+ messages ,
88+ openUrl ,
89+ isTextEditor ,
90+ globals ,
91+ setContext ,
92+ } from 'aws-core-vscode/shared'
93+ import {
94+ DefaultAmazonQAppInitContext ,
95+ messageDispatcher ,
96+ EditorContentController ,
97+ ViewDiffMessage ,
98+ referenceLogText ,
99+ } from 'aws-core-vscode/amazonq'
89100import { telemetry } from 'aws-core-vscode/telemetry'
90101import { isValidResponseError } from './error'
91102import { decryptResponse , encryptRequest } from '../encryption'
@@ -150,7 +161,6 @@ export function registerMessageListeners(
150161 encryptionKey : Buffer
151162) {
152163 const chatStreamTokens = new Map < string , CancellationTokenSource > ( ) // tab id -> token
153- const tempDiffFiles = new Set < string > ( ) // track temp files for cleanup
154164
155165 // Keep track of pending chat options to send when webview UI is ready
156166 const pendingChatOptions = languageClient . initializeResult ?. awsServerCapabilities ?. chatOptions
@@ -654,50 +664,31 @@ export function registerMessageListeners(
654664 )
655665
656666 languageClient . onNotification ( openFileDiffNotificationType . method , async ( params : OpenFileDiffParams ) => {
657- const currentFileUri = vscode . Uri . parse ( params . originalFileUri )
658- const originalContent = params . originalFileContent ?? ''
659-
660- // Clean up any existing temp files first
661- for ( const tempFile of tempDiffFiles ) {
662- try {
663- await fs . delete ( tempFile )
664- } catch { }
665- }
666- tempDiffFiles . clear ( )
667-
668- // Create a temporary file with original content
669- const fileName = path . basename ( currentFileUri . fsPath )
670- const tempFileName = `${ path . parse ( fileName ) . name } _original_${ Date . now ( ) } ${ path . extname ( fileName ) } `
671- const tempFilePath = path . join ( os . tmpdir ( ) , tempFileName )
672-
673- try {
674- await fs . writeFile ( tempFilePath , originalContent )
675- const tempFileUri = vscode . Uri . file ( tempFilePath )
676- tempDiffFiles . add ( tempFilePath )
677-
678- // Open diff view with temp file (left) vs current file (right)
679- await vscode . commands . executeCommand (
680- 'vscode.diff' ,
681- tempFileUri ,
682- currentFileUri ,
683- `${ vscode . workspace . asRelativePath ( currentFileUri ) } (Original ↔ Current)` ,
684- { preview : false }
685- )
686-
687- // Clean up temp file when diff view is closed
688- const disposable = vscode . window . onDidChangeVisibleTextEditors ( ( ) => {
689- const isDiffViewOpen = vscode . window . visibleTextEditors . some (
690- ( editor ) => editor . document . uri . toString ( ) === tempFileUri . toString ( )
691- )
692- if ( ! isDiffViewOpen && tempDiffFiles . has ( tempFilePath ) ) {
693- fs . delete ( tempFilePath ) . catch ( ( ) => { } )
694- tempDiffFiles . delete ( tempFilePath )
695- disposable . dispose ( )
696- }
697- } )
698- } catch ( error ) {
699- languageClient . error ( `[VSCode Client] Failed to create temp file for diff: ${ error } ` )
667+ const ecc = new EditorContentController ( )
668+ const uri = params . originalFileUri
669+ const doc = await vscode . workspace . openTextDocument ( uri )
670+ const entireDocumentSelection = new vscode . Selection (
671+ new vscode . Position ( 0 , 0 ) ,
672+ new vscode . Position ( doc . lineCount - 1 , doc . lineAt ( doc . lineCount - 1 ) . text . length )
673+ )
674+ const viewDiffMessage : ViewDiffMessage = {
675+ context : {
676+ activeFileContext : {
677+ filePath : params . originalFileUri ,
678+ fileText : params . originalFileContent ?? '' ,
679+ fileLanguage : undefined ,
680+ matchPolicy : undefined ,
681+ } ,
682+ focusAreaContext : {
683+ selectionInsideExtendedCodeBlock : entireDocumentSelection ,
684+ codeBlock : '' ,
685+ extendedCodeBlock : '' ,
686+ names : undefined ,
687+ } ,
688+ } ,
689+ code : params . fileContent ?? '' ,
700690 }
691+ await ecc . viewDiff ( viewDiffMessage , amazonQDiffScheme )
701692 } )
702693
703694 languageClient . onNotification ( chatUpdateNotificationType . method , ( params : ChatUpdateParams ) => {
0 commit comments