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

Function process_function_body

internal/cbm/lsp/ts_lsp.c:3690–3758  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3688}
3689
3690static void process_function_body(TSLSPContext *ctx, TSNode func_node, const char *func_qn,
3691 const char *class_qn) {
3692 if (ts_node_is_null(func_node))
3693 return;
3694 CBMScope *saved_scope = ctx->current_scope;
3695 const char *saved_func = ctx->enclosing_func_qn;
3696 const char *saved_class = ctx->enclosing_class_qn;
3697
3698 ctx->current_scope = cbm_scope_push(ctx->arena, saved_scope);
3699 ctx->enclosing_func_qn = func_qn;
3700 ctx->enclosing_class_qn = class_qn ? class_qn : saved_class;
3701
3702 if (class_qn) {
3703 // Bind `this` to the class type for member resolution within methods.
3704 cbm_scope_bind(ctx->current_scope, "this", cbm_type_named(ctx->arena, class_qn));
3705 }
3706
3707 TSNode params =
3708 ts_node_child_by_field_name(func_node, "parameters", TS_LSP_FIELD_LEN("parameters"));
3709 if (!ts_node_is_null(params)) {
3710 uint32_t nc = ts_node_named_child_count(params);
3711 for (uint32_t i = 0; i < nc; i++)
3712 bind_parameter(ctx, ts_node_named_child(params, i));
3713
3714 // JSDoc / signature-derived param-type fallback: if bind_parameter left a
3715 // param bound to UNKNOWN (no inline TS annotation), use the registered func's
3716 // signature param_types[i] (which apply_jsdoc_signatures may have populated).
3717 if (func_qn) {
3718 const CBMRegisteredFunc *rf = cbm_registry_lookup_func(ctx->registry, func_qn);
3719 if (rf && rf->signature && rf->signature->kind == CBM_TYPE_FUNC &&
3720 rf->signature->data.func.param_names && rf->signature->data.func.param_types) {
3721 for (int i = 0; rf->signature->data.func.param_names[i] &&
3722 rf->signature->data.func.param_types[i];
3723 i++) {
3724 const char *pname = rf->signature->data.func.param_names[i];
3725 const CBMType *ptype = rf->signature->data.func.param_types[i];
3726 if (cbm_type_is_unknown(ptype))
3727 continue;
3728 const CBMType *existing = cbm_scope_lookup(ctx->current_scope, pname);
3729 if (existing && !cbm_type_is_unknown(existing))
3730 continue;
3731 cbm_scope_bind(ctx->current_scope, pname, ptype);
3732 }
3733 }
3734 }
3735 }
3736
3737 TSNode body = ts_node_child_by_field_name(func_node, "body", TS_LSP_FIELD_LEN("body"));
3738 if (!ts_node_is_null(body)) {
3739 // statement_block: walk every child statement. Expression body (concise
3740 // arrow): walk the expression directly — process_node on that handles
3741 // call_expression resolution.
3742 if (strcmp(ts_node_type(body), "statement_block") == 0) {
3743 TSTreeCursor cursor = ts_tree_cursor_new(body);
3744 if (ts_tree_cursor_goto_first_child(&cursor)) {
3745 do {
3746 process_node(ctx, ts_tree_cursor_current_node(&cursor));
3747 } while (ts_tree_cursor_goto_next_sibling(&cursor));

Callers 3

process_namespace_memberFunction · 0.85
process_nodeFunction · 0.85
ts_lsp_process_fileFunction · 0.85

Calls 8

cbm_scope_pushFunction · 0.85
cbm_scope_bindFunction · 0.85
cbm_type_namedFunction · 0.85
bind_parameterFunction · 0.85
cbm_registry_lookup_funcFunction · 0.85
cbm_type_is_unknownFunction · 0.85
cbm_scope_lookupFunction · 0.85
process_nodeFunction · 0.85

Tested by

no test coverage detected