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

Function process_function

internal/cbm/lsp/go_lsp.c:1980–2115  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1978// --- Process a single function body ---
1979
1980static void process_function(GoLSPContext *ctx, TSNode func_node) {
1981 // Set enclosing function QN
1982 TSNode name_node = ts_node_child_by_field_name(func_node, "name", 4);
1983 if (ts_node_is_null(name_node))
1984 return;
1985
1986 char *func_name = lsp_node_text(ctx, name_node);
1987 if (!func_name || !func_name[0])
1988 return;
1989
1990 // Enclosing-function QN must be the BARE package.Func form (no receiver
1991 // type segment). The textual call events (extract_unified.c) source calls
1992 // as package_qn.func_name — methods included — and the defs pass creates
1993 // the graph Method node under the same QN, so any other form breaks the
1994 // caller-QN join in cbm_pipeline_find_lsp_resolution and the LSP-resolved
1995 // call silently falls back to the registry short-name resolver. The
1996 // receiver type still reaches the registry via the def's parent_class /
1997 // method->receiver_type; it just does not appear in the caller QN.
1998 ctx->enclosing_func_qn = cbm_arena_sprintf(ctx->arena, "%s.%s", ctx->package_qn, func_name);
1999
2000 // Push function scope
2001 CBMScope *saved_scope = ctx->current_scope;
2002 ctx->current_scope = cbm_scope_push(ctx->arena, ctx->current_scope);
2003
2004 // Bind parameters into scope (including variadic)
2005 TSNode params = ts_node_child_by_field_name(func_node, "parameters", 10);
2006 if (!ts_node_is_null(params)) {
2007 uint32_t nc = ts_node_child_count(params);
2008 for (uint32_t i = 0; i < nc; i++) {
2009 TSNode param = ts_node_child(params, i);
2010 if (ts_node_is_null(param) || !ts_node_is_named(param))
2011 continue;
2012 const char *pk = ts_node_type(param);
2013
2014 bool is_variadic = (strcmp(pk, "variadic_parameter_declaration") == 0);
2015 if (!is_variadic && strcmp(pk, "parameter_declaration") != 0)
2016 continue;
2017
2018 // Get type
2019 TSNode type_node = ts_node_child_by_field_name(param, "type", 4);
2020 const CBMType *param_type = go_parse_type_node(ctx, type_node);
2021
2022 // Variadic: ...T is []T in the function body
2023 if (is_variadic && param_type) {
2024 param_type = cbm_type_slice(ctx->arena, param_type);
2025 }
2026
2027 // Get name(s) — Go allows multiple names per declaration: a, b int
2028 uint32_t pnc = ts_node_child_count(param);
2029 for (uint32_t j = 0; j < pnc; j++) {
2030 TSNode child = ts_node_child(param, j);
2031 if (ts_node_is_null(child) || !ts_node_is_named(child))
2032 continue;
2033 if (strcmp(ts_node_type(child), "identifier") == 0) {
2034 char *pname = lsp_node_text(ctx, child);
2035 if (pname && strcmp(pname, "_") != 0) {
2036 cbm_scope_bind(ctx->current_scope, pname, param_type);
2037 }

Callers 1

go_lsp_process_fileFunction · 0.85

Calls 7

lsp_node_textFunction · 0.85
cbm_scope_pushFunction · 0.85
go_parse_type_nodeFunction · 0.85
cbm_type_sliceFunction · 0.85
cbm_scope_bindFunction · 0.85
resolve_calls_in_nodeFunction · 0.85
cbm_arena_sprintfFunction · 0.50

Tested by

no test coverage detected