Browse Source

Fix bug where write_to_file sometimes closed claude dev tab

Saoud Rizwan 1 year ago
parent
commit
93073512ce
2 changed files with 13 additions and 3 deletions
  1. 1 1
      package.json
  2. 12 2
      src/ClaudeDev.ts

+ 1 - 1
package.json

@@ -2,7 +2,7 @@
   "name": "claude-dev",
   "displayName": "Claude Dev",
   "description": "Autonomous coding agent right in your IDE, capable of creating/editing files, executing commands, and more with your permission every step of the way.",
-  "version": "1.5.27",
+  "version": "1.5.28",
   "icon": "icon.png",
   "engines": {
     "vscode": "^1.84.0"

+ 12 - 2
src/ClaudeDev.ts

@@ -875,15 +875,25 @@ export class ClaudeDev {
 				// ensure that the in-memory doc is active editor (this seems to fail on windows machines if its already active, so ignoring if there's an error as it's likely it's already active anyways)
 				try {
 					await vscode.window.showTextDocument(inMemoryDocument, {
-						preview: true,
+						preview: false, // ensures it opens in non-preview tab (preview tabs are easily replaced)
 						preserveFocus: false,
 					})
 					// await vscode.window.showTextDocument(inMemoryDocument.uri, { preview: true, preserveFocus: false })
 				} catch (error) {
 					console.log(`Could not open editor for ${absolutePath}: ${error}`)
 				}
+				// Wait for the in-memory document to become the active editor (sometimes vscode timing issues happen and this would accidentally close claude dev!)
+				await pWaitFor(
+					() => {
+						return vscode.window.activeTextEditor?.document === inMemoryDocument
+					},
+					{ timeout: 5000, interval: 100 }
+				)
+
+				if (vscode.window.activeTextEditor?.document === inMemoryDocument) {
+					await vscode.commands.executeCommand("workbench.action.revertAndCloseActiveEditor") // allows us to close the untitled doc without being prompted to save it
+				}
 
-				await vscode.commands.executeCommand("workbench.action.revertAndCloseActiveEditor") // allows us to close the untitled doc without being prompted to save it
 				await this.closeDiffViews()
 			}