Use CanIgnore atom kind

trailing_commas
Wilfred Hughes 2024-06-29 23:02:31 +07:00
parent a90254ede7
commit 1fab9630cb
4 changed files with 16 additions and 3 deletions

@ -47,6 +47,7 @@ pub(crate) fn insert_deep_unchanged<'a>(
},
) => {
for (child, opposite_child) in node_children.iter().zip(opposite_children) {
// TODO: one side may now be CanIgnore
insert_deep_unchanged(child, opposite_child, change_map);
}
}

@ -267,6 +267,7 @@ impl Highlight {
AtomKind::Comment => Highlight::Comment,
AtomKind::Type => Highlight::Type,
AtomKind::Normal => Highlight::Normal,
AtomKind::CanIgnore => Highlight::Normal,
AtomKind::TreeSitterError => Highlight::TreeSitterError,
},
}

@ -359,7 +359,7 @@ pub(crate) fn color_positions(
style = style.bold();
}
AtomKind::TreeSitterError => style = style.purple(),
AtomKind::Normal => {}
AtomKind::Normal | AtomKind::CanIgnore => {}
}
}
}

@ -433,8 +433,14 @@ fn set_content_id(nodes: &[&Syntax], existing: &mut DftHashMap<ContentKey, u32>)
// Recurse first, so children all have their content_id set.
set_content_id(children, existing);
let children_content_ids: Vec<_> =
children.iter().map(|c| c.info().content_id.get()).collect();
let children_content_ids: Vec<_> = children
.iter()
.filter(|c| match c {
List { .. } => true,
Atom { kind, .. } => *kind != AtomKind::CanIgnore,
})
.map(|c| c.info().content_id.get())
.collect();
(
Some(open_content.clone()),
@ -620,6 +626,11 @@ pub(crate) enum AtomKind {
Comment,
Keyword,
TreeSitterError,
/// Trailing commas can be ignored in some positions, such as the
/// last comma in `[1, 2,]` in JS. However, it's not obligatory,
/// and it's useful when diffing `[1,]` against `[1, 2]` to be
/// able to match up the commas.
CanIgnore,
}
/// Unlike atoms, tokens can be delimiters like `{`.