Skip to content

feat(windows): support both "\" and "/" for path separator on windows #442

Merged
dmtrKovalenko merged 8 commits intomainfrom
fix/directory-separator-on-windows
May 4, 2026
Merged

feat(windows): support both "\" and "/" for path separator on windows #442
dmtrKovalenko merged 8 commits intomainfrom
fix/directory-separator-on-windows

Conversation

@dmtrKovalenko
Copy link
Copy Markdown
Owner

@dmtrKovalenko dmtrKovalenko commented May 3, 2026

closes #381

Indexed paths keep the OS-native separator (\\ on Windows) so that pathdiff, strip_prefix and watcher event lookups all stay byte-identical. Queries and constraints always use /, so path_contains_segment and path_ends_with_suffix now fold / and \\ together when walking boundaries and comparing slices. Glob matching gets a localized / rewrite at the call site because globset operates on strings.

Adds windows-latest to the Rust test matrix with a focused regression test covering PathSegment, FilePath and Glob constraints across grep, multi_grep and fuzzy_search. Also gates the unix-only write_relative_cstr / MMAP_THRESHOLD so -D warnings compiles on Windows.

Fixes #381
@dmtrKovalenko dmtrKovalenko force-pushed the fix/directory-separator-on-windows branch from 2478937 to c8d8c02 Compare May 3, 2026 23:24
Three pre-existing tests compared picker-internal (canonical) paths against tmp.path()-derived (potentially 8.3 short-name) paths and silently passed on Linux/macOS. Match the picker's dunce canonicalization in each test so watch_dir, overflow and libgit2-workdir assertions hold on Windows too.

score.rs also now detects a forward slash in the query (on top of MAIN_SEPARATOR) so a path-like query enables the path-alignment bonus on Windows.
…okups

FilePicker canonicalizes its base via dunce but watcher events, consumer calls and tests may still pass short-name / different-casing paths. to_relative_path, find_file_index and add_new_file now fall back to canonicalize (or parent canonicalize for deleted files) on Windows, keeping native separators in storage while still resolving non-matching prefixes.
Stored paths keep the native separator, so a user query like 'src/core/file.rs' fails the byte-wise frizbee match against 'src\\core\\file.rs'. Translate forward slashes to backslashes only when the query uses them, inside both score_files and score_dirs, so full-path queries still rank the closest path match first.
…mbined

edit_name/del_name come from repo_files with forward-slash relative paths, but stored paths on Windows use backslashes, so p.contains(edit_name) never matched. Fall back to file_name() which is separator-agnostic.
grep_with_path_constraint, grep_with_negated_path_constraint and the watcher burst test asserted on relative paths with forward-slash prefixes. Stored paths on Windows use '\\', so accept either form.
is_path_sep only folds '\\' on Windows and the two backslash-specific tests are #[cfg(windows)]. Removed verbose examples from the rustdoc on path_contains_segment / path_ends_with_suffix now that the behaviour is covered by the unit tests.
@dmtrKovalenko dmtrKovalenko changed the title fix(windows): normalize path separators for directory constraints fix(windows): support both "\" and "/" for path separator on windows May 4, 2026
@dmtrKovalenko dmtrKovalenko changed the title fix(windows): support both "\" and "/" for path separator on windows feat(windows): support both "\" and "/" for path separator on windows May 4, 2026
@dmtrKovalenko dmtrKovalenko merged commit 2f1e51e into main May 4, 2026
47 of 48 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.

Directory path constraints return 0 results on Windows (path separator mismatch)

1 participant