发布

  • fix(grep): align preview highlight stripping with Rust query parser (#343)

    frostbyte_neo 发布于 2026-04-08 21:21:11 +00:00

    • fix(grep): align preview highlight stripping with Rust query parser

    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 #331

    • refactor(grep): expose parsed query to lua via Rust function

    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


    Co-authored-by: Matt Van Horn 455140+mvanhorn@users.noreply.github.com
    Co-authored-by: Claude Opus 4.6 (1M context) noreply@anthropic.com

    下载附件