fix(lib): set the error cost of children that are terminal error nodes, as they have not been set yet

This commit is contained in:
Amaan Qureshi 2024-09-27 16:10:07 -04:00
parent b2359e4020
commit 5032b341a7
No known key found for this signature in database
GPG key ID: E67890ADC4227273

View file

@ -435,6 +435,14 @@ void ts_subtree_summarize_children(
}
}
// This is a terminal ERROR node that hasn't had its error cost assigned to it yet.
if (ts_subtree_is_error(child) && grandchild_count == 0) {
MutableSubtree child_mut = ts_subtree_to_mut_unsafe(child);
child_mut.ptr->error_cost = ERROR_COST_PER_RECOVERY +
ERROR_COST_PER_SKIPPED_CHAR * child.ptr->size.bytes +
ERROR_COST_PER_SKIPPED_LINE * child.ptr->size.extent.row;
}
self.ptr->dynamic_precedence += ts_subtree_dynamic_precedence(child);
self.ptr->visible_descendant_count += ts_subtree_visible_descendant_count(child);