Skip to content

fix(query-parser): parse file:line after a Windows drive letter - #864

Open
kevin9327 wants to merge 1 commit into
dmtrKovalenko:mainfrom
kevin9327:fix/location-windows-drive
Open

fix(query-parser): parse file:line after a Windows drive letter#864
kevin9327 wants to merge 1 commit into
dmtrKovalenko:mainfrom
kevin9327:fix/location-windows-drive

Conversation

@kevin9327

@kevin9327 kevin9327 commented Sep 9, 2026

Copy link
Copy Markdown

The defect

parse_location drops the location suffix of any Windows absolute path:

parse_location(r"C:\Users\me\file.rs:12")
  -> ("C:\\Users\\me\\file.rs:12", None)   // expected ("C:\\Users\\me\\file.rs", Line(12))

parse_column_location splits on the first colon and gives up if that one
split does not yield a location:

let (file_path, location_part) = query.split_once(':')?;

On C:\Users\me\file.rs:12 the first colon is the drive separator, so
location_part is \Users\me\file.rs:12, none of the three shapes parse, and
the whole query falls through as plain text. Pasting a path from a compiler
error, a stack trace or grep output into the picker opens the file at line 1
instead of the line named in it — or, since the query still carries the :12,
finds nothing.

Unix absolute paths are unaffected (/Users/.../file.rs:12 has no earlier
colon), which is why the single-token guard in parser.rs that was written for
exactly this shape — "the token looks like an absolute file path with a location
suffix (e.g. /Users/.../file.rs:12)" — never surfaced it.

The fix

Keep scanning colons left to right instead of giving up after the first one.
Left to right is load-bearing: file:12:4 must still split at its first colon
so the location part is 12:4, not 4.

Verification (Windows, default features)

RUSTUP_TOOLCHAIN was pinned to 1.98.0-x86_64-pc-windows-msvc because
rust-toolchain.toml's stable channel could not update on this machine.

Before, cargo test -p fff-query-parser --lib -- location:

test location::tests::parses_location_after_a_windows_drive_letter ... FAILED

---- location::tests::parses_location_after_a_windows_drive_letter stdout ----

thread 'location::tests::parses_location_after_a_windows_drive_letter' (35060) panicked at crates\fff-query-parser\src\location.rs:268:9:
assertion `left == right` failed
  left: ("C:\\Users\\me\\file.rs:12", None)
 right: ("C:\\Users\\me\\file.rs", Some(Line(12)))

test result: FAILED. 6 passed; 1 failed; 0 ignored; 0 measured; 82 filtered out

After:

test result: ok. 89 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

Pins that the scan does not widen anything, all passing before and after:

  • C:\Users\me\file.rs (colon, no location) stays untouched, as does foo:bar
    — the new assertions in the same test.

  • test_location_parsing keeps file:12:4 at Position { 12, 4 } (not
    Line(4)), file:12ab at None, and the four range shapes unchanged.

  • test_grep_no_location_parsing_single_token, test_grep_no_location_parsing_multi_token
    and test_absolute_path_with_location_not_path_segment are unchanged.

  • cargo test -p fff-query-parser — 89 lib + 3 doc tests passed, 0 failed.

  • cargo test -p fff-search --lib — 159 passed, 0 failed.

  • cargo fmt --all -- --check — clean.

  • cargo clippy -p fff-query-parser --lib — clean.

Summary by CodeRabbit

  • Bug Fixes
    • Improved location parsing for Windows drive-letter paths such as C:\....
    • Queries with multiple colons are now handled correctly by identifying the first valid location marker.
    • Queries containing colons that do not begin a valid location continue to return no location.

@coderabbitai

coderabbitai Bot commented Sep 9, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 077a76f5-942c-46fc-a6c5-6062dac861a0

📥 Commits

Reviewing files that changed from the base of the PR and between 7f8537e and a513374.

📒 Files selected for processing (1)
  • crates/fff-query-parser/src/location.rs

Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review.


📝 Walkthrough

Walkthrough

parse_column_location now scans all colon positions instead of stopping at the first colon. This supports Windows drive-letter paths and preserves unchanged results when no valid location exists. Tests cover line locations, position locations, and invalid suffixes.

Changes

Column location parsing

Layer / File(s) Summary
Colon scanning and Windows path validation
crates/fff-query-parser/src/location.rs
parse_column_location checks each colon until it finds a valid location. Tests cover Windows drive-letter paths, line and position suffixes, and invalid queries.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to a5133

Windows drive-letter paths with line or column suffixes now parse correctly while invalid colon suffixes remain ordinary queries. The focused parser change includes regression coverage and is ready to merge.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: parsing file and line locations after Windows drive letters.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 1 files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

1 participant