From 5032b341a71ef08777a0091cb32806ce777c0989 Mon Sep 17 00:00:00 2001 From: Amaan Qureshi Date: Fri, 27 Sep 2024 16:10:07 -0400 Subject: [PATCH] fix(lib): set the error cost of children that are terminal error nodes, as they have not been set yet --- lib/src/subtree.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/src/subtree.c b/lib/src/subtree.c index ba04feda..03bab364 100644 --- a/lib/src/subtree.c +++ b/lib/src/subtree.c @@ -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);