Read and write files through Zed (#6169)

Co-authored-by: Agus Zubiaga <agus@zed.dev>
This commit is contained in:
Conrad Irwin
2025-08-18 16:29:45 -06:00
committed by GitHub
parent 4394b6ab4f
commit fb3ceb0da4
17 changed files with 268 additions and 50 deletions

View File

@@ -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,