|
1 | 1 | // @effect-diagnostics nodeBuiltinImport:off |
2 | 2 | import * as NodeFSP from "node:fs/promises"; |
3 | 3 | import * as NodeServices from "@effect/platform-node/NodeServices"; |
| 4 | +import { FileFinder } from "@ff-labs/fff-node"; |
4 | 5 | import { it, afterEach, describe, expect } from "@effect/vitest"; |
5 | 6 | import * as Effect from "effect/Effect"; |
6 | 7 | import * as FileSystem from "effect/FileSystem"; |
@@ -673,6 +674,53 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceEntries", (it) => { |
673 | 674 | expect(match.lineContent.slice(range.start, range.end)).toBe("wörld"); |
674 | 675 | }), |
675 | 676 | ); |
| 677 | + |
| 678 | + it.effect("keeps answering from the live index when a refresh outlasts the scan wait", () => |
| 679 | + Effect.gen(function* () { |
| 680 | + const cwd = yield* makeTempDir({ prefix: "t3code-workspace-content-refresh-" }); |
| 681 | + yield* writeTextFile(cwd, "src/notes.ts", "const needle = 1;\n"); |
| 682 | + let scansOutlastWait = false; |
| 683 | + let finders = 0; |
| 684 | + let rescans = 0; |
| 685 | + const createFinder = FileFinder.create.bind(FileFinder); |
| 686 | + vi.spyOn(FileFinder, "create").mockImplementation((options) => { |
| 687 | + const created = createFinder(options); |
| 688 | + if (created.ok) { |
| 689 | + const finder = created.value; |
| 690 | + finders += 1; |
| 691 | + const scanFiles = finder.scanFiles.bind(finder); |
| 692 | + finder.scanFiles = () => { |
| 693 | + rescans += 1; |
| 694 | + return scanFiles(); |
| 695 | + }; |
| 696 | + const waitForIndexReady = finder.waitForIndexReady.bind(finder); |
| 697 | + finder.waitForIndexReady = (timeoutMs) => |
| 698 | + scansOutlastWait |
| 699 | + ? Promise.resolve({ ok: true, value: false }) |
| 700 | + : waitForIndexReady(timeoutMs); |
| 701 | + } |
| 702 | + return created; |
| 703 | + }); |
| 704 | + const workspaceEntries = yield* WorkspaceEntries.WorkspaceEntries; |
| 705 | + const searchNeedle = workspaceEntries.searchContents({ |
| 706 | + cwd, |
| 707 | + query: "needle", |
| 708 | + limit: 100, |
| 709 | + caseSensitive: true, |
| 710 | + wholeWord: false, |
| 711 | + useRegex: false, |
| 712 | + }); |
| 713 | + yield* searchNeedle; |
| 714 | + |
| 715 | + scansOutlastWait = true; |
| 716 | + yield* workspaceEntries.refresh(cwd); |
| 717 | + const result = yield* searchNeedle; |
| 718 | + |
| 719 | + expect(result.matches.map((match) => match.path)).toEqual(["src/notes.ts"]); |
| 720 | + // The second search ran on the rescanned live finder, not a rebuild. |
| 721 | + expect({ finders, rescans }).toEqual({ finders: 1, rescans: 1 }); |
| 722 | + }), |
| 723 | + ); |
676 | 724 | }); |
677 | 725 |
|
678 | 726 | describe("browse", () => { |
|
0 commit comments