From f1713e4b9954b525ea6c56d9e25b4bf92dcfcad5 Mon Sep 17 00:00:00 2001 From: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com> Date: Tue, 3 Sep 2024 10:16:44 -0400 Subject: [PATCH] Add fallback for if temp file can't be saved --- src/ClaudeDev.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/ClaudeDev.ts b/src/ClaudeDev.ts index 6d9d991bf9..a6607744e4 100644 --- a/src/ClaudeDev.ts +++ b/src/ClaudeDev.ts @@ -813,17 +813,18 @@ export class ClaudeDev { } // Create a temporary file with the new content + const fileName = path.basename(absolutePath) const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "claude-dev-")) - const tempFilePath = path.join(tempDir, path.basename(absolutePath)) + const tempFilePath = path.join(tempDir, fileName) await fs.writeFile(tempFilePath, newContent) vscode.commands.executeCommand( "vscode.diff", - vscode.Uri.parse(`claude-dev-diff:${path.basename(absolutePath)}`).with({ + vscode.Uri.parse(`claude-dev-diff:${fileName}`).with({ query: Buffer.from(originalContent).toString("base64"), }), vscode.Uri.file(tempFilePath), - `${path.basename(absolutePath)}: ${fileExists ? "Original ↔ Claude's Changes" : "New File"} (Editable)` + `${fileName}: ${fileExists ? "Original ↔ Claude's Changes" : "New File"} (Editable)` ) let userResponse: { @@ -858,6 +859,15 @@ export class ClaudeDev { console.log("saving diff document") await diffDocument.save() } + // some users report a bug where the diff editor doesnt save the file automatically, so this is a workaround + if (!diffDocument) { + const savedResult = await vscode.workspace.save(vscode.Uri.file(tempFilePath)) + // savedResult will be undefined if file was not found or couldn't be saved + if (!savedResult) { + // last resort is saving everything + await vscode.workspace.saveAll(false) + } + } if (response !== "yesButtonTapped") { await this.closeDiffViews()