Skip to content

Commit d9c9065

Browse files
committed
Fixed recs
1 parent d82502f commit d9c9065

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

src/integrations/diff-approve/diffApprovePanel.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as vscode from "vscode"
2-
import * as fs from "fs"
2+
import * as fs from "fs/promises"
33
import * as path from "path"
44
import { getNonce } from "./util"
55
import { 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
}
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1+
import crypto from "crypto"
2+
13
/**
24
* Generates a nonce string for use in Content Security Policy
35
*/
46
export function getNonce(): string {
5-
let text = ""
6-
const possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
7-
for (let i = 0; i < 32; i++) {
8-
text += possible.charAt(Math.floor(Math.random() * possible.length))
9-
}
10-
return text
7+
return crypto.randomBytes(32).toString("base64url")
118
}

0 commit comments

Comments
 (0)