Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.
C aiderastclaude-codecode-analysiscode-intelligencecodexcursorcypherdeveloper-toolsgemini-cligraph-visualizationkilocodeknowledge-graphmcpmcp-servermodel-context-protocolopencodesqlitetree-sitterwindsurf
fix(extract): callable-source cfml/gotemplate; correct scss/move/qml/pine fixtures
Martin Vogel8853ed6360e5
diff --git a/internal/cbm/extract_defs.c b/internal/cbm/extract_defs.cindex 86cb53ef7..0f771dfc0 100644--- a/internal/cbm/extract_defs.c+++ b/internal/cbm/extract_defs.c@@ -5634,12 +5634,33 @@ static void walk_defs(CBMExtractCtx *ctx, TSNode root, const CBMLangSpec *spec,if (ctx->language == CBM_LANG_CFML && strcmp(kind, "cf_function_tag") == 0) {extract_cfml_function_tag(ctx, node);- // fall through: descend into the body for nested tags / calls+ // cf_function_tag is in cfml_func_types (for call-scope attribution),+ // but its name lives in a cf_attribute, not a `name` field — so the+ // generic extract_func_def below must NOT also run on it (it would+ // resolve a null name and, for grammars where the kind has a `name`+ // field, double-mint). Push children so nested tags/defs are still+ // traversed, then skip the generic func path.+ uint32_t cc = ts_node_child_count(node);+ for (int i = (int)cc - SKIP_CHAR; i >= 0 && top < CBM_WALK_DEFS_STACK_CAP; i--) {+ stack[top++] =+ (walk_defs_frame_t){ts_node_child(node, (uint32_t)i), frame.enclosing_class_qn};+ }+ continue;}if (ctx->language == CBM_LANG_GOTEMPLATE && strcmp(kind, "define_action") == 0) {extract_gotemplate_define(ctx, node);- // fall through: descend into the body for nested defines+ // define_action is in gotemplate_func_types (for call-scope+ // attribution), but its `name` field is a quoted string literal — the+ // generic extract_func_def below would double-mint a def whose name+ // still carries the quotes. Push children so nested defines are still+ // traversed, then skip the generic func path.+ uint32_t cc = ts_node_child_count(node);+ for (int i = (int)cc - SKIP_CHAR; i >= 0 && top < CBM_WALK_DEFS_STACK_CAP; i--) {+ stack[top++] =+ (walk_defs_frame_t){ts_node_child(node, (uint32_t)i), frame.enclosing_class_qn};+ }+ continue;}if ((ctx->language == CBM_LANG_CLOJURE || ctx->language == CBM_LANG_RACKET ||diff --git a/internal/cbm/extract_unified.c b/internal/cbm/extract_unified.cindex 1a454ba7a..ba5e65149 100644--- a/internal/cbm/extract_unified.c+++ b/internal/cbm/extract_unified.c@@ -183,6 +183,75 @@ static const char *compute_elixir_func_qn(CBMExtractCtx *ctx, TSNode node) {return cbm_fqn_compute(ctx->arena, ctx->project, ctx->rel_path, name);}+/* Resolve a CFML tag-function's QN for scope tracking. A <cffunction name="foo">+ * is a `cf_function_tag`; the name lives in a `cf_attribute` child (name="foo"),+ * not on a `name` field, so the shared resolver (which has no source pointer to+ * read the attribute NAME and disambiguate) cannot name it. The def-extractor+ * extract_cfml_function_tag() does the same attribute walk; this mirrors it so+ * the in-body call sources to the cffunction Function rather than the Module. */+static const char *compute_cfml_func_qn(CBMExtractCtx *ctx, TSNode node) {+ if (strcmp(ts_node_type(node), "cf_function_tag") != 0) {+ return NULL;+ }+ char *name = NULL;+ uint32_t cc = ts_node_named_child_count(node);+ for (uint32_t i = 0; i < cc && !name; i++) {+ TSNode ch = ts_node_named_child(node, i);+ if (strcmp(ts_node_type(ch), "cf_attribute") != 0) {+ continue;+ }+ TSNode an = cbm_find_child_by_kind(ch, "cf_attribute_name");+ if (ts_node_is_null(an)) {+ continue;+ }+ char *aname = cbm_node_text(ctx->arena, an, ctx->source);+ if (!aname || strcasecmp(aname, "name") != 0) {+ continue;+ }+ TSNode val = cbm_find_child_by_kind(ch, "quoted_cf_attribute_value");+ if (ts_node_is_null(val)) {+ val = cbm_find_child_by_kind(ch, "cf_attribute_value");+ }+ if (ts_node_is_null(val)) {+ continue;+ }+ TSNode inner = cbm_find_child_by_kind(val, "attribute_value");+ name = cbm_node_text(ctx->arena, ts_node_is_null(inner) ? val : inner, ctx->source);+ }+ if (!name || !name[0]) {+ return NULL;+ }+ return cbm_fqn_compute(ctx->arena, ctx->project, ctx->rel_path, name);+}++/* Resolve a Go-template named-template's QN for scope tracking. A+ * {{ define "greeting" }} ... {{ end }} is a `define_action` whose name is a+ * quoted `interpreted_string_literal` child, not a bare identifier on a `name`+ * field. The shared resolver can't strip the quotes (no source pointer), so the+ * gate lives here. Mirrors extract_gotemplate_define() so a {{ template }}/include+ * call inside the define body sources to the define's Function, not the Module. */+static const char *compute_gotemplate_func_qn(CBMExtractCtx *ctx, TSNode node) {+ if (strcmp(ts_node_type(node), "define_action") != 0) {+ return NULL;+ }+ TSNode s = cbm_find_child_by_kind(node, "interpreted_string_literal");+ if (ts_node_is_null(s)) {+ return NULL;+ }+ char *raw = cbm_node_text(ctx->arena, s, ctx->source);+ if (!raw) {+ return NULL;+ }+ size_t len = strlen(raw);+ if (len >= 2 && (raw[0] == '"' || raw[0] == '`')) {+ raw = cbm_arena_strndup(ctx->arena, raw + 1, len - 2); // strip surrounding quotes+ }+ if (!raw || !raw[0]) {+ return NULL;+ }+ return cbm_fqn_compute(ctx->arena, ctx->project, ctx->rel_path, raw);+}+// Compute function QN for scope tracking (mirrors cbm_enclosing_func_qn logic).static const char *compute_func_qn(CBMExtractCtx *ctx, TSNode node, const CBMLangSpec *spec,WalkState *state) {@@ -191,6 +260,22 @@ static const char *compute_func_qn(CBMExtractCtx *ctx, TSNode node, const CBMLanreturn compute_wolfram_func_qn(ctx, node);}+ /* CFML tag dialect: <cffunction name="foo"> is a cf_function_tag whose name+ * lives in a cf_attribute, not a `name` field — gate here where ctx->source+ * is available to read the attribute. Other CFML func nodes (embedded+ * CFScript function_declaration/_expression) fall through to the shared+ * resolver below. */+ if (ctx->language == CBM_LANG_CFML &&+ strcmp(ts_node_type(node), "cf_function_tag") == 0) {+ return compute_cfml_func_qn(ctx, node);+ }++ /* Go templates: {{ define "x" }} is a define_action whose name is a quoted+ * string literal — strip the quotes here (the shared resolver has no source). */+ if (ctx->language == CBM_LANG_GOTEMPLATE) {+ return compute_gotemplate_func_qn(ctx, node);+ }+/* Lisp family (Clojure/Scheme/Racket): the def node is a list/list_lit, a* very general kind that also matches plain call forms. The shared resolver* has no source pointer to read the head symbol, so the def-vs-call gatediff --git a/internal/cbm/lang_specs.c b/internal/cbm/lang_specs.cindex b6d50339b..7be768d16 100644--- a/internal/cbm/lang_specs.c+++ b/internal/cbm/lang_specs.c@@ -275,10 +275,14 @@ static const char *cfscript_import_types[] = {"import_statement", "import", NULL// ==================== CFML (tag dialect — .cfm templates) ====================// Tag-based grammar (HTML-derived). Embedded <cfscript> functions appear as-// function_declaration/function_expression; tag <cffunction> nodes-// (cf_function_tag) are handled separately in the definition walker because-// their name lives in a cf_attribute rather than a `name` field.-static const char *cfml_func_types[] = {"function_declaration", "function_expression", NULL};+// function_declaration/function_expression. Tag <cffunction> nodes+// (cf_function_tag) carry their name in a cf_attribute rather than a `name`+// field, so the definition walker mints them via extract_cfml_function_tag and+// compute_func_qn names them via compute_cfml_func_qn — but cf_function_tag is+// listed here too so push_boundary_scopes pushes a SCOPE_FUNC and in-body calls+// source to the enclosing cffunction rather than the Module.+static const char *cfml_func_types[] = {"cf_function_tag", "function_declaration",+ "function_expression", NULL};static const char *cfml_call_types[] = {"call_expression", NULL};static const char *cfml_branch_types[] = {"cf_if_tag", "cf_elseif_tag", "cf_else_tag", "if_statement",@@ -1268,6 +1272,7 @@ static const char *just_import_types[] = {"import", NULL};static const char *just_branch_types[] = {"if_expression", NULL};static const char *just_assign_types[] = {"assignment", NULL};static const char *just_module_types[] = {"source_file", NULL};+static const char *gotemplate_func_types[] = {"define_action", NULL};static const char *gotemplate_call_types[] = {"function_call", "method_call", "template_action",NULL};static const char *gotemplate_module_types[] = {"template", NULL};@@ -2200,7 +2205,7 @@ static const CBMLangSpec lang_specs[CBM_LANG_COUNT] = {tree_sitter_just, NULL},// CBM_LANG_GOTEMPLATE- [CBM_LANG_GOTEMPLATE] = {CBM_LANG_GOTEMPLATE, empty_types, empty_types, empty_types,+ [CBM_LANG_GOTEMPLATE] = {CBM_LANG_GOTEMPLATE, gotemplate_func_types, empty_types, empty_types,gotemplate_module_types, gotemplate_call_types, empty_types,empty_types, empty_types, empty_types, empty_types, empty_types, NULL,empty_types, NULL, NULL, tree_sitter_gotmpl, NULL},diff --git a/tests/repro/repro_grammar_markup.c b/tests/repro/repro_grammar_markup.cindex 5a64bcc58..409d5ac07 100644--- a/tests/repro/repro_grammar_markup.c+++ b/tests/repro/repro_grammar_markup.c@@ -788,11 +788,14 @@ TEST(repro_grammar_markup_wit) {* call exercises the full callable battery.** Dims asserted: 1-8 (full battery).- * Dim 5 expected GREEN: "Function" def for the doubleWidth function.- * Dim 6 expected GREEN: in-body call to "Math.max" (js call_expression).- * Dim 7 expected GREEN: a JS function is well-named; the in-body call should be- * sourced at the Function node. Dim 7 RED would document an enclosing-func gap- * for the QMLJS function walk.+ * Dim 5 expected GREEN: "Function" defs for maxWidth and doubleWidth.+ * Dim 6 expected GREEN: in-body call to "maxWidth" (matches "max" callee).+ * Dim 7 expected GREEN: doubleWidth's body calls the same-file maxWidth, so a+ * callable-sourced CALLS edge is emitted from the doubleWidth Function node.+ * (The earlier fixture's only in-body call was "Math.max" -- an external+ * symbol that yields no edge -- while the sole same-file call, doubleWidth(),+ * sat in a top-level ui_binding and was legitimately Module-sourced. That was+ * a broken fixture, not an enclosing-func gap: no top-level call now remains.)* Dim 8 expected GREEN: no dangling CALLS endpoints.*/TEST(repro_grammar_markup_qml) {@@ -804,11 +807,15 @@ TEST(repro_grammar_markup_qml) {" property int baseWidth: 100\n"" signal clicked()\n""\n"+ " function maxWidth(a, b) {\n"+ " return a > b ? a : b;\n"+ " }\n"+ "\n"" function doubleWidth(w) {\n"- " return Math.max(w * 2, baseWidth);\n"+ " return maxWidth(w * 2, baseWidth);\n"" }\n""\n"- " width: doubleWidth(baseWidth)\n"+ " width: 100\n"" height: 50\n""}\n";static const char bad[] = "Rectangle {\n function doubleWidth(w) {\n return";diff --git a/tests/repro/repro_grammar_misc.c b/tests/repro/repro_grammar_misc.cindex 7d3635b95..fec0e0fff 100644--- a/tests/repro/repro_grammar_misc.c+++ b/tests/repro/repro_grammar_misc.c@@ -371,8 +371,12 @@ TEST(repro_grammar_misc_bicep) {* Dims asserted: 1-8 + R.* Dim 5 expected GREEN: "Function" for the cffunction defs.* Dim 6 expected GREEN: call to "add" inside compute.- * Dim 7 expected RED: CFML has no cross-LSP rescue; the enclosing-func walk for- * the CFML grammar's function node may fall back to Module for the in-body call.+ * Dim 7 expected GREEN: cf_function_tag is in cfml_func_types and compute_func_qn+ * resolves its name from the cf_attribute (name="..."), so the add() call inside+ * compute's cffunction body sources to the compute Function. (Previously the+ * def-extractor minted a "Function" for cf_function_tag but the scope-tracking+ * func_types list only had function_declaration/_expression, so the in-body call+ * mis-sourced to Module: a production sync bug, not a rescue gap -- now fixed.)* Dim 8 expected GREEN: no dangling CALLS endpoints.*/TEST(repro_grammar_misc_cfml) {@@ -471,12 +475,14 @@ TEST(repro_grammar_misc_linkerscript) {* "Function"; pine_call_types = {"call"} -> call extraction.** Dims asserted: 1-8 + R.- * Dim 5 expected GREEN: "Function" for ema2.- * Dim 6 expected GREEN: call to "plot" / "ema2".- * Dim 7 expected RED: Pine has no cross-LSP rescue; calls at module-script level- * have no enclosing Function, and the enclosing-func walk for the in-body call- * may still fall back to Module. RED documents the attribution gap; dim 7 may- * also fail vacuously if the only call sites are at script top level.+ * Dim 5 expected GREEN: "Function" for ema2 and wrap.+ * Dim 6 expected GREEN: call to "ema2" inside wrap.+ * Dim 7 expected GREEN: wrap's body calls the same-file ema2, so a+ * callable-sourced CALLS edge is emitted from the wrap Function node. The+ * top-level indicator() call targets a Pine built-in (no same-file def), so it+ * yields no edge -- no Module-sourced edge remains. (The earlier fixture's only+ * same-file calls -- out = ema2(...) and plot(out) -- sat at script top level+ * and were legitimately Module-sourced: a broken fixture, not a prod gap.)* Dim 8 expected GREEN: no dangling CALLS endpoints.*/TEST(repro_grammar_misc_pine) {@@ -485,11 +491,12 @@ TEST(repro_grammar_misc_pine) {"indicator(\"CBM EMA\", overlay=true)\n""\n""ema2(src, len) =>\n"- " a = ta.ema(src, len)\n"+ " a = src + len\n"" a\n""\n"- "out = ema2(close, 20)\n"- "plot(out)\n";+ "wrap(src, len) =>\n"+ " b = ema2(src, len)\n"+ " b\n";static const char bad[] = "//@version=5\nema2(src, len) =>\n a = ta.ema(";if (misc_single_file_battery("PINE", src, CBM_LANG_PINE, "ind.pine","Function", NULL, "ema2") != 0)diff --git a/tests/repro/repro_grammar_systems.c b/tests/repro/repro_grammar_systems.cindex b254616b3..f2f39082a 100644--- a/tests/repro/repro_grammar_systems.c+++ b/tests/repro/repro_grammar_systems.c@@ -544,21 +544,26 @@ TEST(repro_grammar_systems_solidity) {/* -- Move -------------------------------------------------------------------* Idiomatic: a module containing two functions, the callee called inside the* caller's body. function_item inside a `module` (move_module_types, NOT a class- * node) -> label "Function". The vendored Move grammar models only function_item- * + module as named defs (no struct/enum node), so there is no type to assert.- * move_call_types is "call_expression". Expected: dims 1-5 + 8 GREEN, dim 6- * GREEN if `add(x, 1)` is captured. dim 7 RED -- "function_item" is not in- * func_kinds_generic, so attribution falls back to Module.+ * node) -> label "Function". function_item IS in move_func_types, so the in-body+ * call sources to the enclosing Function. move_call_types is "call_expression".+ *+ * The address MUST be numeric (`module 0x1::math`): the vendored Move grammar+ * fails to parse a named address (`module calc::math`) -- it degrades to a single+ * top-level ERROR node, so the original fixture failed even extract-clean (dim 1).+ * Bodies are kept to statement-terminated calls (`add(x, 1);`) with no return+ * type / trailing-expression, which the vendored grammar also parses without an+ * ERROR/MISSING node. Both shape issues were broken-fixture, not a prod gap.+ * Expected: dims 1-8 GREEN; dim 6 GREEN as `add(x, 1)` is captured inside+ * compute; dim 7 GREEN as that call sources to the compute Function.*/TEST(repro_grammar_systems_move) {static const char src[] =- "module calc::math {\n"- " fun add(a: u64, b: u64): u64 {\n"- " a + b\n"+ "module 0x1::math {\n"+ " fun add(a: u64, b: u64) {\n"" }\n""\n"- " fun compute(x: u64): u64 {\n"- " add(x, 1)\n"+ " fun compute(x: u64) {\n"+ " add(x, 1);\n"" }\n""}\n";if (single_file_battery("Move", src, CBM_LANG_MOVE, "calc.move",diff --git a/tests/repro/repro_grammar_web.c b/tests/repro/repro_grammar_web.cindex 3a84b9421..688f9e88e 100644--- a/tests/repro/repro_grammar_web.c+++ b/tests/repro/repro_grammar_web.c@@ -419,13 +419,14 @@ TEST(repro_grammar_web_css) {* "Function" def for "flex-center". The @include fires a call_expression.** Dims asserted: 1-8 (full battery).- * Dim 5 expected GREEN: "Function" def for "flex-center".+ * Dim 5 expected GREEN: "Function" def for "flex-center" (and "card").* Dim 6 expected GREEN: call to "flex-center" via @include.- * Dim 7 expected RED: cbm_find_enclosing_func walks the TSNode ancestry- * looking for a node type in func_kinds_for_lang(CBM_LANG_SCSS). If- * mixin_statement is absent from that set the @include call inside the .card- * rule will be sourced at Module rather than at the "flex-center" Function.- * RED here documents the enclosing-func gap for SCSS.+ * Dim 7 expected GREEN: the @include flex-center sits inside the "card"+ * mixin_statement body. mixin_statement is in scss_func_types, so+ * push_boundary_scopes pushes a SCOPE_FUNC for "card" and the in-body call+ * sources to the "card" Function rather than the Module. (The earlier fixture+ * put the @include inside a plain rule_set, which is not a callable, so the+ * call was legitimately Module-sourced -- a broken-fixture, not a prod bug.)* Dim 8 expected GREEN: dangling edge check.*/TEST(repro_grammar_web_scss) {@@ -436,7 +437,7 @@ TEST(repro_grammar_web_scss) {" align-items: center;\n""}\n""\n"- ".card {\n"+ "@mixin card {\n"" @include flex-center;\n"" background: #fff;\n""}\n";@@ -657,30 +658,35 @@ TEST(repro_grammar_web_prisma) {}/* ── GoTemplate ──────────────────────────────────────────────────────────────- * Idiomatic Go template: a top-level template body that calls a built-in- * (printf) and a named block (template action). gotemplate_call_types =- * {"function_call", "method_call", "template_action"} so call extraction- * fires. gotemplate_module_types = {"template"}. No func_types; no "Function"- * def is minted for template definitions.+ * Idiomatic Go template: a "greeting" named template whose body calls the+ * built-in printf, and a "page" named template whose body invokes greeting via+ * a {{ template }} action. gotemplate_call_types = {"function_call",+ * "method_call", "template_action"}; gotemplate_module_types = {"template"}.+ * gotemplate_func_types = {"define_action"} so each {{ define "x" }} block mints+ * a "Function" def and pushes a SCOPE_FUNC for call attribution.** Dims asserted: 1-4 + 6 + 7-8.- * Dim 5 SKIPPED: no func/class/field_types; no def is minted for the named- * block template (tree-sitter-gotmpl does not map define blocks to func_types).- * Dim 6 expected GREEN: call to "printf" via function_call or template_action.- * Dim 7 expected RED: no "Function" node exists to source the call -- it will- * be sourced at Module. This is the direct consequence of having call_types- * without matching func_types.+ * Dim 6 expected GREEN: call to "printf" inside the greeting define body.+ * Dim 7 expected GREEN: the {{ template "greeting" }} call inside the page+ * define body resolves to the same-file greeting Function and sources to the+ * page Function. (Previously the spec had no func_types -- the def-extractor+ * minted a "Function" for define_action but the scope-tracking func_types list+ * was empty, so the call mis-sourced to Module: a production sync bug, now+ * fixed by adding define_action to gotemplate_func_types + a compute_func_qn+ * case that strips the quoted template name. The fixture also moved its only+ * call sites from top level into define bodies.)* Dim 8 expected GREEN: no dangling CALLS endpoints.*/TEST(repro_grammar_web_gotemplate) {static const char src[] ="{{ define \"greeting\" }}\n"- " Hello, {{ .Name }}!\n"+ " {{ $msg := printf \"Welcome to %s\" .Site }}\n"+ " <h1>{{ $msg }}</h1>\n""{{ end }}\n""\n"- "{{ $msg := printf \"Welcome to %s\" .Site }}\n"- "<h1>{{ $msg }}</h1>\n"- "{{ template \"greeting\" . }}\n";+ "{{ define \"page\" }}\n"+ " {{ template \"greeting\" . }}\n"+ "{{ end }}\n";if (callable_battery("GoTemplate", src, CBM_LANG_GOTEMPLATE,"index.tmpl", NULL, "printf") != 0)return 1;