Skip to content

Commit

Permalink
Use CanIgnore atom kind
Browse files Browse the repository at this point in the history
  • Loading branch information
Wilfred committed Jun 30, 2024
1 parent ca0540b commit de62036
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/display/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}
Expand Down
2 changes: 1 addition & 1 deletion src/display/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ pub(crate) fn color_positions(
style = style.bold();
}
AtomKind::TreeSitterError => style = style.purple(),
AtomKind::Normal => {}
AtomKind::Normal | AtomKind::CanIgnore => {}
}
}
}
Expand Down
15 changes: 13 additions & 2 deletions src/parse/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,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()),
Expand Down Expand Up @@ -579,6 +585,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 `{`.
Expand Down
9 changes: 3 additions & 6 deletions src/parse/tree_sitter_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1875,15 +1875,12 @@ fn list_from_cursor<'a>(
if should_ignore_last_child(config, &root_node, &between_delim) {
if let Some(last_child) = between_delim.pop() {
if let Syntax::Atom {
position,
content,
kind,
..
position, content, ..
} = last_child
{
let position = position.clone();
// TODO: New unused kind for atoms.
let new_last_child = Syntax::new_atom(arena, position, content, *kind);
let new_last_child =
Syntax::new_atom(arena, position, content, AtomKind::CanIgnore);
between_delim.push(new_last_child);
}
}
Expand Down

0 comments on commit de62036

Please sign in to comment.