diff options
| author | Conrad Irwin <[email protected]> | 2025-08-18 16:29:45 -0600 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-08-18 22:29:45 +0000 |
| commit | fb3ceb0da4e2cd636013c2c36a9c0016c01aa47f (patch) | |
| tree | 7aa43846dd88bd5acdb8898b0ccd2e685f2d5ece /packages/core/src/tools/edit.ts | |
| parent | 4394b6ab4fc86637b07fcd26b9a790c627d1e065 (diff) | |
Read and write files through Zed (#6169)
Co-authored-by: Agus Zubiaga <[email protected]>
Diffstat (limited to 'packages/core/src/tools/edit.ts')
| -rw-r--r-- | packages/core/src/tools/edit.ts | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/packages/core/src/tools/edit.ts b/packages/core/src/tools/edit.ts index 8d90dfe4..35e828b0 100644 --- a/packages/core/src/tools/edit.ts +++ b/packages/core/src/tools/edit.ts @@ -125,7 +125,9 @@ class EditToolInvocation implements ToolInvocation<EditToolParams, ToolResult> { | undefined = undefined; try { - currentContent = fs.readFileSync(params.file_path, 'utf8'); + currentContent = await this.config + .getFileSystemService() + .readTextFile(params.file_path); // Normalize line endings to LF for consistent processing. currentContent = currentContent.replace(/\r\n/g, '\n'); fileExists = true; @@ -339,7 +341,9 @@ class EditToolInvocation implements ToolInvocation<EditToolParams, ToolResult> { try { this.ensureParentDirectoriesExist(this.params.file_path); - fs.writeFileSync(this.params.file_path, editData.newContent, 'utf8'); + await this.config + .getFileSystemService() + .writeTextFile(this.params.file_path, editData.newContent); let displayResult: ToolResultDisplay; if (editData.isNewFile) { @@ -504,7 +508,9 @@ Expectation for required parameters: getFilePath: (params: EditToolParams) => params.file_path, getCurrentContent: async (params: EditToolParams): Promise<string> => { try { - return fs.readFileSync(params.file_path, 'utf8'); + return this.config + .getFileSystemService() + .readTextFile(params.file_path); } catch (err) { if (!isNodeError(err) || err.code !== 'ENOENT') throw err; return ''; @@ -512,7 +518,9 @@ Expectation for required parameters: }, getProposedContent: async (params: EditToolParams): Promise<string> => { try { - const currentContent = fs.readFileSync(params.file_path, 'utf8'); + const currentContent = await this.config + .getFileSystemService() + .readTextFile(params.file_path); return applyReplacement( currentContent, params.old_string, |
