fix(grep): align preview highlight stripping with Rust query parser#343
Conversation
|
I think we should simply expose the parsed query to the lua results to avoid this double reparse which will break once we add a new token type. What are you trying to do ? |
|
The highlight stripping in the preview was using a regex that didn't account for all the query syntax the Rust grep engine supports (like negation tokens). When the query had special tokens, the preview highlights would be misaligned. Exposing the parsed query to lua makes sense - that would keep the Rust parser as the single source of truth and avoid any drift. Happy to take that approach instead if you can point me to where the results are serialized for lua. |
|
There is lua_types.rs file. But we probably should only do this by request: add a new function that returns a breakdown of a query by string |
The Lua heuristic in highlight_grep_matches used a simple prefix check (^[*!/] or ^.) to strip constraints. This diverged from the Rust GrepConfig parser in several ways: - Multi-word queries like 'foo bar *.rs' only highlighted 'foo' - Constraint prefixes like type:rust were not stripped - Tokens starting with '.' were incorrectly treated as constraints - Escaped constraint tokens (e.g. \*.config) were not handled Replace the heuristic with _is_grep_constraint() that matches the Rust parser's actual GrepConfig rules: extensions (*.rs), path segments (/src/), exclusions (!test), type filters (type:rust), and path-oriented globs. Use all text parts joined with space for highlighting, matching grep_text() on the Rust side. Fixes dmtrKovalenko#331
Replace the Lua-side constraint detection (_is_grep_constraint) with a new parse_grep_query() function that delegates to the Rust GrepConfig parser. This keeps the Rust parser as the single source of truth for query parsing, avoiding drift when new token types are added. The new function is exposed to Lua as fff.parse_grep_query(query) and returns a table with the grep_text field (the search text with all constraints stripped). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
4586839 to
d02642b
Compare
|
Replaced the Lua-side constraint detection with a new This removes |
|
Thanks for the merge, @dmtrKovalenko! |
The Lua heuristic in
highlight_grep_matches(location_utils.lua) used a simple prefix check to strip constraint tokens before highlighting. This diverged from the RustGrepConfigparser in several ways:foo bar *.rsonly highlightedfoo(first text part), not the full search texttype:rustand other key:value constraints weren't stripped.were incorrectly treated as constraints\*.configas literal search text) weren't handledThis adds
_is_grep_constraint()that matches the Rust parser's actual GrepConfig rules: extensions (*.rs), path segments (/src/), exclusions (!test), type filters (type:rust), and path-oriented globs. Text parts are now joined with space for highlighting, matchinggrep_text()on the Rust side.Fixes #331
This contribution was developed with AI assistance (Claude Code).