Skip to content

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.

fix(extract): def + call extraction for jsonnet/typst/meson

Martin Vogelffbf923a6f39
diff --git a/internal/cbm/extract_calls.c b/internal/cbm/extract_calls.c
index 14df416fe..6dbd67a29 100644
--- a/internal/cbm/extract_calls.c
+++ b/internal/cbm/extract_calls.c
@@ -698,10 +698,53 @@ static char *extract_elm_callee(CBMArena *a, TSNode node, const char *source, co
return cbm_node_text(a, id, source);
}
+// Jsonnet: a `functioncall` node's callee is its first `id` child (the called
+// binding name); the generic field path misses it (no `function`/`name` field).
+static char *extract_jsonnet_callee(CBMArena *a, TSNode node, const char *source, const char *nk) {
+ if (strcmp(nk, "functioncall") != 0) {
+ return NULL;
+ }
+ TSNode id = cbm_find_child_by_kind(node, "id");
+ return ts_node_is_null(id) ? NULL : cbm_node_text(a, id, source);
+}
+
+// Typst: a `call` node's callee is its `item` field (an ident), matching the
+// def-side resolution of `#let greet(name) = ...`.
+static char *extract_typst_callee(CBMArena *a, TSNode node, const char *source, const char *nk) {
+ if (strcmp(nk, "call") != 0) {
+ return NULL;
+ }
+ TSNode item = ts_node_child_by_field_name(node, TS_FIELD("item"));
+ return ts_node_is_null(item) ? NULL : cbm_node_text(a, item, source);
+}
+
+// Meson: a builtin invocation (`executable(...)`, `dependency(...)`) is a
+// `normal_command` whose `command` field is the called identifier.
+static char *extract_meson_callee(CBMArena *a, TSNode node, const char *source, const char *nk) {
+ if (strcmp(nk, "normal_command") != 0) {
+ return NULL;
+ }
+ TSNode cmd = ts_node_child_by_field_name(node, TS_FIELD("command"));
+ return ts_node_is_null(cmd) ? NULL : cbm_node_text(a, cmd, source);
+}
+
static char *extract_callee_lang_specific(CBMArena *a, TSNode node, const char *source,
CBMLanguage lang) {
const char *nk = ts_node_type(node);
+ if (lang == CBM_LANG_JSONNET) {
+ char *c = extract_jsonnet_callee(a, node, source, nk);
+ return c ? c : extract_scripting_callee(a, node, source, lang, nk);
+ }
+ if (lang == CBM_LANG_TYPST) {
+ char *c = extract_typst_callee(a, node, source, nk);
+ return c ? c : extract_scripting_callee(a, node, source, lang, nk);
+ }
+ if (lang == CBM_LANG_MESON) {
+ char *c = extract_meson_callee(a, node, source, nk);
+ return c ? c : extract_scripting_callee(a, node, source, lang, nk);
+ }
+
if (lang == CBM_LANG_SCSS) {
char *c = extract_scss_callee(a, node, source, nk);
return c ? c : extract_scripting_callee(a, node, source, lang, nk);
diff --git a/internal/cbm/extract_defs.c b/internal/cbm/extract_defs.c
index 0ac43e2ab..fe959ec20 100644
--- a/internal/cbm/extract_defs.c
+++ b/internal/cbm/extract_defs.c
@@ -849,6 +849,34 @@ TSNode cbm_resolve_func_name(TSNode node, CBMLanguage lang) {
}
}
+ /* Jsonnet: a function binding is a `bind` node carrying the name on the
+ * `function` field (an `id`), plus a `params` field. Plain value binds
+ * (`local x = 1`) have no `params` field -> resolve null -> skipped, so
+ * only function binds become Function defs. */
+ if (lang == CBM_LANG_JSONNET && strcmp(kind, "bind") == 0) {
+ TSNode params = ts_node_child_by_field_name(node, TS_FIELD("params"));
+ if (!ts_node_is_null(params)) {
+ TSNode nm = ts_node_child_by_field_name(node, TS_FIELD("function"));
+ if (!ts_node_is_null(nm)) {
+ return nm;
+ }
+ }
+ }
+
+ /* Typst: `#let greet(name) = ...` parses to a `let` whose `pattern` field
+ * is a `call` node (the function signature); the name is that call's
+ * `item` field (an ident). A plain `#let x = 1` has a non-call pattern ->
+ * resolve null -> skipped, keeping value bindings out of func_types. */
+ if (lang == CBM_LANG_TYPST && strcmp(kind, "let") == 0) {
+ TSNode pat = ts_node_child_by_field_name(node, TS_FIELD("pattern"));
+ if (!ts_node_is_null(pat) && strcmp(ts_node_type(pat), "call") == 0) {
+ TSNode item = ts_node_child_by_field_name(pat, TS_FIELD("item"));
+ if (!ts_node_is_null(item)) {
+ return item;
+ }
+ }
+ }
+
/* SQL: create_function has no `name` field; the function name is nested as
* object_reference > `name` field (an identifier). */
if (lang == CBM_LANG_SQL && strcmp(kind, "create_function") == 0) {
diff --git a/internal/cbm/lang_specs.c b/internal/cbm/lang_specs.c
index d6351878b..ba897992f 100644
--- a/internal/cbm/lang_specs.c
+++ b/internal/cbm/lang_specs.c
@@ -886,7 +886,7 @@ static const char *svelte_branch_types[] = {"if_statement", "each_statement", "a
// ==================== MESON ====================
static const char *meson_func_types[] = {"function_expression", NULL};
static const char *meson_module_types[] = {"source_file", NULL};
-static const char *meson_call_types[] = {"function_expression", "command", NULL};
+static const char *meson_call_types[] = {"normal_command", NULL};
static const char *meson_branch_types[] = {"if_statement", "foreach_statement", NULL};
static const char *meson_var_types[] = {"assignment_statement", NULL};
@@ -998,7 +998,7 @@ static const char *solidity_assign_types[] = {"assignment_expression",
"augmented_assignment_expression", NULL};
static const char *solidity_throw_types[] = {"revert_statement", "emit_statement", NULL};
static const char *solidity_module_types[] = {"source_file", NULL};
-static const char *typst_func_types[] = {"lambda", NULL};
+static const char *typst_func_types[] = {"lambda", "let", NULL};
static const char *typst_call_types[] = {"call", NULL};
static const char *typst_import_types[] = {"import", "include", NULL};
static const char *typst_branch_types[] = {"if", "for", "while", NULL};
@@ -1292,7 +1292,7 @@ static const char *wgsl_assign_types[] = {"assignment_statement", NULL};
static const char *wgsl_module_types[] = {"translation_unit", NULL};
static const char *kdl_module_types[] = {"document", NULL};
static const char *json5_module_types[] = {"document", NULL};
-static const char *jsonnet_func_types[] = {"anonymous_function", NULL};
+static const char *jsonnet_func_types[] = {"anonymous_function", "bind", NULL};
static const char *jsonnet_call_types[] = {"functioncall", NULL};
static const char *jsonnet_import_types[] = {"import", "importstr", NULL};
static const char *jsonnet_branch_types[] = {"conditional", NULL};