Skip to main content

Module brackets

Module brackets 

Source
Expand description

Finding the partner of the bracket at a position.

§Bounded on purpose

The search takes a line budget and gives up rather than exceeding it. This runs on the render path — the match is recomputed as the cursor moves — and architecture §4 puts a 16 ms ceiling on a keystroke. An unmatched bracket on a 50k-line file is a far smaller cost than a scan of it, so the caller passes its viewport height plus a margin and the answer is “no match” beyond that.

§Known limitation, until M2.5

This is a character scan with no idea what a string or a comment is, so the ( in "a ( b" counts, and a ) inside a comment can be matched as a partner. Fixing that needs the syntax tree, which arrives with tree-sitter at M2.5 — at which point this function takes a predicate for “is this position code” and the scan is otherwise unchanged. Recorded here rather than left to be filed as a bug later.

Functions§

match_at
The matching pair for the bracket at, or immediately before, at.