Prefer Option for converting tree-sitter nodes to difftastic nodes

pull/392/head
Wilfred Hughes 2022-09-20 09:12:34 +07:00
parent c67a3d339a
commit af73c27cd2
1 changed files with 6 additions and 6 deletions

@ -1071,7 +1071,7 @@ fn syntax_from_cursor<'a>(
cursor: &mut ts::TreeCursor,
config: &TreeSitterConfig,
highlights: &HighlightedNodeIds,
) -> Vec<&'a Syntax<'a>> {
) -> Option<&'a Syntax<'a>> {
let node = cursor.node();
if node.is_error() {
@ -1090,9 +1090,9 @@ fn syntax_from_cursor<'a>(
// of whether they have children.
atom_from_cursor(arena, src, nl_pos, cursor, highlights)
} else if node.child_count() > 0 {
vec![list_from_cursor(
Some(list_from_cursor(
arena, src, nl_pos, cursor, config, highlights,
)]
))
} else {
atom_from_cursor(arena, src, nl_pos, cursor, highlights)
}
@ -1216,7 +1216,7 @@ fn atom_from_cursor<'a>(
nl_pos: &NewlinePositions,
cursor: &mut ts::TreeCursor,
highlights: &HighlightedNodeIds,
) -> Vec<&'a Syntax<'a>> {
) -> Option<&'a Syntax<'a>> {
let node = cursor.node();
let position = nl_pos.from_offsets(node.start_byte(), node.end_byte());
let mut content = &src[node.start_byte()..node.end_byte()];
@ -1226,7 +1226,7 @@ fn atom_from_cursor<'a>(
// not visible, but leads us to highlight unchanged lines that
// happen to have preceding newline node.
if node.kind() == "\n" {
return vec![];
return None;
}
// JSX trims whitespace at the beginning and end of text nodes.
@ -1259,7 +1259,7 @@ fn atom_from_cursor<'a>(
AtomKind::Normal
};
vec![Syntax::new_atom(arena, position, content, highlight)]
Some(Syntax::new_atom(arena, position, content, highlight))
}
#[cfg(test)]