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

Function push_method_def

internal/cbm/extract_defs.c:8363–8459  ·  view source on GitHub ↗

Push a single method definition

Source from the content-addressed store, hash-verified

8361
8362// Push a single method definition
8363static void push_method_def(CBMExtractCtx *ctx, TSNode child, TSNode class_node,
8364 const char *class_qn, const CBMLangSpec *spec, TSNode name_node) {
8365 CBMArena *a = ctx->arena;
8366
8367 char *name = cbm_func_name_node_text(a, name_node, ctx->source, ctx->language);
8368 if (!name || !name[0]) {
8369 return;
8370 }
8371
8372 const char *method_qn = cbm_arena_sprintf(a, "%s.%s", class_qn, name);
8373
8374 CBMDefinition def;
8375 memset(&def, 0, sizeof(def));
8376 def.name = name;
8377 def.qualified_name = method_qn;
8378 def.label = "Method";
8379 def.file_path = ctx->rel_path;
8380 def.parent_class = class_qn;
8381 def.start_line = ts_node_start_point(child).row + TS_LINE_OFFSET;
8382 def.end_line = ts_node_end_point(child).row + TS_LINE_OFFSET;
8383 def.lines = (int)(def.end_line - def.start_line + TS_LINE_OFFSET);
8384 def.is_exported = cbm_is_exported(name, ctx->language);
8385 if (ctx->language == CBM_LANG_RUST &&
8386 strcmp(ts_node_type(child), "function_signature_item") == 0) {
8387 def.is_abstract = true;
8388 }
8389
8390 TSNode params = find_function_params(child, ctx->language);
8391 if (!ts_node_is_null(params)) {
8392 def.signature = cbm_node_text(a, params, ctx->source);
8393 def.param_types = extract_param_types(a, params, ctx->source, ctx->language);
8394 def.signature_param_types = extract_signature_param_types(
8395 a, params, ctx->source, ctx->language, true, &def.signature_param_count);
8396 }
8397
8398 // Return type (same fields as extract_func_def)
8399 {
8400 static const char *rt_fields[] = {"result", "return_type", "type", NULL};
8401 for (const char **f = rt_fields; *f; f++) {
8402 TSNode rt = ts_node_child_by_field_name(child, *f, (uint32_t)strlen(*f));
8403 if (!ts_node_is_null(rt)) {
8404 def.return_type = c_declared_return_type(ctx, child, rt);
8405 break;
8406 }
8407 }
8408 }
8409
8410 // ObjectScript: return type is method_definition -> return_type -> typename.
8411 if (!def.return_type && (ctx->language == CBM_LANG_OBJECTSCRIPT_UDL ||
8412 ctx->language == CBM_LANG_OBJECTSCRIPT_ROUTINE)) {
8413 TSNode mdef = cbm_find_child_by_kind(child, "method_definition");
8414 if (ts_node_is_null(mdef)) {
8415 mdef = child;
8416 }
8417 TSNode rt_node = cbm_find_child_by_kind(mdef, "return_type");
8418 if (!ts_node_is_null(rt_node)) {
8419 TSNode tname = cbm_find_child_by_kind(rt_node, "typename");
8420 if (!ts_node_is_null(tname)) {

Callers 2

extract_class_methodsFunction · 0.85

Calls 15

cbm_func_name_node_textFunction · 0.85
cbm_is_exportedFunction · 0.85
find_function_paramsFunction · 0.85
cbm_node_textFunction · 0.85
extract_param_typesFunction · 0.85
c_declared_return_typeFunction · 0.85
cbm_find_child_by_kindFunction · 0.85
extract_decoratorsFunction · 0.85

Tested by

no test coverage detected