From 4c7ba410a5fdb12514bf3865f075f17d82b024cf Mon Sep 17 00:00:00 2001 From: Wilfred Hughes Date: Sat, 11 Nov 2023 11:26:40 -0800 Subject: Track whether we're entering a significant whitespace list --- src/diff/dijkstra.rs | 8 ++++++-- src/diff/graph.rs | 38 +++++++++++++++++++++++++++++++------- src/parse/syntax.rs | 1 + 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/src/diff/dijkstra.rs b/src/diff/dijkstra.rs index 7b2f01fd5..15597a2a8 100644 --- a/src/diff/dijkstra.rs +++ b/src/diff/dijkstra.rs @@ -416,8 +416,12 @@ mod tests { assert_eq!( actions, vec![ - EnterNovelDelimiterRHS {}, - EnterNovelDelimiterLHS {}, + EnterNovelDelimiterRHS { + significant_whitespace: false + }, + EnterNovelDelimiterLHS { + significant_whitespace: false + }, UnchangedNode { probably_punctuation: false, depth_difference: 0 diff --git a/src/diff/graph.rs b/src/diff/graph.rs index 1e533e9d3..b19033881 100644 --- a/src/diff/graph.rs +++ b/src/diff/graph.rs @@ -296,8 +296,12 @@ pub enum Edge { NovelAtomRHS {}, // TODO: An EnterNovelDelimiterBoth edge might help performance // rather doing LHS and RHS separately. - EnterNovelDelimiterLHS {}, - EnterNovelDelimiterRHS {}, + EnterNovelDelimiterLHS { + significant_whitespace: bool, + }, + EnterNovelDelimiterRHS { + significant_whitespace: bool, + }, } impl Edge { @@ -668,7 +672,12 @@ pub fn set_neighbours<'s, 'b>( )); } // Step into this partially/fully novel list. - Syntax::List { children, .. } => { + Syntax::List { + children, + open_content, + close_content, + .. + } => { let lhs_next = children.get(0).copied(); let parents_next = push_lhs_delimiter(&v.parents, lhs_syntax); @@ -683,7 +692,9 @@ pub fn set_neighbours<'s, 'b>( ); res.push(( - EnterNovelDelimiterLHS {}, + EnterNovelDelimiterLHS { + significant_whitespace: open_content.is_empty() && close_content.is_empty(), + }, allocate_if_new( Vertex { neighbours: RefCell::new(None), @@ -733,7 +744,12 @@ pub fn set_neighbours<'s, 'b>( )); } // Step into this partially/fully novel list. - Syntax::List { children, .. } => { + Syntax::List { + children, + open_content, + close_content, + .. + } => { let rhs_next = children.get(0).copied(); let parents_next = push_rhs_delimiter(&v.parents, rhs_syntax); @@ -747,7 +763,9 @@ pub fn set_neighbours<'s, 'b>( ); res.push(( - EnterNovelDelimiterRHS {}, + EnterNovelDelimiterRHS { + significant_whitespace: open_content.is_empty() && close_content.is_empty(), + }, allocate_if_new( Vertex { neighbours: RefCell::new(None), @@ -818,7 +836,13 @@ pub fn populate_change_map<'s, 'b>( let lhs = v.lhs_syntax.unwrap(); change_map.insert(lhs, ChangeKind::Novel); } - NovelAtomRHS { .. } | EnterNovelDelimiterRHS { .. } => { + NovelAtomRHS { .. } => { + let rhs = v.rhs_syntax.unwrap(); + change_map.insert(rhs, ChangeKind::Novel); + } + EnterNovelDelimiterRHS { + significant_whitespace, + } => { let rhs = v.rhs_syntax.unwrap(); change_map.insert(rhs, ChangeKind::Novel); } diff --git a/src/parse/syntax.rs b/src/parse/syntax.rs index d07bc7a9e..02ea499f9 100644 --- a/src/parse/syntax.rs +++ b/src/parse/syntax.rs @@ -952,6 +952,7 @@ pub fn change_positions<'a>( nodes: &[&'a Syntax<'a>], change_map: &ChangeMap<'a>, ) -> Vec { + // here let mut positions = Vec::new(); change_positions_(nodes, change_map, &mut positions); positions -- cgit v1.2.3