Skip to main content

Module fold

Module fold 

Source
Expand description

D.3.f.1 (2026-05-29) / DX.3-C7 (2026-06-24): HunkFoldSource.

A [lattice_core::FoldSource] that emits one [Fold] per non-empty, multi-line current-side hunk range of a diff session. Mode-owned: diff-mode’s on_activate constructs one per participating buffer (holding that buffer’s Arc<DiffSession>) and registers it via the FoldOverlayService; the mode’s Drop guard removes it. This is the same shape multibuffer’s ExcerptFoldProvider / FileBoundaryFoldProvider use — a self-contained FoldSource (no FoldContext) wrapped by the host’s FoldSourceAdapter, which gates compute_folds to the target buffer. (Before C7 this was a context-driven FoldProvider pre-seeded into FoldRegistry::with_builtins, reading FoldContext::diff_hunks; that coupling between the host fold substrate and lattice-diff is now gone.)

See docs/dev/architecture/fold-architecture.md §2 and docs/dev/architecture/diff-system.md §6.5.

§Why current-side only

Hunks classify changes against an earlier baseline; the foldable region is the current document’s lines, which live in Hunk::ranges[1]. Pure-Remove hunks have an empty current-side range (no current-side text to fold — the deletion is surfaced via a virtual row, not a fold). Add / Change / Conflict hunks all have non-empty current-side ranges, but a single-line hunk (ranges[1] covers exactly one line) is also non-foldable — the z* grammar treats a 1-line fold as a no-op. Filter both cases.

§Identity

hash(("diff:hunk", start_line, end_line)) is namespaced with the literal "diff:hunk" so that a syntax fold and a hunk fold covering the same (start, end) produce distinct identity hashes. Closed-state survives across diff publishes when a hunk’s range is unchanged.

Structs§

HunkFoldSource
DX.3-C7: per-buffer hunk-fold source.
UnchangedFoldSource
D-fix.5 (2026-06-26): per-buffer, per-side unchanged-fold source — vimdiff foldmethod=diff / VS Code “Collapse Unchanged Regions”.

Constants§

HUNK_FOLD_NAMESPACE
Namespace for per-buffer hunk-fold provider ids. OR’d with the buffer’s id (low 32 bits) so simultaneous diff buffers register distinct overlay ids — FoldOverlayService::add_source keys removal on the id, so a shared id would let one buffer’s deregistration evict another’s folds. Distinct from multibuffer’s 0xBBBB_* namespaces.
UNCHANGED_FOLD_NAMESPACE
D-fix.5: namespace for per-buffer unchanged-fold provider ids. Distinct high bits from HUNK_FOLD_NAMESPACE so a buffer’s hunk fold source and its unchanged fold source register under different overlay ids (both OR in the buffer’s low-32 id) — they coexist on the same buffer covering disjoint regions (hunks vs. the gaps between).

Functions§

hunk_fold_identity
Compute the stable identity hash for a single hunk fold.
unchanged_fold_identity
Compute the stable identity hash for a single unchanged fold. Namespaced with "diff:unchanged" + the slot so it never collides with a hunk fold ("diff:hunk") or the same span on the other side; span-keyed so closed-state (a user zo) survives a republish that reproduces the same gap.