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

Function process_node

internal/cbm/lsp/ts_lsp.c:3324–3688  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3322}
3323
3324static void process_node(TSLSPContext *ctx, TSNode node) {
3325 if (!ctx || ts_node_is_null(node))
3326 return;
3327 const char *kind = ts_node_type(node);
3328
3329 /* A nested statement block owns `let`/`const` declarations. Function-body
3330 * blocks are intentionally unwrapped by process_function_body(), so this
3331 * branch applies only to nested lexical blocks and cannot hide parameters. */
3332 if (strcmp(kind, "statement_block") == 0) {
3333 CBMScope *saved = ctx->current_scope;
3334 ctx->current_scope = cbm_scope_push(ctx->arena, saved);
3335 TSTreeCursor cursor = ts_tree_cursor_new(node);
3336 if (ts_tree_cursor_goto_first_child(&cursor)) {
3337 do {
3338 process_node(ctx, ts_tree_cursor_current_node(&cursor));
3339 } while (ts_tree_cursor_goto_next_sibling(&cursor));
3340 }
3341 ts_tree_cursor_delete(&cursor);
3342 ctx->current_scope = saved;
3343 return;
3344 }
3345
3346 // Scope-affecting statements bind first, then we recurse.
3347 ts_process_statement(ctx, node);
3348
3349 if (strcmp(kind, "call_expression") == 0) {
3350 resolve_call_at(ctx, node);
3351 resolve_value_references_at(ctx, node);
3352
3353 // Contextual callback typing: when an arg is an arrow_function and the
3354 // corresponding param of the called function is itself a FUNC, propagate the
3355 // expected callback param types into the arrow's body before walking it.
3356 // Handle arg processing manually for this path to avoid double-walking via
3357 // default recurse below.
3358 do {
3359 TSNode fn_node =
3360 ts_node_child_by_field_name(node, "function", TS_LSP_FIELD_LEN("function"));
3361 if (ts_node_is_null(fn_node))
3362 break;
3363 TSNode args =
3364 ts_node_child_by_field_name(node, "arguments", TS_LSP_FIELD_LEN("arguments"));
3365 if (ts_node_is_null(args))
3366 break;
3367 const CBMType *fn_type = ts_signature_for_call(ctx, fn_node, args);
3368 if (!fn_type || fn_type->kind != CBM_TYPE_FUNC)
3369 break;
3370 if (!fn_type->data.func.param_types)
3371 break;
3372
3373 // Process the function child for nested call resolution.
3374 process_node(ctx, fn_node);
3375
3376 // param_types is NULL-terminated (no count field). Measure its
3377 // length so we never index past the terminator: a call may pass
3378 // more args than the function declares params (e.g. excess/variadic
3379 // args), and the extra args simply have no expected type. Indexing
3380 // param_types[i] by the raw arg count read out of bounds → garbage
3381 // CBMType* → crash on expected->kind.

Callers 4

process_callback_arrowFunction · 0.85
process_namespace_memberFunction · 0.85
process_function_bodyFunction · 0.85
ts_lsp_process_fileFunction · 0.85

Calls 15

cbm_scope_pushFunction · 0.85
ts_process_statementFunction · 0.85
resolve_call_atFunction · 0.85
ts_signature_for_callFunction · 0.85
process_callback_arrowFunction · 0.85
resolve_jsx_elementFunction · 0.85
node_textFunction · 0.85
cbm_scope_lookupFunction · 0.85
cbm_registry_lookup_typeFunction · 0.85
cbm_scope_bindFunction · 0.85
extract_narrowingFunction · 0.85

Tested by

no test coverage detected