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

Function extract_variables

internal/cbm/extract_defs.c:10307–10412  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10305}
10306
10307static void extract_variables(CBMExtractCtx *ctx, TSNode root, const CBMLangSpec *spec) {
10308 if (!spec->variable_node_types || !spec->variable_node_types[0]) {
10309 return;
10310 }
10311
10312 // Helm values.yaml: only top-level keys, not the per-leaf flood.
10313 if (ctx->language == CBM_LANG_YAML && is_helm_values_file(ctx->rel_path)) {
10314 extract_yaml_toplevel_keys(ctx, root);
10315 return;
10316 }
10317
10318 // A Kubernetes object's top-level keys (apiVersion, kind, metadata, spec,
10319 // status) are its envelope, which its Resource node carries; as Variables
10320 // they repeated in every manifest and fed name-similarity config links.
10321 if (ctx->language == CBM_LANG_YAML && yaml_is_k8s_object(ctx, root)) {
10322 return;
10323 }
10324
10325 // Config languages with nested structure: use recursive walk
10326 if (ctx->language == CBM_LANG_YAML || ctx->language == CBM_LANG_TOML ||
10327 ctx->language == CBM_LANG_INI || ctx->language == CBM_LANG_JSON) {
10328 walk_variables_iter(ctx, root, spec);
10329 return;
10330 }
10331
10332 /* HCL: a file's own assignments -- a .tfvars file, Terragrunt's `inputs`
10333 * -- sit in the top-level body, one level below the root the generic loop
10334 * scans, so none was extracted. Attributes inside blocks belong to their
10335 * block. */
10336 if (ctx->language == CBM_LANG_HCL) {
10337 TSNode body = cbm_find_child_by_kind(root, "body");
10338 uint32_t n = ts_node_is_null(body) ? 0 : ts_node_named_child_count(body);
10339 for (uint32_t i = 0; i < n; i++) {
10340 TSNode attr = ts_node_named_child(body, i);
10341 if (strcmp(ts_node_type(attr), "attribute") != 0) {
10342 continue;
10343 }
10344 TSNode id = cbm_find_child_by_kind(attr, "identifier");
10345 if (!ts_node_is_null(id)) {
10346 push_var_def(ctx, cbm_node_text(ctx->arena, id, ctx->source), attr);
10347 }
10348 }
10349 return;
10350 }
10351
10352 /* Nix: the file's top level sits behind its header lambda(s), so the root's
10353 * only child is a function_expression and the generic loop below would see
10354 * nothing. Resolve past the header to the binding container(s) that actually
10355 * constitute file scope, and mint only THEIR direct bindings.
10356 *
10357 * That bound is the point. Every Nix binding's parent is a binding_set at any
10358 * depth, so admitting them all would mint a node per `enable = true` in a
10359 * NixOS module's settings tree — the per-leaf flood the Helm values.yaml case
10360 * above exists to avoid. C++ mints file-scope declarations and never locals;
10361 * this is the same rule applied to a language whose file scope is behind a
10362 * lambda. */
10363 if (ctx->language == CBM_LANG_NIX) {
10364 extract_nix_module_vars(ctx, root, spec);

Calls 11

is_helm_values_fileFunction · 0.85
yaml_is_k8s_objectFunction · 0.85
walk_variables_iterFunction · 0.85
cbm_find_child_by_kindFunction · 0.85
push_var_defFunction · 0.85
cbm_node_textFunction · 0.85
extract_nix_module_varsFunction · 0.85
cbm_is_module_level_pFunction · 0.85
cbm_kind_in_setFunction · 0.85
extract_var_namesFunction · 0.85

Tested by

no test coverage detected