pub fn compute_diff(
sources: &[Rope],
algorithm: DiffAlgorithm,
) -> Result<HunkIndex, DiffEngineError>Expand description
D.8.a: the engine’s only public dispatch entry. Routes by
sources.len() to the appropriate algorithm, returning a
typed error for arities outside the supported range.
- N=0:
Err(DiffEngineError::Empty)— there’s nothing to diff. Callers should never reach this; defensive. - N=1: empty
HunkIndex— a single participant has no peers to compare against. The session is “dormant” in the subsystem’s terms (D.8.e); the first:diffthislands here, before a second:diffthisextends it to N=2. - N=2: dispatches to [
two_way]. - N=3: dispatches to [
three_way]. - N≥4:
Err(DiffEngineError::Unsupported { n }). v1 cap. The reference table in §12 ofdocs/dev/architecture/n-way-diff-membership.mdsurveys how other editors handle this — Helix/Zed/VSCode also don’t support N≥4; Vim does via pairwise-vs-anchor. The cap moves when user-feedback signals N>3 is wanted.
compute_diff is the only public entry — all external
callers go through it. The dispatch decision lives entirely
inside this function so consumers never branch on arity.