fix(pi-fff): preserve path/exclude in fuzzy grep fallback (#697) (#699)

* fix(pi-fff): preserve path and exclude constraints in fuzzy grep fallback (#697)

The automatic fuzzy fallback in the pi-fff `grep` tool passed the raw
`pattern` to `picker.grep`, discarding the constrained `query` built via
`buildQuery`. As a result, the fallback ignored the caller's `path` and
`exclude` constraints and could return matches from explicitly excluded
directories or files outside the requested path.

Pass the constrained `query` to the fallback instead, so it only broadens
matching (fuzzy vs. plain) without broadening scope.

Closes #697

* fix(pi-fff): drop path constraint in fuzzy fallback only for file paths

When the caller pinned a specific file (path has an extension), the
fuzzy fallback broadens across the whole picker so a mistyped filename
can still surface matches. For directory constraints (or no path), keep
the constrained query so the fallback does not leak matches from
excluded / out-of-scope directories.

---------

Co-authored-by: gustav-fff <286169375+gustav-fff@users.noreply.github.com>
This commit is contained in:
Gustav the Bot
2026-07-23 11:38:42 -07:00
committed by GitHub
parent 9bab609ddf
commit 829bfa9570
+9 -1
View File
@@ -722,7 +722,15 @@ export default function fffExtension(pi: ExtensionAPI) {
// automatic fuzzy fallback allows to broad the queries and find different cases
if (result.items.length === 0 && !params.cursor && mode !== "regex") {
const fuzzy = picker.grep(pattern, {
// When the caller pinned a specific file (path has an extension), the
// fuzzy fallback broadens across the whole picker — the file may just
// be misnamed. For directory constraints (or no path), we keep the
// constrained query so the fallback does not leak matches from
// excluded / out-of-scope directories.
const lastSeg = params.path?.split(/[\\/]/).pop() ?? "";
const pathTargetsFile = /\.[a-zA-Z][a-zA-Z0-9]{0,9}$/.test(lastSeg);
const fuzzyQuery = pathTargetsFile ? pattern : query;
const fuzzy = picker.grep(fuzzyQuery, {
mode: "fuzzy",
smartCase,
maxMatchesPerFile: Math.min(effectiveLimit, 50),