lattice_diff/lib.rs
1//! Pure data layer for Lattice's diff subsystem.
2//!
3//! Arity-agnostic hunk computation over `&ropey::Rope` inputs,
4//! backed by [`imara_diff`] (Histogram by default; Myers +
5//! Patience also wired). No host integration, no actor
6//! plumbing -- those land in D.2.
7//!
8//! [`compute_diff`] is the only public engine entry: pass an
9//! `&[Rope]` of N participants (N ∈ {0, 1, 2, 3} in v1), get
10//! back a `Result<HunkIndex, DiffEngineError>`. The engine
11//! dispatches by arity to crate-private two-way / three-way
12//! algorithms; external consumers never branch on N. See
13//! `docs/dev/architecture/n-way-diff-membership.md` (D.8) for
14//! the design rationale.
15//!
16//! See `docs/dev/architecture/diff-system.md` §3.1 for the type
17//! model and §4 for the engine choice.
18//!
19//! ## Example
20//!
21//! ```
22//! use lattice_diff::{compute_diff, DiffAlgorithm, HunkKind};
23//! use ropey::Rope;
24//!
25//! let a = Rope::from("alpha\nbeta\ngamma\n");
26//! let b = Rope::from("alpha\nBETA\ngamma\n");
27//! let hunks = compute_diff(&[a, b], DiffAlgorithm::Histogram)
28//! .expect("two-way is supported");
29//!
30//! assert_eq!(hunks.hunks.len(), 1);
31//! assert_eq!(hunks.hunks[0].kind, HunkKind::Change);
32//! ```
33
34#![deny(unsafe_code)]
35
36pub mod compute;
37pub mod patch;
38// DR.1 (2026-08-12): intra-line refinement — which PART of a changed
39// line changed. Pure; `lattice-magit` and `diff-mode` both consume it.
40pub mod refine;
41pub mod types;
42
43// BC.6 / DX.6 (2026-06-24): the host-attached diff *subsystem*, moved
44// in from `lattice-host::diff`. The pure data layer above
45// (`compute`/`types`/`patch`) stays the bottom of the crate; these
46// layer the sessions + `diff-mode` + presentation providers on top.
47// `lattice-host` re-exports these modules under `crate::diff::*` (the
48// façade) so existing call sites are unchanged; DX.7 collapses the boot
49// wiring into `lattice_diff::install(boot)`.
50pub mod filler;
51pub mod fold;
52pub mod mode;
53// D-fix.5: diff-presentation options (`ui.diff.fold-unchanged`,
54// `ui.diff.context`). Self-register via `linkme` at link time; the
55// module exists so the crate links the registrations into the binary.
56pub mod options;
57pub mod overlay;
58pub mod pane_group;
59pub mod subsystem;
60
61// BC.6 / DX.7: the crate-owned `install(boot)` entry point — one Phase-B
62// line in `editor_boot` (`lattice_diff::install(&mut boot)`), the terminal /
63// claude-code shape. Registers the diff modes; the subsystem bind + keymap
64// push + modeline element stay host-side (see `install` docs for why).
65pub mod install;
66
67// I4 (Claude Code IDE peer, openDiff): the host-drained "open a diff and await
68// the user's verdict" request + its inbound bus. The host drains it and opens a
69// side-by-side diff bound to the request's completion oneshot; the IDE peer (or
70// any in-tree consumer: an LSP WorkspaceEdit preview, a magit-style plugin)
71// produces it.
72pub mod programmatic;
73
74pub use compute::{DiffEngineError, compute_diff};
75pub use install::install;
76pub use programmatic::{ProgrammaticDiffBus, ProgrammaticDiffRequest};
77pub use refine::{RegionRefinement, refine_regions};
78pub use types::{DiffAlgorithm, Hunk, HunkIndex, HunkKind, LineRange};