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