Add project file picker (⌘P) and project content search (⇧⌘F) (#4855)

Co-authored-by: Claude Fable 5 <[email protected]>
Co-authored-by: Julius Marminge <[email protected]>
This commit is contained in:
authored and GitHub committed 2026-07-30 16:39:15 +02:00
1 parent 1877237c7a
commit abc409c2d4
39 files changed
+2932 -480

No files matched your search

@@ -1,4 +1,4 @@
import { FileFinder } from "@ff-labs/fff-node";
import { FileFinder, type GrepCursor, type GrepOptions, type GrepResult } from "@ff-labs/fff-node";
import { afterEach, expect, it } from "@effect/vitest";
import * as Cause from "effect/Cause";
import * as Effect from "effect/Effect";
@@ -51,6 +51,41 @@ it.effect("keeps returned FileFinder creation diagnostics out of the cause chain
}),
);
it.effect("waits for the full content index warmup before returning", () =>
Effect.gen(function* () {
const waitForIndexReady = vi.fn(async () => ({ ok: true as const, value: true }));
const finder = {
destroy: vi.fn(),
waitForIndexReady,
} as unknown as FileFinder;
vi.spyOn(FileFinder, "create").mockReturnValueOnce({ ok: true, value: finder });
yield* Effect.scoped(WorkspaceSearchIndex.make("/workspace/project", "content"));
expect(waitForIndexReady).toHaveBeenCalledWith(15_000);
}),
);
it.effect("preserves a full-index warmup timeout as a structured error", () =>
Effect.gen(function* () {
const finder = {
destroy: vi.fn(),
waitForIndexReady: vi.fn(async () => ({ ok: true as const, value: false })),
} as unknown as FileFinder;
vi.spyOn(FileFinder, "create").mockReturnValueOnce({ ok: true, value: finder });
const error = yield* Effect.flip(
Effect.scoped(WorkspaceSearchIndex.make("/workspace/project", "content")),
);
expect(error).toMatchObject({
_tag: "WorkspaceSearchIndexScanTimedOut",
cwd: "/workspace/project",
timeout: "15 seconds",
});
}),
);
it.effect("preserves FileFinder destroy failures as structured defects", () =>
Effect.gen(function* () {
const cause = new Error("native destroy failed");
@@ -58,7 +93,7 @@ it.effect("preserves FileFinder destroy failures as structured defects", () =>
destroy: vi.fn(() => {
throw cause;
}),
isScanning: vi.fn(() => false),
waitForIndexReady: vi.fn(async () => ({ ok: true as const, value: true })),
} as unknown as FileFinder;
vi.spyOn(FileFinder, "create").mockReturnValueOnce({ ok: true, value: finder });
@@ -85,12 +120,16 @@ it.effect("preserves search and refresh failures with operation context", () =>
Effect.gen(function* () {
const searchCause = new Error("native search failed");
const refreshCause = new Error("native scan failed");
const contentSearchCause = new Error("native grep failed");
const finder = {
destroy: vi.fn(),
isScanning: vi.fn(() => false),
waitForIndexReady: vi.fn(async () => ({ ok: true as const, value: true })),
mixedSearch: vi.fn(() => {
throw searchCause;
}),
grep: vi.fn(() => {
throw contentSearchCause;
}),
scanFiles: vi.fn(() => {
throw refreshCause;
}),
@@ -100,6 +139,15 @@ it.effect("preserves search and refresh failures with operation context", () =>
const searchIndex = yield* WorkspaceSearchIndex.make("/workspace/project");
const query = "authorization: Bearer secret-token";
const searchError = yield* Effect.flip(searchIndex.search(query, 3));
const contentSearchError = yield* Effect.flip(
searchIndex.searchContents({
query,
limit: 3,
caseSensitive: false,
wholeWord: false,
useRegex: false,
}),
);
const refreshError = yield* Effect.flip(searchIndex.refresh());
expect(searchError).toMatchObject({
@@ -112,6 +160,16 @@ it.effect("preserves search and refresh failures with operation context", () =>
});
expect(searchError).not.toHaveProperty("query");
expect(searchError.message).not.toMatch(/Bearer|secret-token/);
expect(contentSearchError).toMatchObject({
_tag: "WorkspaceSearchIndexSearchFailed",
cwd: "/workspace/project",
queryLength: query.length,
pageSize: 3,
reason: "FileFinder.grep threw unexpectedly.",
cause: contentSearchCause,
});
expect(contentSearchError).not.toHaveProperty("query");
expect(contentSearchError.message).not.toMatch(/Bearer|secret-token/);
expect(refreshError).toMatchObject({
_tag: "WorkspaceSearchIndexRefreshFailed",
cwd: "/workspace/project",
@@ -127,7 +185,7 @@ it.effect("keeps returned search diagnostics out of the cause chain", () =>
Effect.gen(function* () {
const finder = {
destroy: vi.fn(),
isScanning: vi.fn(() => false),
waitForIndexReady: vi.fn(async () => ({ ok: true as const, value: true })),
mixedSearch: vi.fn(() => ({ ok: false, error: "native query rejected" })),
scanFiles: vi.fn(() => ({ ok: false, error: "native refresh rejected" })),
} as unknown as FileFinder;
@@ -157,3 +215,80 @@ it.effect("keeps returned search diagnostics out of the cause chain", () =>
}),
),
);
it.effect("continues whole-word searches after a filtered grep page", () =>
Effect.scoped(
Effect.gen(function* () {
const nextCursor = {
__brand: "GrepCursor",
_offset: 1,
} as GrepCursor;
const grepResult = (
lineContent: string,
matchRanges: Array<[number, number]>,
cursor: GrepCursor | null,
): GrepResult => ({
items: [
{
relativePath: "src/words.ts",
fileName: "words.ts",
gitStatus: "unmodified",
size: lineContent.length,
modified: 0,
isBinary: false,
totalFrecencyScore: 0,
accessFrecencyScore: 0,
modificationFrecencyScore: 0,
lineNumber: 1,
col: 0,
byteOffset: 0,
lineContent,
matchRanges,
},
],
totalMatched: 1,
totalFilesSearched: 1,
totalFiles: 1,
filteredFileCount: 1,
nextCursor: cursor,
});
const grep = vi.fn((_query: string, options?: GrepOptions) =>
options?.cursor
? { ok: true as const, value: grepResult("needle", [[0, 6]], null) }
: {
ok: true as const,
value: grepResult("needleSuffix", [[0, 6]], nextCursor),
},
);
const finder = {
destroy: vi.fn(),
waitForIndexReady: vi.fn(async () => ({ ok: true as const, value: true })),
grep,
} as unknown as FileFinder;
vi.spyOn(FileFinder, "create").mockReturnValueOnce({ ok: true, value: finder });
const searchIndex = yield* WorkspaceSearchIndex.make("/workspace/project", "content");
const result = yield* searchIndex.searchContents({
query: "needle",
limit: 1,
caseSensitive: true,
wholeWord: true,
useRegex: false,
});
expect(result).toEqual({
matches: [
{
path: "src/words.ts",
lineNumber: 1,
lineContent: "needle",
matchRanges: [{ start: 0, end: 6 }],
},
],
truncated: false,
});
expect(grep).toHaveBeenCalledTimes(2);
expect(grep.mock.calls[1]?.[1]?.cursor).toBe(nextCursor);
}),
),
);