Add an opt-in detailed text diff
This commit is contained in:
parent
ab308f7b7f
commit
f3275fc161
1 changed files with 266 additions and 45 deletions
102
src/review.rs
102
src/review.rs
|
|
@ -1202,6 +1202,15 @@ pub struct Comparison {
|
|||
pub diagnostics: Vec<Diagnostic>,
|
||||
}
|
||||
|
||||
/// Additional presentation options for a text comparison.
|
||||
#[derive(Clone, Copy, Debug, Default)]
|
||||
pub struct TextReportOptions {
|
||||
/// Print individual object evidence, including both sides of replacements.
|
||||
pub details: bool,
|
||||
/// Append the ASCII hierarchy at this depth when provided.
|
||||
pub ascii_depth: Option<usize>,
|
||||
}
|
||||
|
||||
/// A comparison for text and hierarchy reports.
|
||||
#[derive(Debug)]
|
||||
pub struct TextComparison {
|
||||
|
|
@ -1229,6 +1238,17 @@ impl TextComparison {
|
|||
.render_text(max_objects, show, show_library_presence)
|
||||
}
|
||||
|
||||
pub fn render_text_with_options(
|
||||
&self,
|
||||
max_objects: usize,
|
||||
show: &DisplayFilter,
|
||||
show_library_presence: bool,
|
||||
options: TextReportOptions,
|
||||
) -> String {
|
||||
self.comparison
|
||||
.render_text_with_options(max_objects, show, show_library_presence, options)
|
||||
}
|
||||
|
||||
/// Render the cell changes and their ASCII hierarchy together.
|
||||
pub fn render_text_with_ascii_hierarchy(
|
||||
&self,
|
||||
|
|
@ -1457,7 +1477,12 @@ impl Comparison {
|
|||
show: &DisplayFilter,
|
||||
show_library_presence: bool,
|
||||
) -> String {
|
||||
self.render_text_report(max_objects, show, show_library_presence, None)
|
||||
self.render_text_with_options(
|
||||
max_objects,
|
||||
show,
|
||||
show_library_presence,
|
||||
TextReportOptions::default(),
|
||||
)
|
||||
}
|
||||
|
||||
/// Render the cell changes and omit simple hierarchy edges already shown there.
|
||||
|
|
@ -1468,16 +1493,29 @@ impl Comparison {
|
|||
show_library_presence: bool,
|
||||
max_depth: usize,
|
||||
) -> String {
|
||||
self.render_text_report(max_objects, show, show_library_presence, Some(max_depth))
|
||||
self.render_text_with_options(
|
||||
max_objects,
|
||||
show,
|
||||
show_library_presence,
|
||||
TextReportOptions {
|
||||
ascii_depth: Some(max_depth),
|
||||
..TextReportOptions::default()
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
fn render_text_report(
|
||||
/// Render the selected changes with optional object details and ASCII hierarchy.
|
||||
pub fn render_text_with_options(
|
||||
&self,
|
||||
max_objects: usize,
|
||||
show: &DisplayFilter,
|
||||
show_library_presence: bool,
|
||||
ascii_depth: Option<usize>,
|
||||
options: TextReportOptions,
|
||||
) -> String {
|
||||
let TextReportOptions {
|
||||
details,
|
||||
ascii_depth,
|
||||
} = options;
|
||||
let outcome = self.outcome();
|
||||
let mut out = match outcome {
|
||||
Outcome::Equal => "Equal",
|
||||
|
|
@ -1594,27 +1632,36 @@ impl Comparison {
|
|||
}
|
||||
paired_old.insert(replacement.removed);
|
||||
paired_new.insert(replacement.added);
|
||||
if max_objects - shown >= 2 {
|
||||
if max_objects - shown < 2 {
|
||||
continue;
|
||||
}
|
||||
if !details && a.layer == b.layer && is_polygon(a.kind) {
|
||||
polygons.replacement(a, b);
|
||||
} else {
|
||||
out.push_str(" ~ ");
|
||||
let row_start = out.len();
|
||||
if a.layer != b.layer {
|
||||
out.push_str(" ~ ");
|
||||
changes::write_layer_transition(&mut out, a, b, Some(&mut layers));
|
||||
out.push('\n');
|
||||
} else if is_polygon(a.kind) {
|
||||
polygons.replacement(a, b);
|
||||
} else {
|
||||
out.push_str(" ~ ");
|
||||
let row_start = out.len();
|
||||
layers.record(a.layer, row_start);
|
||||
writeln!(out, "{}", changes::replacement_summary(a, b)).unwrap();
|
||||
if let Some(target) = &a.target {
|
||||
shown_refs
|
||||
.entry(target)
|
||||
.or_default()
|
||||
.replacement(a, b, row_start);
|
||||
if details {
|
||||
out.push_str(&changes::replacement_heading(a, b));
|
||||
} else {
|
||||
out.push_str(&changes::replacement_summary(a, b));
|
||||
}
|
||||
}
|
||||
shown += 2;
|
||||
out.push('\n');
|
||||
if details {
|
||||
changes::write_replacement_objects(&mut out, a, b);
|
||||
}
|
||||
if let Some(target) = &a.target {
|
||||
shown_refs
|
||||
.entry(target)
|
||||
.or_default()
|
||||
.replacement(a, b, row_start);
|
||||
}
|
||||
}
|
||||
shown += 2;
|
||||
}
|
||||
let mut removed_refs = BTreeMap::new();
|
||||
let mut added_refs = BTreeMap::new();
|
||||
|
|
@ -1630,9 +1677,9 @@ impl Comparison {
|
|||
}
|
||||
selected += 1;
|
||||
if !paired.contains(&index) && shown < max_objects {
|
||||
if is_polygon(object.kind) {
|
||||
if !details && is_polygon(object.kind) {
|
||||
polygons.unmatched(object, removed);
|
||||
} else if let Some(target) = object.target.as_deref() {
|
||||
} else if !details && let Some(target) = object.target.as_deref() {
|
||||
let (_, counts) = references
|
||||
.entry(target)
|
||||
.or_insert_with(|| (object, changes::ReferenceCounts::default()));
|
||||
|
|
@ -1655,8 +1702,19 @@ impl Comparison {
|
|||
if count > 1 {
|
||||
write!(out, "{count}× ").unwrap();
|
||||
}
|
||||
layers.record(object.layer, out.len());
|
||||
changes::write_unmatched(&mut out, object);
|
||||
let row_start = out.len();
|
||||
layers.record(object.layer, row_start);
|
||||
if details {
|
||||
writeln!(out, "{object}").unwrap();
|
||||
if let Some(target) = object.target.as_deref() {
|
||||
shown_refs
|
||||
.entry(target)
|
||||
.or_default()
|
||||
.individual(object, removed, count, row_start);
|
||||
}
|
||||
} else {
|
||||
changes::write_unmatched(&mut out, object);
|
||||
}
|
||||
}
|
||||
}
|
||||
let no_refs = changes::ReferenceCounts::default();
|
||||
|
|
|
|||
Loading…
Reference in a new issue