summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilfred Hughes <me@wilfred.me.uk>2023-11-11 11:26:40 -0800
committerWilfred Hughes <me@wilfred.me.uk>2023-11-11 11:26:40 -0800
commit4c7ba410a5fdb12514bf3865f075f17d82b024cf (patch)
tree697a303e54c5e3140bb4a10e2e7aaea074bc0c11
parent142144e4848ec1a26b5d4214abf34c3a14d72330 (diff)
Track whether we're entering a significant whitespace listsignificant_whitespace
-rw-r--r--src/diff/dijkstra.rs8
-rw-r--r--src/diff/graph.rs38
-rw-r--r--src/parse/syntax.rs1
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<MatchedPos> {
+ // here
let mut positions = Vec::new();
change_positions_(nodes, change_map, &mut positions);
positions