Skip to content

Commit

Permalink
fix improper distinction of errors and extras
Browse files Browse the repository at this point in the history
  • Loading branch information
SpontanCombust committed Aug 15, 2024
1 parent 2898a54 commit 5ee6a42
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions crates/core/src/syntax_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,7 @@ impl<'script, T> SyntaxNode<'script, T> {

/// Whether any nodes descending from this node are errors
pub fn has_errors(&self) -> bool {
self.use_cursor(|mut cursor| {
let any_errors = self.tree_node
.children(&mut cursor)
.any(|child| child.has_error());

(cursor, any_errors)
})
self.tree_node.has_error()
}

/// Returns an iterator over ERROR or missing children nodes
Expand Down Expand Up @@ -161,8 +155,7 @@ impl<'script, T> SyntaxNode<'script, T> {

#[inline]
pub fn is_comment(&self) -> bool {
// comments are the only syntax that creates nodes but is also treated as whitespace
self.tree_node.is_extra()
self.tree_node.kind() == "comment"
}

#[inline]
Expand Down Expand Up @@ -417,15 +410,14 @@ impl<'script> Iterator for SyntaxNodeChildrenDetailed<'script> {
fn next(&mut self) -> Option<Self::Item> {
if self.any_children_left {
let mut n = self.cursor.node();
while n.is_extra()
while (n.is_extra() && !n.is_error()) // all errors are extras, not all extras are errors
|| (self.must_be_named && !n.is_named()) {
if self.cursor.goto_next_sibling() {
n = self.cursor.node();
} else {
return None;
}
}


let res = if n.is_error() {
Err(ErrorNode::new(n))
Expand Down

0 comments on commit 5ee6a42

Please sign in to comment.