Skip to content

FollowUp: Make Query.Between default exclusive; add block wrapping helpers; improve region traversal#37

Merged
dsisco11 merged 6 commits into
masterfrom
sisco/queries
Jan 12, 2026
Merged

FollowUp: Make Query.Between default exclusive; add block wrapping helpers; improve region traversal#37
dsisco11 merged 6 commits into
masterfrom
sisco/queries

Conversation

@dsisco11

Copy link
Copy Markdown
Owner

Summary
This PR adjusts Query.Between to default to inclusive: false (exclusive), fixes region-resolution semantics for BetweenQuery while keeping sequence-safe consumption, adds a new offset-capable RegionTraversal overload for efficient region selection, and introduces convenience APIs to wrap existing block nodes into queries (Query.Wrap(...) / Query.Inner(...)). Tests and wiki docs are updated accordingly.

Key Changes

  • Query.Between defaults to exclusive:
    • Query.Between(start, end) now matches the content between start/end delimiters (delimiters excluded).
    • Use inclusive: true to include the delimiters in the matched region.
  • BetweenQuery semantics split “consumption” vs “edit region”:
    • TryMatch always consumes the full start→end span (safe in sequences).
    • Region selection applies inclusive/exclusive boundaries for editor operations.
  • Region traversal improvements:
    • Added a RegionTraversal overload that supports offset regions (start slot offset + custom first-node/position), so queries like BetweenQuery can remain efficient without switching to a TreeWalker-based region scan.
  • New convenience APIs for node-based querying:
    • Query.Wrap(SyntaxBlock) returns a BlockNodeQuery so callers can use .Inner() / .Start() / .End() on an existing block instance.
    • Query.Wrap(SyntaxNode) returns a BlockNodeQuery for blocks, otherwise an ExactNodeQuery.
    • Query.Inner(SyntaxBlock) is shorthand for Query.Wrap(block).Inner().

Tests/Docs

  • Updated tests that relied on the old inclusive default to explicitly pass inclusive: true.
  • Added tests validating Query.Wrap(block).Inner() and Query.Inner(block) edit only the intended block.
  • Updated wiki docs to reflect Query.Between default behavior and the new wrap/inner conveniences.

Behavior Change / Migration Notes

  • Breaking-ish behavior change: code that assumed Query.Between(start, end) included the delimiters must switch to Query.Between(start, end, inclusive: true).
  • This change is intentional to better match “between” expectations and make editor operations more ergonomic.

@dsisco11 dsisco11 merged commit e71b80c into master Jan 12, 2026
1 check passed
@dsisco11 dsisco11 deleted the sisco/queries branch January 12, 2026 12:18
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