diff options
author | Wilfred Hughes <me@wilfred.me.uk> | 2021-07-22 00:05:00 -0700 |
---|---|---|
committer | Wilfred Hughes <me@wilfred.me.uk> | 2021-07-22 00:07:09 -0700 |
commit | 5d2c14a3f9920d7b8f8e5445e9fcda334e3fcf09 (patch) | |
tree | 3a7cea768f44794c39112ef7d74dd33a5eeeac31 | |
parent | 61446c916aef80d78ccd408f2c4dda3e303a24a9 (diff) |
Entering a list should set the prev_novel state to the open delimiter0.5
-rw-r--r-- | CHANGELOG.md | 3 | ||||
-rw-r--r-- | src/dijkstra.rs | 41 |
2 files changed, 42 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 35d86b54e..c78441e07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,9 @@ Reduced memory usage when diffing. Difftastic now highlights word-level changes between comments. +Diffing now prefers contiguous nodes even when entering a list, so +`(foo` is considered contiguous. + Large AST trees with very few common nodes are now considered wholly novel, rather than trying to match up the few common nodes. This avoids nonsensical diffs when toplevel function A is completely diff --git a/src/dijkstra.rs b/src/dijkstra.rs index 6c4d1ecce..5bbbeed11 100644 --- a/src/dijkstra.rs +++ b/src/dijkstra.rs @@ -291,6 +291,7 @@ fn neighbours<'a>(v: &Vertex<'a>) -> Vec<(Edge, Vertex<'a>)> { } // Step into this partially/fully novel list. Syntax::List { + open_position, children, num_descendants, .. @@ -308,7 +309,7 @@ fn neighbours<'a>(v: &Vertex<'a>) -> Vec<(Edge, Vertex<'a>)> { }, Vertex { lhs_syntax: lhs_next, - lhs_prev_novel: v.lhs_prev_novel, + lhs_prev_novel: open_position.last().map(|lp| lp.line), rhs_syntax: v.rhs_syntax, rhs_prev_novel: v.rhs_prev_novel, }, @@ -349,6 +350,7 @@ fn neighbours<'a>(v: &Vertex<'a>) -> Vec<(Edge, Vertex<'a>)> { } // Step into this partially/fully novel list. Syntax::List { + open_position, children, num_descendants, .. @@ -367,7 +369,7 @@ fn neighbours<'a>(v: &Vertex<'a>) -> Vec<(Edge, Vertex<'a>)> { lhs_syntax: v.lhs_syntax, lhs_prev_novel: v.lhs_prev_novel, rhs_syntax: rhs_next, - rhs_prev_novel: v.rhs_prev_novel, + rhs_prev_novel: open_position.last().map(|lp| lp.line), }, )); @@ -665,6 +667,7 @@ mod tests { ], ); } + #[test] fn prefer_atoms_same_line() { let arena = Arena::new(); @@ -699,6 +702,40 @@ mod tests { } #[test] + fn prefer_children_same_line() { + let arena = Arena::new(); + + let lhs: Vec<&Syntax> = vec![Syntax::new_list( + &arena, + "[".into(), + col_helper(1, 0), + vec![Syntax::new_atom(&arena, col_helper(1, 2), "1")], + "]".into(), + pos_helper(2), + )]; + init_info(&lhs); + + let rhs: Vec<&Syntax> = vec![]; + + let start = Vertex { + lhs_syntax: lhs.get(0).map(|n| *n), + lhs_prev_novel: None, + rhs_syntax: rhs.get(0).map(|n| *n), + rhs_prev_novel: None, + }; + let route = shortest_path(start); + + let actions = route.iter().map(|(action, _)| *action).collect_vec(); + assert_eq!( + actions, + vec![ + NovelDelimiterLHS { contiguous: false }, + NovelAtomLHS { contiguous: true }, + ] + ); + } + + #[test] fn test_novel_tree() { let arena = Arena::new(); |