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

Function compute_elixir_func_qn

internal/cbm/extract_unified.c:165–196  ·  view source on GitHub ↗

Resolve an Elixir def/defp/defmacro's QN for scope tracking. The def is a * `call` node whose target (first child) is the def macro and whose first * argument is either the function head call `name(args)` or a bare identifier * (zero-arg). Returns NULL for a non-def `call` (e.g. the in-body `add(x,1)` * call, whose target is not a def macro) so only defs push a scope. Mirrors * extract_elixir

Source from the content-addressed store, hash-verified

163 * call, whose target is not a def macro) so only defs push a scope. Mirrors
164 * extract_elixir_func_def() in extract_defs.c. */
165static const char *compute_elixir_func_qn(CBMExtractCtx *ctx, TSNode node) {
166 if (ts_node_child_count(node) == 0) {
167 return NULL;
168 }
169 char *macro = cbm_node_text(ctx->arena, ts_node_child(node, 0), ctx->source);
170 if (!macro || (strcmp(macro, "def") != 0 && strcmp(macro, "defp") != 0 &&
171 strcmp(macro, "defmacro") != 0)) {
172 return NULL;
173 }
174 TSNode args = ts_node_child_by_field_name(node, TS_FIELD("arguments"));
175 if (ts_node_is_null(args) && ts_node_child_count(node) > 1) {
176 args = ts_node_child(node, 1);
177 }
178 if (ts_node_is_null(args) || ts_node_child_count(args) == 0) {
179 return NULL;
180 }
181 TSNode first_arg = ts_node_child(args, 0);
182 if (ts_node_is_null(first_arg)) {
183 return NULL;
184 }
185 const char *fk = ts_node_type(first_arg);
186 char *name = NULL;
187 if (strcmp(fk, "call") == 0 && ts_node_child_count(first_arg) > 0) {
188 name = cbm_node_text(ctx->arena, ts_node_child(first_arg, 0), ctx->source);
189 } else if (strcmp(fk, "identifier") == 0) {
190 name = cbm_node_text(ctx->arena, first_arg, ctx->source);
191 }
192 if (!name || !name[0]) {
193 return NULL;
194 }
195 return cbm_fqn_compute(ctx->arena, ctx->project, ctx->rel_path, name);
196}
197
198/* Resolve a CFML tag-function's QN for scope tracking. A <cffunction name="foo">
199 * is a `cf_function_tag`; the name lives in a `cf_attribute` child (name="foo"),

Callers 1

compute_func_qnFunction · 0.85

Calls 2

cbm_node_textFunction · 0.85
cbm_fqn_computeFunction · 0.85

Tested by

no test coverage detected