Browse Source

Make reveal range operation safer

Saoud Rizwan 1 year ago
parent
commit
e5979eed3c
2 changed files with 20 additions and 7 deletions
  1. 1 1
      package.json
  2. 19 6
      src/ClaudeDev.ts

+ 1 - 1
package.json

@@ -2,7 +2,7 @@
   "name": "claude-dev",
   "name": "claude-dev",
   "displayName": "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.",
   "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.6.3",
+  "version": "1.6.4",
   "icon": "icons/icon.png",
   "icon": "icons/icon.png",
   "galleryBanner": {
   "galleryBanner": {
     "color": "#F9E1D2",
     "color": "#F9E1D2",

+ 19 - 6
src/ClaudeDev.ts

@@ -855,11 +855,24 @@ export class ClaudeDev {
 					if (part.added || part.removed) {
 					if (part.added || part.removed) {
 						const startLine = lineCount + 1
 						const startLine = lineCount + 1
 						const endLine = lineCount + (part.count || 0)
 						const endLine = lineCount + (part.count || 0)
-						vscode.window.activeTextEditor?.revealRange(
-							// + 3 to move the editor up slightly as this looks better
-							new vscode.Range(new vscode.Position(startLine, 0), new vscode.Position(endLine + 3, 0)),
-							vscode.TextEditorRevealType.InCenter
-						)
+						const activeEditor = vscode.window.activeTextEditor
+						if (activeEditor) {
+							try {
+								activeEditor.revealRange(
+									// + 3 to move the editor up slightly as this looks better
+									new vscode.Range(
+										new vscode.Position(startLine, 0),
+										new vscode.Position(
+											Math.min(endLine + 3, activeEditor.document.lineCount - 1),
+											0
+										)
+									),
+									vscode.TextEditorRevealType.InCenter
+								)
+							} catch (error) {
+								console.error(`Error revealing range for ${absolutePath}: ${error}`)
+							}
+						}
 						break
 						break
 					}
 					}
 					lineCount += part.count || 0
 					lineCount += part.count || 0
@@ -1558,7 +1571,7 @@ ${this.customInstructions.trim()}
 			const { response, text, images } = await this.ask(
 			const { response, text, images } = await this.ask(
 				"mistake_limit_reached",
 				"mistake_limit_reached",
 				this.api.getModel().id.includes("claude")
 				this.api.getModel().id.includes("claude")
-					? `This may indicate a failure in his thought process or inability to use a tool properly, which can be mitigated with some user guidance (e.g. "let's try breaking this large file down into smaller files").`
+					? `This may indicate a failure in his thought process or inability to use a tool properly, which can be mitigated with some user guidance (e.g. "Try breaking down the task into smaller steps").`
 					: "Claude Dev uses complex prompts and iterative task execution that may be challenging for less capable models. For best results, it's recommended to use Claude 3.5 Sonnet for its advanced agentic coding capabilities."
 					: "Claude Dev uses complex prompts and iterative task execution that may be challenging for less capable models. For best results, it's recommended to use Claude 3.5 Sonnet for its advanced agentic coding capabilities."
 			)
 			)
 			if (response === "messageResponse") {
 			if (response === "messageResponse") {