@ff-labs/pi-fff 0.7.3-nightly.d56006d → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.ts +30 -67
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ff-labs/pi-fff",
3
3
  "public": true,
4
- "version": "0.7.3-nightly.d56006d",
4
+ "version": "0.8.0",
5
5
  "description": "pi extension: FFF-powered fuzzy file and content search",
6
6
  "type": "module",
7
7
  "license": "MIT",
package/src/index.ts CHANGED
@@ -256,9 +256,7 @@ function createFffMentionProvider(
256
256
 
257
257
  const query = prefix.startsWith('@"') ? prefix.slice(2) : prefix.slice(1);
258
258
  const items = await getItems(query, options.signal);
259
- return options.signal.aborted || items.length === 0
260
- ? null
261
- : { items, prefix };
259
+ return options.signal.aborted || items.length === 0 ? null : { items, prefix };
262
260
  },
263
261
  applyCompletion(_lines, cursorLine, cursorCol, item, prefix) {
264
262
  const currentLine = _lines[cursorLine] || "";
@@ -267,11 +265,7 @@ function createFffMentionProvider(
267
265
  const newLine = before + item.value + after;
268
266
  const newCursorCol = cursorCol - prefix.length + item.value.length;
269
267
  return {
270
- lines: [
271
- ..._lines.slice(0, cursorLine),
272
- newLine,
273
- ..._lines.slice(cursorLine + 1),
274
- ],
268
+ lines: [..._lines.slice(0, cursorLine), newLine, ..._lines.slice(cursorLine + 1)],
275
269
  cursorLine,
276
270
  cursorCol: newCursorCol,
277
271
  };
@@ -381,22 +375,20 @@ export default function fffExtension(pi: ExtensionAPI) {
381
375
  const result = f.mixedSearch(query, { pageSize: MENTION_MAX_RESULTS });
382
376
  if (!result.ok) return [];
383
377
 
384
- return result.value.items
385
- .slice(0, MENTION_MAX_RESULTS)
386
- .map((mixed: MixedItem) => {
387
- if (mixed.type === "directory") {
388
- return {
389
- value: buildAtCompletionValue(mixed.item.relativePath),
390
- label: mixed.item.dirName,
391
- description: mixed.item.relativePath,
392
- };
393
- }
378
+ return result.value.items.slice(0, MENTION_MAX_RESULTS).map((mixed: MixedItem) => {
379
+ if (mixed.type === "directory") {
394
380
  return {
395
381
  value: buildAtCompletionValue(mixed.item.relativePath),
396
- label: mixed.item.fileName,
382
+ label: mixed.item.dirName,
397
383
  description: mixed.item.relativePath,
398
384
  };
399
- });
385
+ }
386
+ return {
387
+ value: buildAtCompletionValue(mixed.item.relativePath),
388
+ label: mixed.item.fileName,
389
+ description: mixed.item.relativePath,
390
+ };
391
+ });
400
392
  }
401
393
 
402
394
  // Editor wrapper that injects FFF @-mention autocomplete alongside base provider.
@@ -423,12 +415,8 @@ export default function fffExtension(pi: ExtensionAPI) {
423
415
  if (mentionResult) return mentionResult;
424
416
  // Fall back to base provider
425
417
  return (
426
- this.baseProvider?.getSuggestions(
427
- lines,
428
- cursorLine,
429
- cursorCol,
430
- options,
431
- ) ?? null
418
+ this.baseProvider?.getSuggestions(lines, cursorLine, cursorCol, options) ??
419
+ null
432
420
  );
433
421
  },
434
422
  applyCompletion: (lines, cursorLine, cursorCol, item, prefix) => {
@@ -480,14 +468,12 @@ export default function fffExtension(pi: ExtensionAPI) {
480
468
  });
481
469
 
482
470
  pi.registerFlag("fff-frecency-db", {
483
- description:
484
- "Path to the frecency database (overrides FFF_FRECENCY_DB env)",
471
+ description: "Path to the frecency database (overrides FFF_FRECENCY_DB env)",
485
472
  type: "string",
486
473
  });
487
474
 
488
475
  pi.registerFlag("fff-history-db", {
489
- description:
490
- "Path to the query history database (overrides FFF_HISTORY_DB env)",
476
+ description: "Path to the query history database (overrides FFF_HISTORY_DB env)",
491
477
  type: "string",
492
478
  });
493
479
 
@@ -517,20 +503,15 @@ export default function fffExtension(pi: ExtensionAPI) {
517
503
  context: any,
518
504
  maxLines = 15,
519
505
  ) => {
520
- const text =
521
- (context.lastComponent as Text | undefined) ?? new Text("", 0, 0);
522
- const output =
523
- result.content?.find((c) => c.type === "text")?.text?.trim() ?? "";
506
+ const text = (context.lastComponent as Text | undefined) ?? new Text("", 0, 0);
507
+ const output = result.content?.find((c) => c.type === "text")?.text?.trim() ?? "";
524
508
  if (!output) {
525
509
  text.setText(theme.fg("muted", "No output"));
526
510
  return text;
527
511
  }
528
512
 
529
513
  const lines = output.split("\n");
530
- const displayLines = lines.slice(
531
- 0,
532
- options.expanded ? lines.length : maxLines,
533
- );
514
+ const displayLines = lines.slice(0, options.expanded ? lines.length : maxLines);
534
515
  let content = `\n${displayLines.map((line: string) => theme.fg("toolOutput", line)).join("\n")}`;
535
516
  if (lines.length > displayLines.length) {
536
517
  content += theme.fg(
@@ -602,8 +583,7 @@ export default function fffExtension(pi: ExtensionAPI) {
602
583
  // as a valid regex, otherwise plain literal. The fuzzy fallback below
603
584
  // only kicks in for plain mode — regex queries are intentional.
604
585
  const hasRegexSyntax =
605
- params.pattern !==
606
- params.pattern.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
586
+ params.pattern !== params.pattern.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
607
587
  let mode: GrepMode = hasRegexSyntax ? "regex" : "plain";
608
588
  if (mode === "regex") {
609
589
  try {
@@ -675,14 +655,10 @@ export default function fffExtension(pi: ExtensionAPI) {
675
655
  let output = formatGrepOutput(result);
676
656
  const notices: string[] = [];
677
657
  if (result.regexFallbackError) {
678
- notices.push(
679
- `Invalid regex: ${result.regexFallbackError}, used literal match`,
680
- );
658
+ notices.push(`Invalid regex: ${result.regexFallbackError}, used literal match`);
681
659
  }
682
660
  if (result.nextCursor) {
683
- notices.push(
684
- `Continue with cursor="${storeCursor(result.nextCursor)}"`,
685
- );
661
+ notices.push(`Continue with cursor="${storeCursor(result.nextCursor)}"`);
686
662
  }
687
663
 
688
664
  if (notices.length > 0) output += `\n\n[${notices.join(". ")}]`;
@@ -698,8 +674,7 @@ export default function fffExtension(pi: ExtensionAPI) {
698
674
  },
699
675
 
700
676
  renderCall(args, theme, context) {
701
- const text =
702
- (context.lastComponent as Text | undefined) ?? new Text("", 0, 0);
677
+ const text = (context.lastComponent as Text | undefined) ?? new Text("", 0, 0);
703
678
  const pattern = args?.pattern ?? "";
704
679
  const path = args?.path ?? ".";
705
680
  let content =
@@ -795,8 +770,7 @@ export default function fffExtension(pi: ExtensionAPI) {
795
770
  // shown so far there's another page to fetch.
796
771
  const shownSoFar = pageIndex * effectiveLimit + result.items.length;
797
772
  const hasMore =
798
- result.items.length >= effectiveLimit &&
799
- result.totalMatched > shownSoFar;
773
+ result.items.length >= effectiveLimit && result.totalMatched > shownSoFar;
800
774
 
801
775
  const notices: string[] = [];
802
776
  if (formatted.weak && formatted.shownCount > 0)
@@ -830,8 +804,7 @@ export default function fffExtension(pi: ExtensionAPI) {
830
804
  },
831
805
 
832
806
  renderCall(args, theme, context) {
833
- const text =
834
- (context.lastComponent as Text | undefined) ?? new Text("", 0, 0);
807
+ const text = (context.lastComponent as Text | undefined) ?? new Text("", 0, 0);
835
808
  const pattern = args?.pattern ?? "";
836
809
  const path = args?.path ?? ".";
837
810
  let content =
@@ -864,9 +837,7 @@ export default function fffExtension(pi: ExtensionAPI) {
864
837
  constraints: Type.Optional(
865
838
  Type.String({ description: "File filter, e.g. '*.{ts,tsx} !test/'" }),
866
839
  ),
867
- context: Type.Optional(
868
- Type.Number({ description: "Context lines before+after" }),
869
- ),
840
+ context: Type.Optional(Type.Number({ description: "Context lines before+after" })),
870
841
  limit: Type.Optional(
871
842
  Type.Number({
872
843
  description: `Max matches (default ${DEFAULT_GREP_LIMIT})`,
@@ -932,8 +903,7 @@ export default function fffExtension(pi: ExtensionAPI) {
932
903
  },
933
904
 
934
905
  renderCall(args, theme, context) {
935
- const text =
936
- (context.lastComponent as Text | undefined) ?? new Text("", 0, 0);
906
+ const text = (context.lastComponent as Text | undefined) ?? new Text("", 0, 0);
937
907
  const patterns = args?.patterns ?? [];
938
908
  const constraints = args?.constraints;
939
909
  let content =
@@ -955,8 +925,7 @@ export default function fffExtension(pi: ExtensionAPI) {
955
925
  // --- commands ---
956
926
 
957
927
  pi.registerCommand("fff-mode", {
958
- description:
959
- "Show or set FFF mode: /fff-mode [tools-and-ui | tools-only | override]",
928
+ description: "Show or set FFF mode: /fff-mode [tools-and-ui | tools-only | override]",
960
929
  handler: async (args, ctx) => {
961
930
  const arg = (args || "").trim();
962
931
 
@@ -965,19 +934,13 @@ export default function fffExtension(pi: ExtensionAPI) {
965
934
  const mode = getMode();
966
935
  const flag = pi.getFlag("fff-mode") ?? "unset";
967
936
  const env = process.env.PI_FFF_MODE ?? "unset";
968
- ctx.ui.notify(
969
- `Current mode: '${mode}'\nFlag: ${flag}, Env: ${env}`,
970
- "info",
971
- );
937
+ ctx.ui.notify(`Current mode: '${mode}'\nFlag: ${flag}, Env: ${env}`, "info");
972
938
  return;
973
939
  }
974
940
 
975
941
  // Validate and set mode
976
942
  if (!VALID_MODES.includes(arg as FffMode)) {
977
- ctx.ui.notify(
978
- `Usage: /fff-mode [${VALID_MODES.join(" | ")}]`,
979
- "warning",
980
- );
943
+ ctx.ui.notify(`Usage: /fff-mode [${VALID_MODES.join(" | ")}]`, "warning");
981
944
  return;
982
945
  }
983
946