Skip to content

Commit e5cdf92

Browse files
committed
feat(node & bun): Expose pageSize option
1 parent 97c1812 commit e5cdf92

7 files changed

Lines changed: 58 additions & 6 deletions

File tree

packages/fff-bun/src/finder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ export class FileFinder {
321321
options?.maxMatchesPerFile ?? 0,
322322
options?.smartCase ?? true,
323323
options?.cursor?._offset ?? 0,
324-
0, // page_limit (0 = default 50)
324+
options?.pageSize ?? 0,
325325
options?.timeBudgetMs ?? 0,
326326
options?.beforeContext ?? 0,
327327
options?.afterContext ?? 0,
@@ -370,7 +370,7 @@ export class FileFinder {
370370
options.maxMatchesPerFile ?? 0,
371371
options.smartCase ?? true,
372372
options.cursor?._offset ?? 0,
373-
0, // page_limit (0 = default 50)
373+
options.pageSize ?? 0,
374374
options.timeBudgetMs ?? 0,
375375
options.beforeContext ?? 0,
376376
options.afterContext ?? 0,

packages/fff-bun/src/index.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,28 @@ describe("FileFinder - Full Lifecycle", () => {
199199
}
200200
});
201201

202+
test("grep respects pageSize option", () => {
203+
// Cap to one match per file so pageSize bounds the total deterministically.
204+
const unbounded = finder.grep("import", {
205+
mode: "plain",
206+
maxMatchesPerFile: 1,
207+
});
208+
expect(unbounded.ok).toBe(true);
209+
if (!unbounded.ok) return;
210+
expect(unbounded.value.items.length).toBeGreaterThan(2);
211+
212+
const limited = finder.grep("import", {
213+
mode: "plain",
214+
maxMatchesPerFile: 1,
215+
pageSize: 2,
216+
});
217+
expect(limited.ok).toBe(true);
218+
if (!limited.ok) return;
219+
expect(limited.value.items.length).toBeLessThanOrEqual(2);
220+
expect(limited.value.items.length).toBeLessThan(unbounded.value.items.length);
221+
expect(limited.value.nextCursor).not.toBeNull();
222+
});
223+
202224
test("grep fuzzy mode returns results with scores", () => {
203225
// Intentional typo: "depdnency" instead of "dependency" to exercise fuzzy matching
204226
const result = finder.grep("depdnency", {

packages/fff-bun/src/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,8 @@ export interface GrepOptions {
361361
beforeContext?: number;
362362
/** Number of context lines to include after each match (default: 0) */
363363
afterContext?: number;
364+
/** Maximum matches to return in this page across all files (default: 50) */
365+
pageSize?: number;
364366
}
365367

366368
/**
@@ -457,4 +459,6 @@ export interface MultiGrepOptions {
457459
beforeContext?: number;
458460
/** Number of context lines to include after each match (default: 0) */
459461
afterContext?: number;
462+
/** Maximum matches to return in this page across all files (default: 50) */
463+
pageSize?: number;
460464
}

packages/fff-node/src/finder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ export class FileFinder {
321321
options?.maxMatchesPerFile ?? 0,
322322
options?.smartCase ?? true,
323323
options?.cursor?._offset ?? 0,
324-
0, // page_limit (0 = default 50)
324+
options?.pageSize ?? 0,
325325
options?.timeBudgetMs ?? 0,
326326
options?.beforeContext ?? 0,
327327
options?.afterContext ?? 0,
@@ -370,7 +370,7 @@ export class FileFinder {
370370
options.maxMatchesPerFile ?? 0,
371371
options.smartCase ?? true,
372372
options.cursor?._offset ?? 0,
373-
0, // page_limit (0 = default 50)
373+
options.pageSize ?? 0,
374374
options.timeBudgetMs ?? 0,
375375
options.beforeContext ?? 0,
376376
options.afterContext ?? 0,

packages/fff-node/src/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,8 @@ export interface GrepOptions {
364364
* without a TS-side regex port. (default: false)
365365
*/
366366
classifyDefinitions?: boolean;
367+
/** Maximum matches to return in this page across all files (default: 50) */
368+
pageSize?: number;
367369
}
368370

369371
/**
@@ -467,4 +469,6 @@ export interface MultiGrepOptions {
467469
* and expose it via `GrepMatch.isDefinition`. (default: false)
468470
*/
469471
classifyDefinitions?: boolean;
472+
/** Maximum matches to return in this page across all files (default: 50) */
473+
pageSize?: number;
470474
}

packages/fff-node/test/e2e.mjs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,29 @@ describe("fff-node", { concurrency: 1 }, () => {
170170
}
171171
});
172172

173+
it("respects pageSize", () => {
174+
// Cap to one match per file so pageSize bounds the total deterministically.
175+
const unbounded = finder.grep("fn", { mode: "plain", maxMatchesPerFile: 1 });
176+
assert.ok(unbounded.ok, `grep failed: ${!unbounded.ok ? unbounded.error : ""}`);
177+
assert.ok(unbounded.value.items.length > 2);
178+
179+
const limited = finder.grep("fn", {
180+
mode: "plain",
181+
maxMatchesPerFile: 1,
182+
pageSize: 2,
183+
});
184+
assert.ok(limited.ok, `grep failed: ${!limited.ok ? limited.error : ""}`);
185+
assert.ok(
186+
limited.value.items.length <= 2,
187+
`expected <=2 items, got ${limited.value.items.length}`,
188+
);
189+
assert.ok(
190+
limited.value.items.length < unbounded.value.items.length,
191+
"limited page should yield fewer matches than the default",
192+
);
193+
assert.ok(limited.value.nextCursor !== null, "nextCursor should be set");
194+
});
195+
173196
it("regex mode matches pub fn declarations", () => {
174197
const r = finder.grep("pub fn \\w+", { mode: "regex" });
175198
assert.ok(r.ok, `regex grep failed: ${!r.ok ? r.error : ""}`);

packages/pi-fff/src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,8 +455,7 @@ export default function fffExtension(pi: ExtensionAPI) {
455455
if (!shouldEnableMentions()) return;
456456

457457
ctx.ui.setEditorComponent(
458-
(tui: any, theme: any, keybindings: any) =>
459-
new FffEditor(tui, theme, keybindings),
458+
(tui: any, theme: any, keybindings: any) => new FffEditor(tui, theme, keybindings),
460459
);
461460
}
462461

0 commit comments

Comments
 (0)