11import * as vscode from "vscode"
2- import * as fs from "fs"
2+ import * as fs from "fs/promises "
33import * as path from "path"
44import { getNonce } from "./util"
55import { DiffContent , DiffBlock , ApprovalAction } from "./types"
@@ -112,20 +112,25 @@ export class DiffApprovePanel {
112112 private async _loadDiffContent ( ) : Promise < void > {
113113 try {
114114 // Read file contents
115- const file1Content = fs . readFileSync ( this . _file1Uri . fsPath , "utf8" )
116- const file2Content = fs . readFileSync ( this . _file2Uri . fsPath , "utf8" )
117-
118- // Calculate diff using our diff algorithm
119- const diffs = await this . _computeDiff ( file1Content , file2Content )
115+ const file1Content = await fs . readFile ( this . _file1Uri . fsPath , "utf8" )
116+ const file2Content = await fs . readFile ( this . _file2Uri . fsPath , "utf8" )
120117
118+ // Compute diff
121119 this . _diffContent = {
122120 file1 : path . basename ( this . _file1Uri . fsPath ) ,
123121 file2 : path . basename ( this . _file2Uri . fsPath ) ,
124- blocks : diffs ,
122+ blocks : await this . _computeDiff ( file1Content , file2Content ) ,
125123 }
126- } catch ( err ) {
124+
125+ // Update webview
126+ this . _panel . webview . postMessage ( {
127+ command : "contentLoaded" ,
128+ content : this . _diffContent ,
129+ pendingBlocks : Array . from ( this . _pendingBlocks ) ,
130+ } )
131+ } catch ( error ) {
127132 vscode . window . showErrorMessage (
128- `Error loading diff content: ${ err instanceof Error ? err . message : String ( err ) } ` ,
133+ `Error loading diff content: ${ error instanceof Error ? error . message : String ( error ) } ` ,
129134 )
130135 }
131136 }
@@ -328,7 +333,7 @@ export class DiffApprovePanel {
328333 // vscode.window.showInformationMessage(`Approved change for block ${blockId}`)
329334 } else if ( action === "deny" ) {
330335 // For deny, we revert the change by applying the left side content to the right file
331- const file2Content = fs . readFileSync ( this . _file2Uri . fsPath , "utf8" )
336+ const file2Content = await fs . readFile ( this . _file2Uri . fsPath , "utf8" )
332337 const lines = file2Content . split ( "\n" )
333338
334339 // Apply the revert
@@ -348,7 +353,7 @@ export class DiffApprovePanel {
348353 }
349354
350355 // Write back the file
351- fs . writeFileSync ( this . _file2Uri . fsPath , lines . join ( "\n" ) , "utf8" )
356+ await fs . writeFile ( this . _file2Uri . fsPath , lines . join ( "\n" ) , "utf8" )
352357 this . _pendingBlocks . delete ( blockId )
353358 // vscode.window.showInformationMessage(`Denied change for block ${blockId}, reverted to original`)
354359
@@ -365,9 +370,9 @@ export class DiffApprovePanel {
365370
366371 // Check if all blocks have been processed
367372 this . _checkIfAllBlocksProcessed ( )
368- } catch ( err ) {
373+ } catch ( error ) {
369374 vscode . window . showErrorMessage (
370- `Error handling approval: ${ err instanceof Error ? err . message : String ( err ) } ` ,
375+ `Error handling approval: ${ error instanceof Error ? error . message : String ( error ) } ` ,
371376 )
372377 }
373378 }
0 commit comments