Skip to content

fix(windows): directorySearch returns 0 results on Windows#394

Merged
dmtrKovalenko merged 8 commits intodmtrKovalenko:mainfrom
schizoidcock:fix/windows-directory-search
Apr 20, 2026
Merged

fix(windows): directorySearch returns 0 results on Windows#394
dmtrKovalenko merged 8 commits intodmtrKovalenko:mainfrom
schizoidcock:fix/windows-directory-search

Conversation

@schizoidcock
Copy link
Copy Markdown
Contributor

@schizoidcock schizoidcock commented Apr 19, 2026

Problem

On Windows, directorySearch returns 0 results even when directories exist.

Root Cause Analysis

Path::to_string_lossy() returns platform-native separators:

  • Unix: src/components/Button.tsx
  • Windows: src\components\Button.tsx

fff uses rfind('/') in 10+ locations to extract directory parts:

let fname_offset = rel_str.rfind('/').map(|i| i + 1).unwrap_or(0);

On Windows, rfind('/') returns Nonefname_offset = 0 → entire path treated as filename → no directory part extracted → directorySearch finds nothing.

Solution

Added normalize_path_separator() helper in path_utils.rs:

#[cfg(windows)]
pub fn normalize_path_separator(path: Cow<'_, str>) -> Cow<'static, str> {
    if path.contains('\\') {
        Cow::Owned(path.replace('\\', "/"))
    } else {
        Cow::Owned(path.into_owned())
    }
}

#[cfg(not(windows))]
pub fn normalize_path_separator(path: Cow<'_, str>) -> Cow<'static, str> {
    Cow::Owned(path.into_owned()) // No-op on Unix
}

Applied to all 3 path-to-string conversion points:

  • find_file_index (line 208) - file lookup by path
  • new_with_metadata (line 311) - runtime file creation
  • new_from_walk (line 365) - initial filesystem indexing

Additional Fix

Removed frecency filter in score.rs that was hiding directories without access history:

// Before: .filter(|d| d.max_access_frecency() > 0)
// After: Include all directories

Steps to Reproduce

  1. Build fff on Windows
  2. Index a directory with subdirectories
  3. Call directorySearch('component')
  4. Observe 0 results (before fix) vs correct results (after fix)

Testing

  • cargo build --release passes
  • Manual testing confirms directorySearch now returns results on Windows

Comment thread crates/fff-core/src/file_picker.rs Outdated
}

/// Return dirs ranked by frecency only (no fuzzy query).
fn score_dirs_by_frecency<'a>(
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wooooow this is so bad how did I leave this function

@schizoidcock schizoidcock force-pushed the fix/windows-directory-search branch from e9ff0f6 to 1391f73 Compare April 19, 2026 23:35
@schizoidcock schizoidcock force-pushed the fix/windows-directory-search branch from 1391f73 to aa1a249 Compare April 20, 2026 00:48
dmtrKovalenko and others added 6 commits April 19, 2026 18:22
* feat: add pi extension for FFF file search

Add @ff-labs/pi-fff package providing pi coding agent integration:

- Overrides built-in find/grep tools with FFF-powered versions
- Adds multi_grep tool for SIMD-accelerated multi-pattern search
- Replaces @-mention autocomplete with FFF frecency-ranked suggestions
- Commands: /fff-health, /fff-rescan, /fff-mode (with immediate switch)
- Streamlined implementation: 26% code reduction (800→590 lines)

Published as pi package: npm:@ff-labs/pi-fff

* docs: fix install instructions

- Remove git install option (doesn't work for monorepo subfolders)
- Remove config file from mode precedence (no longer used)
- Keep npm as only recommended install method

* feat: add root pi manifest for git installs

Add pi configuration to root package.json pointing to packages/pi-fff.
This enables:
  pi install git:github.com/dmtrKovalenko/fff.nvim

The root stays private (not published to npm), but pi can now discover
the extension from the git repo structure.

* docs: add git install instructions

Now that root package.json has pi manifest, git installs work:
  pi install git:github.com/dmtrKovalenko/fff.nvim

* fix: address PR review feedback

- Add config file persistence for /fff-mode (fixes 'persist' claim)
- Add readConfigMode() and writeConfigMode() helpers
- Use applyEditorMode() in /fff-mode command (DRY)
- Add publishConfig.access: 'public' for npm publishing
- Fix @types/node to ^22.0.0 (align with repo)
- Remove ignoreCase parameter (FFF doesn't support force case-insensitive)
- Run Biome formatter (fix tab indentation)

* update toolnames and add to release pipeline

* do not override default tools

* Make an option to override the default tools

* fix: macos tests

* better toolnames mangement

---------

Co-authored-by: Dmitriy Kovalenko <dmtr.kovalenko@outlook.com>
@dmtrKovalenko
Copy link
Copy Markdown
Owner

I have added some fixes that I think eliminates the need for the normalization could you please pull and check if this is actualy resolves and issue on your end

@schizoidcock
Copy link
Copy Markdown
Contributor Author

I have added some fixes that I think eliminates the need for the normalization could you please pull and check if this is actualy resolves and issue on your end

I will check this to test in a moment, but in my end it is working with my fixes already as intended

@dmtrKovalenko
Copy link
Copy Markdown
Owner

I don't like the normalization of paths. I want to avoid that as much as possible

@schizoidcock
Copy link
Copy Markdown
Contributor Author

I pulled the latest main and tested on Windows:

directorySearch result:
ok: true
items: 0

grep result:
ok: true
items: 55
totalMatched: 55

grep works, but directorySearch still returns 0 items on Windows.

The issue persists without the path normalization fix. The root cause is that rfind('/') in Rust expects forward slashes, but Path::to_string_lossy() returns backslashes on Windows.

@dmtrKovalenko
Copy link
Copy Markdown
Owner

Wait but I got rid of all rfind / no?

@schizoidcock
Copy link
Copy Markdown
Contributor Author

Tested commit 2c837c8 on Windows — it works! 🎉

directorySearch('tools'):
  ok: true
  items: 3
    1. packages/cli/src/tools/
    2. hooks/
    3. packages/cli/src/utils/

directorySearch('src'):
  ok: true  
  items: 5

The rfind fix resolves the issue. I'll remove my path normalization commits since they're no longer needed.

Thanks for the quick fix!

@schizoidcock
Copy link
Copy Markdown
Contributor Author

Closing — the fix in commit 2c837c8 works. Thanks for resolving this upstream!

@dmtrKovalenko
Copy link
Copy Markdown
Owner

Wait but we need to make sure it's merged :D

@dmtrKovalenko dmtrKovalenko merged commit 743ab60 into dmtrKovalenko:main Apr 20, 2026
80 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants