Entering a list should set the prev_novel state to the open delimiter

pull/25/head 0.5
Wilfred Hughes 2021-07-22 00:05:00 +07:00
parent 61446c916a
commit 5d2c14a3f9
2 changed files with 42 additions and 2 deletions

@ -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

@ -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();
@ -698,6 +701,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();