Expand description
Computed folds (DESIGN.md §5.1, §15:18; user-facing reference
at docs/user/folding.md).
Folds derived automatically from the buffer’s structure. v1 providers:
- Indent – fold spans any line whose successor indents deeper, ending at the last line whose indent is strictly greater than the start. Universal across languages.
- Markdown –
^#+headings define the fold tree. A# H1folds until the next# H1; a## H2folds until the next same-or-higher heading. - Syntax (tree-sitter) – runs the language’s compiled
folds.scmquery against the parse tree owned bylattice_syntax::Syntax. Each@foldcapture becomes a fold spanning the captured node’s lines. Falls back to the Markdown / Indent providers for languages that don’t ship afolds.scmyet.
Manual folds (created via zf from a Visual selection) and
computed folds coexist in [crate::app::App::folds] with no
distinction at the storage layer; the :set foldmethod option
decides which side feeds in.
Fold identity (Fold::identity) is the SHA-style hash of the
trimmed start-line text plus indent depth (for indent / markdown
providers) or (node_kind, trimmed start-line text) (for the
syntax provider). When the buffer changes and folds recompute,
we match new folds to old ones by identity and transfer the
closed-state – so adding a line to one section doesn’t reopen
the closed section above. Manual folds carry identity = None
(their stable identity is the line range itself).
Structs§
- Fold
Index - O(log folds) lookup index built once per frame (or per publish) over a snapshot of the active document’s folds.
- Indent
Primary - LspPrimary
- Manual
Primary - Markdown
Primary - Syntax
Primary
Enums§
- Fold
Marker - A gutter fold marker’s state: the head row of an open (expanded) fold
versus a closed (collapsed) one. Renderers map this to their glyph +
themed colour (
gutter.fold.open/gutter.fold.closed). - Fold
Recompute Cause - Why
crate::editor::Editor::recompute_folds_becauseis running, and so whetherfoldlevelgets to seed the folds it has not seen before.
Functions§
- apply_
fold_ level - Close every fold deeper than
level, open the rest. - apply_
fold_ level_ to_ new - Close new folds that sit deeper than
foldlevel, leaving folds whose state was carried over untouched. - compute_
code_ block_ lines - MC.2: the source lines that lie inside a fenced (or indented) code block,
for the full-width
syntax.code_blockbackground tint (markdown and any grammar exposing those node kinds). - compute_
fold_ hash - Phase 5.8.AF.5 / Slice X2: hoisted host-side from
lattice-ui-tui::app::folds::compute_fold_hashso dispatch’spublish_render_statecan populateSyntaxRenderState::fold_hashwithout depending on the renderer crate. - compute_
indent_ folds - Run the indent-based fold algorithm against
bufferand return every fold it discovers. All produced folds are open (closed = false) by default – vim’sfoldlevelstartwould override that, but v1 doesn’t model the level option yet. - compute_
markdown_ folds - Markdown heading-based fold provider (DESIGN.md §15:18,
docs/user/folding.md). Walks the buffer for ATX headings (^#+\s) and emits one fold per heading whose body has at least one row. Heading depth (the number of#s) determines nesting: a## H2ends at the next same-or-shallower heading (# H1or another## H2or end-of-buffer). - compute_
syntax_ folds - Tree-sitter-driven fold provider. Runs the language’s compiled
folds.scmquery againstlattice_syntax::Syntax’s parse tree and emits oneFoldper@foldcapture spanning more than a single line. - count_
visible_ rows_ between - Count how many visible (non-fold-hidden) rows exist between
from_line(inclusive) andto_line(exclusive). Closed fold bodies are skipped. Both lines must be visible (not inside a closed fold body) — callers ensure this before calling. Returns the number of display rows spanning the range. - fold_
aware_ visible_ end - The exclusive buffer-line bound a
height-row viewport starting atscrollactually reaches. - fold_
aware_ visible_ end_ of fold_aware_visible_endfrom a raw fold slice, skipping theFoldIndexbuild when there is no closed fold to walk over — the overwhelmingly common case, and one that runs per worker tick.- fold_
levels - Hash the user-visible signature of the current fold set.
- fold_
summary_ text - The
⋯ N linessummary text trailing a collapsed head row, wherenisfolded_line_span’s count. One function so the TUI and GPUI peers cannot drift on spacing, glyph, or pluralisation — the TUI grew this as an inlineformat!and GPUI had no summary at all, which is exactly how two renderers end up disagreeing. - folded_
line_ span - max_
fold_ level - Deepest level present, or 0 when there are no folds.
zR’s equivalentfoldlevelvalue. - nth_
visible_ line_ backward - Walk backward from
start_lineand return the line atoffsetvisible rows above it. Walking backward hops over closed fold bodies to their visible heads, then continues from the preceding line. Returns 0 when the walk hits BOF before consumingoffsetrows. - nth_
visible_ line_ forward - Walk forward from
start_lineand return the buffer line atoffsetvisible (non-fold-hidden) display rows below it. Closed fold bodies are skipped — only fold heads (start lines) and non-folded lines count as visible rows. When the walk reaches the last addressable line before consumingoffsetrows, that last line is returned (the caller’s clamp). - visible_
fold_ edge - VM.3i: vim’s
zj/zkedge fromline— the nearest fold START after it (forward) or fold END before it — among edges that are VISIBLE. - visible_
source_ lines - Number of buffer lines collapsed onto the visible head row of the
closed fold
(start_line, end_line)— the count both renderers show in the⋯ N linesfold summary. Walks forward fromend_line + 1through any sibling closed folds whose heading is itself hidden by the region already collapsed (start < probe <= end), so overlapping folds (e.g.(1,3)+(3,5)fromfoldmethod=indent) report their combined span. Folds that merely ABUT — the next fold starts atend + 1, the first visible line after this one — are NOT chained: that fold has an on-screen heading and is a separate fold with its own summary. Shared by the TUI and GPUI renderers so the count stays identical. The source lines a pane actually shows, in paint order: walk fromscrollcollecting lines untilheightVISIBLE ones are gathered, skipping every line hidden inside a closed fold and stepping over a closed fold’s body in one jump (its head row stands for the whole range).