pub fn fold_levels(folds: &[Fold]) -> Vec<u32>Expand description
Hash the user-visible signature of the current fold set.
Used as part of the highlights cache key
(crate::render_state::VisibleHighlightsKey::fold_hash) so a
fold toggle invalidates cached spans: collapsing / expanding a
fold changes which physical lines are visible, which changes
what highlight_lines(start, end) should produce.
Only (start_line, end_line, closed) are hashed —
fold identity is excluded because two folds with the same
range and state but different identities don’t change which
bytes are visible.
Nesting level of each fold, 1-based, in folds order.
Vim’s model: the outermost fold is level 1, and foldlevel=N
closes everything deeper than N (so foldlevel=0 closes
everything). A fold’s level is one more than the number of folds
that properly contain it.
Properly is the load-bearing word. Two providers routinely emit
folds over the identical range — a multibuffer file that contributes
exactly one excerpt gets a FileBoundaryFoldProvider fold and an
ExcerptFoldProvider fold with the same bounds. Under a
start <= start && end >= end test each would “contain” the other,
both would land at level 2, and foldlevel=1 would collapse a view
that has only one level of structure to show. Equal ranges are
siblings, not parent and child.
O(n²) in the fold count — the same shape as the closed-state
carry-over recompute_folds already runs over the same list, so this
adds a constant factor rather than a complexity class. Both callers
skip it entirely at the default foldlevel (see
[level_opens_everything]), which is the case that runs after every
reparse.