Skip to content

Commit b6f066b

Browse files
only21milclaude
andauthored
fix(server): editing a file no longer forces a full search-index rescan (#24713)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent e6fccee commit b6f066b

2 files changed

Lines changed: 41 additions & 1 deletion

File tree

‎apps/server/src/workspace/WorkspaceFileSystem.test.ts‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,38 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceFileSystemLive", (i
428428
}),
429429
);
430430

431+
it.effect("saves over an existing file without rescanning the workspace", () =>
432+
Effect.gen(function* () {
433+
const workspaceFileSystem = yield* WorkspaceFileSystem.WorkspaceFileSystem;
434+
const fileSystem = yield* FileSystem.FileSystem;
435+
const path = yield* Path.Path;
436+
const cwd = yield* makeTempDir;
437+
yield* writeTextFile(cwd, "src/main.ts", "export {};\n");
438+
439+
yield* workspaceFileSystem.writeFile({
440+
cwd,
441+
relativePath: "src/main.ts",
442+
contents: "export const edited = true;\n",
443+
});
444+
445+
expect(yield* fileSystem.readFileString(path.join(cwd, "src/main.ts"))).toBe(
446+
"export const edited = true;\n",
447+
);
448+
}).pipe(
449+
Effect.provide(
450+
Layer.fresh(WorkspaceFileSystem.layer).pipe(
451+
Layer.provide(layerKnownWorkspacesTest),
452+
Layer.provide(WorkspacePaths.layer),
453+
Layer.provide(
454+
Layer.mock(WorkspaceEntries.WorkspaceEntries)({
455+
refresh: () => Effect.die("An overwrite rescanned the workspace."),
456+
}),
457+
),
458+
),
459+
),
460+
),
461+
);
462+
431463
it.effect("rejects writes outside the workspace root", () =>
432464
Effect.gen(function* () {
433465
const workspaceFileSystem = yield* WorkspaceFileSystem.WorkspaceFileSystem;

‎apps/server/src/workspace/WorkspaceFileSystem.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,9 @@ export const make = Effect.gen(function* () {
531531
yield* knownWorkspaces.assertContains(input.cwd);
532532
const target = yield* resolveWriteTarget(input);
533533
const realTargetPath = target.realTargetPath;
534+
const replacesFile = yield* fileSystem
535+
.exists(realTargetPath)
536+
.pipe(Effect.orElseSucceed(() => false));
534537

535538
yield* fileSystem.makeDirectory(path.dirname(realTargetPath), { recursive: true }).pipe(
536539
Effect.mapError(
@@ -565,7 +568,12 @@ export const make = Effect.gen(function* () {
565568
cause,
566569
}),
567570
});
568-
yield* workspaceEntries.refresh(input.cwd);
571+
// Editor autosave overwrites existing files, which leaves the indexed paths unchanged, and
572+
// fff's watcher applies the new contents on its own. A forced rescan re-walks the whole
573+
// workspace, and the save would wait for it.
574+
if (!replacesFile) {
575+
yield* workspaceEntries.refresh(input.cwd);
576+
}
569577
return { relativePath: target.relativePath };
570578
});
571579

0 commit comments

Comments
 (0)