MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / rs_first_error

Function rs_first_error

internal/cbm/doclink_rs.c:3515–3553  ·  view source on GitHub ↗

The first ERROR or MISSING node of the tree, in document order, that is not * contained (rs_error_contained); a null node when there is none. Walks only * the nodes that hold an error, with a cursor. */

Source from the content-addressed store, hash-verified

3513 * contained (rs_error_contained); a null node when there is none. Walks only
3514 * the nodes that hold an error, with a cursor. */
3515static TSNode rs_first_error(const rs_scan_t *s, TSNode root) {
3516 TSNode found = {0};
3517 if (!ts_node_has_error(root)) {
3518 return found;
3519 }
3520 TSTreeCursor cur = ts_tree_cursor_new(root);
3521 int depth = 0;
3522 int block_depth = CBM_NOT_FOUND; /* depth of the outermost block around the cursor */
3523 for (bool more = true; more;) {
3524 TSNode n = ts_tree_cursor_current_node(&cur);
3525 bool error = ts_node_is_missing(n) || rs_kind(n, "ERROR");
3526 if (error && !rs_error_contained(s, n, block_depth >= 0)) {
3527 found = n;
3528 break;
3529 }
3530 if (block_depth < 0 && rs_kind(n, "block")) {
3531 block_depth = depth;
3532 }
3533 if (!error && ts_node_has_error(n) && ts_tree_cursor_goto_first_child(&cur)) {
3534 depth++;
3535 continue;
3536 }
3537 for (;;) { /* on to the next node: a sibling, or an ancestor's sibling */
3538 if (block_depth == depth) {
3539 block_depth = CBM_NOT_FOUND; /* leaving the block itself */
3540 }
3541 if (ts_tree_cursor_goto_next_sibling(&cur)) {
3542 break;
3543 }
3544 if (!ts_tree_cursor_goto_parent(&cur)) {
3545 more = false;
3546 break;
3547 }
3548 depth--;
3549 }
3550 }
3551 ts_tree_cursor_delete(&cur);
3552 return found;
3553}
3554
3555static int rs_u32_cmp(const void *a, const void *b) {
3556 uint32_t x = *(const uint32_t *)a;

Callers 1

Calls 2

rs_kindFunction · 0.85
rs_error_containedFunction · 0.85

Tested by

no test coverage detected