Skip to main content

Module apply

Module apply 

Source
Expand description

Carry out moves, in order. diffr carries every plugin’s moves out with this applier, and crate::Draft runs the same code on a copy, so a plugin predicts exactly the trees and ids its moves leave.

A move names a region by id, on the one side that holds it, or the file by ROOT. An unknown id is an error.

  • Cut { region, at } splits a leaf into the lines before at, relative to its first line, and the lines from at on; at must fall strictly inside it. The leaf on the other side with its alignment_id, which has the same length, is cut at the same offset. The first piece on each side keeps its leaf’s ids. The second piece takes a fresh id on each side and a fresh alignment_id shared by the two, and its fold_state_id is the id of the lhs piece, or of its only piece. Pieces keep the leaf’s tags and visibility and the changed spans on their lines. A fold, or the file, cannot be cut.
  • JoinFolds { regions } needs two or more region ids. Each side wraps the ones it holds, which must be two or more consecutive siblings under one parent, in a new fold spanning them, with a fresh id, no tags, and an open, unlabelled visibility. When both sides wrap, the two new folds share the lhs fold’s fold_state_id, its id, so a plugin joins a run and the run matched with it on the other side in one move by listing both runs’ ids. A side holding exactly one of the ids is an error, and so is an id no side holds.
  • LinkFoldState { regions } needs two or more region ids. Every region in any of their fold states, on either side, takes the first region’s fold_state_id and whether it starts collapsed.
  • SetCollapsed { region, collapsed } sets whether every region sharing the region’s fold_state_id starts collapsed, on both sides: they open and close together. On ROOT it sets whether the file starts hidden.
  • SetLabel { region, label } sets the label of that region alone, or of the file on ROOT; None clears it.
  • SetTags { region, tags } replaces that region’s tags. The file’s tags are its manifest entry’s, fixed before any diff runs, so ROOT is an error.

Fresh ids start above the largest id in the file (and above ROOT) when a plugin’s moves begin, and fresh alignment_ids above the largest leaf alignment_id; each is handed out in the order the moves need them, lhs before rhs.

Structs§

Applier
Carries out one plugin’s moves, handing out fresh ids as they need them.
Fresh
The next unused id and leaf alignment_id in the file: what a plugin’s moves hand out, in order. A plugin that does not use crate::Draft predicts the ids its cuts and joins create with it.

Functions§

apply
Carry out moves in order.
find
trees_ref