diff --git a/src/core/tools/WriteToFileTool.ts b/src/core/tools/WriteToFileTool.ts index f7d7d2c6a6..fe36297dde 100644 --- a/src/core/tools/WriteToFileTool.ts +++ b/src/core/tools/WriteToFileTool.ts @@ -287,7 +287,26 @@ export class WriteToFileTool extends BaseTool<"write_to_file"> { return } catch (error) { - await handleError("writing file", error as Error) + const err = error as Error + // Check if this is a VS Code file size limit error + if (err?.message?.includes("Files above") && err?.message?.includes("MB")) { + // The file was likely written successfully, but VS Code can't display it + // Provide a more helpful message to the user + await task.say( + "text", + `The file was saved successfully, but it exceeds VS Code's display size limit for extensions. The file operation completed successfully.`, + ) + pushToolResult( + formatResponse.toolResult( + `File saved successfully. Note: File exceeds VS Code's display size limit but the operation completed.`, + [], + ), + ) + await task.diffViewProvider.reset() + return + } + // For other errors, use the standard error handling + await handleError("writing file", err) await task.diffViewProvider.reset() return } diff --git a/src/integrations/editor/DiffViewProvider.ts b/src/integrations/editor/DiffViewProvider.ts index 983307d919..e20e38dad6 100644 --- a/src/integrations/editor/DiffViewProvider.ts +++ b/src/integrations/editor/DiffViewProvider.ts @@ -211,7 +211,19 @@ export class DiffViewProvider { await updatedDocument.save() } - await vscode.window.showTextDocument(vscode.Uri.file(absolutePath), { preview: false, preserveFocus: true }) + try { + await vscode.window.showTextDocument(vscode.Uri.file(absolutePath), { preview: false, preserveFocus: true }) + } catch (error: any) { + // Handle VS Code/Cursor file size limit error + if (error?.message?.includes("Files above") && error?.message?.includes("MB")) { + // File was saved successfully but VS Code can't display it due to size limit + // This is not a critical error - the file operation succeeded + console.warn(`File ${absolutePath} exceeds VS Code display size limit but was saved successfully`) + } else { + // Re-throw other errors + throw error + } + } await this.closeAllDiffViews() // Getting diagnostics before and after the file edit is a better approach than @@ -436,10 +448,23 @@ export class DiffViewProvider { await updatedDocument.save() if (this.documentWasOpen) { - await vscode.window.showTextDocument(vscode.Uri.file(absolutePath), { - preview: false, - preserveFocus: true, - }) + try { + await vscode.window.showTextDocument(vscode.Uri.file(absolutePath), { + preview: false, + preserveFocus: true, + }) + } catch (error: any) { + // Handle VS Code/Cursor file size limit error + if (error?.message?.includes("Files above") && error?.message?.includes("MB")) { + // File was reverted successfully but VS Code can't display it due to size limit + console.warn( + `File ${absolutePath} exceeds VS Code display size limit but was reverted successfully`, + ) + } else { + // Re-throw other errors + throw error + } + } } await this.closeAllDiffViews() @@ -698,10 +723,23 @@ export class DiffViewProvider { // When openFile is false (PREVENT_FOCUS_DISRUPTION enabled), we only open in memory if (openFile) { // Show the document in the editor - await vscode.window.showTextDocument(vscode.Uri.file(absolutePath), { - preview: false, - preserveFocus: true, - }) + try { + await vscode.window.showTextDocument(vscode.Uri.file(absolutePath), { + preview: false, + preserveFocus: true, + }) + } catch (error: any) { + // Handle VS Code/Cursor file size limit error + if (error?.message?.includes("Files above") && error?.message?.includes("MB")) { + // File was saved successfully but VS Code can't display it due to size limit + // This is not a critical error - the file operation succeeded + console.warn(`File ${absolutePath} exceeds VS Code display size limit but was saved successfully`) + // Continue with diagnostics check even if we can't display the file + } else { + // Re-throw other errors + throw error + } + } } else { // Just open the document in memory to trigger diagnostics without showing it const doc = await vscode.workspace.openTextDocument(vscode.Uri.file(absolutePath))