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

Function py_process_function

internal/cbm/lsp/py_lsp.c:4365–4414  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4363}
4364
4365static void py_process_function(PyLSPContext *ctx, TSNode func_node, const char *container_qn) {
4366 if (!ctx || ctx->eval_failure)
4367 return;
4368 TSNode name_node = ts_node_child_by_field_name(func_node, "name", 4);
4369 if (ts_node_is_null(name_node))
4370 return;
4371 char *fname = py_node_text(ctx, name_node);
4372 if (!fname || !fname[0])
4373 return;
4374
4375 const char *prev_func = ctx->enclosing_func_qn;
4376 const char *base_qn = container_qn ? container_qn : ctx->module_qn;
4377 ctx->enclosing_func_qn = cbm_arena_sprintf(ctx->arena, "%s.%s", base_qn, fname);
4378
4379 CBMScope *saved = ctx->current_scope;
4380 ctx->current_scope = py_scope_push_checked(ctx);
4381
4382 TSNode params = ts_node_child_by_field_name(func_node, "parameters", 10);
4383 py_bind_parameters(ctx, params);
4384
4385 // For methods, bind `self`/`cls` AFTER param walk so the receiver type
4386 // wins over the unannotated `self` / `cls` parameter declaration.
4387 if (ctx->enclosing_class_qn) {
4388 py_scope_bind(ctx, "self", cbm_type_named(ctx->arena, ctx->enclosing_class_qn));
4389 py_scope_bind(ctx, "cls", cbm_type_named(ctx->arena, ctx->enclosing_class_qn));
4390 }
4391
4392 TSNode body = ts_node_child_by_field_name(func_node, "body", 4);
4393 if (!ts_node_is_null(body)) {
4394 py_resolve_calls_in(ctx, body);
4395 // Also descend into nested function/class definitions in the body.
4396 PyKids bk = py_kids(ctx->arena, body);
4397 for (uint32_t i = 0; i < bk.n; i++) {
4398 TSNode c = py_kid(&bk, i);
4399 const char *ck = ts_node_type(c);
4400 if (strcmp(ck, "function_definition") == 0) {
4401 py_process_function(ctx, c, ctx->enclosing_func_qn);
4402 } else if (strcmp(ck, "decorated_definition") == 0) {
4403 TSNode def = ts_node_child_by_field_name(c, "definition", 10);
4404 if (!ts_node_is_null(def) &&
4405 strcmp(ts_node_type(def), "function_definition") == 0) {
4406 py_process_function(ctx, def, ctx->enclosing_func_qn);
4407 }
4408 }
4409 }
4410 }
4411
4412 py_scope_restore(ctx, saved);
4413 ctx->enclosing_func_qn = prev_func;
4414}
4415
4416/* Return true iff func_node's name is __init__ or __post_init__. */
4417static bool py_is_init_method(PyLSPContext *ctx, TSNode func_node) {

Callers 2

py_process_classFunction · 0.85
py_lsp_process_fileFunction · 0.85

Calls 10

py_node_textFunction · 0.85
py_scope_push_checkedFunction · 0.85
py_bind_parametersFunction · 0.85
py_scope_bindFunction · 0.85
cbm_type_namedFunction · 0.85
py_resolve_calls_inFunction · 0.85
py_kidsFunction · 0.85
py_kidFunction · 0.85
py_scope_restoreFunction · 0.85
cbm_arena_sprintfFunction · 0.50

Tested by

no test coverage detected