Skip to content
TypeScript

fix(server): editing a file no longer forces a full search-index rescan (#24713)

Victor Vogelb6f066b14621
diff --git a/apps/server/src/workspace/WorkspaceFileSystem.test.ts b/apps/server/src/workspace/WorkspaceFileSystem.test.ts
index 0cf5524df4e..37d85a0fc68 100644
--- a/apps/server/src/workspace/WorkspaceFileSystem.test.ts
+++ b/apps/server/src/workspace/WorkspaceFileSystem.test.ts
@@ -428,6 +428,38 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceFileSystemLive", (i
}),
);
+ it.effect("saves over an existing file without rescanning the workspace", () =>
+ Effect.gen(function* () {
+ const workspaceFileSystem = yield* WorkspaceFileSystem.WorkspaceFileSystem;
+ const fileSystem = yield* FileSystem.FileSystem;
+ const path = yield* Path.Path;
+ const cwd = yield* makeTempDir;
+ yield* writeTextFile(cwd, "src/main.ts", "export {};\n");
+
+ yield* workspaceFileSystem.writeFile({
+ cwd,
+ relativePath: "src/main.ts",
+ contents: "export const edited = true;\n",
+ });
+
+ expect(yield* fileSystem.readFileString(path.join(cwd, "src/main.ts"))).toBe(
+ "export const edited = true;\n",
+ );
+ }).pipe(
+ Effect.provide(
+ Layer.fresh(WorkspaceFileSystem.layer).pipe(
+ Layer.provide(layerKnownWorkspacesTest),
+ Layer.provide(WorkspacePaths.layer),
+ Layer.provide(
+ Layer.mock(WorkspaceEntries.WorkspaceEntries)({
+ refresh: () => Effect.die("An overwrite rescanned the workspace."),
+ }),
+ ),
+ ),
+ ),
+ ),
+ );
+
it.effect("rejects writes outside the workspace root", () =>
Effect.gen(function* () {
const workspaceFileSystem = yield* WorkspaceFileSystem.WorkspaceFileSystem;
diff --git a/apps/server/src/workspace/WorkspaceFileSystem.ts b/apps/server/src/workspace/WorkspaceFileSystem.ts
index 7107cd99631..053360572b3 100644
--- a/apps/server/src/workspace/WorkspaceFileSystem.ts
+++ b/apps/server/src/workspace/WorkspaceFileSystem.ts
@@ -531,6 +531,9 @@ export const make = Effect.gen(function* () {
yield* knownWorkspaces.assertContains(input.cwd);
const target = yield* resolveWriteTarget(input);
const realTargetPath = target.realTargetPath;
+ const replacesFile = yield* fileSystem
+ .exists(realTargetPath)
+ .pipe(Effect.orElseSucceed(() => false));
yield* fileSystem.makeDirectory(path.dirname(realTargetPath), { recursive: true }).pipe(
Effect.mapError(
@@ -565,7 +568,12 @@ export const make = Effect.gen(function* () {
cause,
}),
});
- yield* workspaceEntries.refresh(input.cwd);
+ // Editor autosave overwrites existing files, which leaves the indexed paths unchanged, and
+ // fff's watcher applies the new contents on its own. A forced rescan re-walks the whole
+ // workspace, and the save would wait for it.
+ if (!replacesFile) {
+ yield* workspaceEntries.refresh(input.cwd);
+ }
return { relativePath: target.relativePath };
});