Skip to content

collectBracketLevels

collectBracketLevels(brackets, options?): readonly BracketLevel[]

Nesting level of every bracket in the list, paired with a stack for the same reason a caret match is. The worker’s depth counts openers it never saw closed, so one stray { inflates the depth of every bracket after it for the rest of the file, and a mismatched closer is reported one level deeper than the opener it belongs to. A level that drifts is worse than no level: anything painting it would recolour the file below the caret while a pair is still half-typed.

Unbalanced text resolves the way a reader resolves it — a closer takes the nearest opener it can legally close, which re-syncs the depth of everything after it rather than carrying the mistake forward. An opener whose closer never arrives still reports the level it was written at, because that is where it sits on screen; only a closer with nothing to close is called out.

readonly BracketInfo[]

BracketLevelOptions

readonly BracketLevel[]