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(calls): extract resolvable builtin calls so LSP builtin edges form
Martin Vogel6b1e3a0d7657
diff --git a/internal/cbm/extract_calls.c b/internal/cbm/extract_calls.cindex 302fee5b7..a7f4286ef 100644--- a/internal/cbm/extract_calls.c+++ b/internal/cbm/extract_calls.c@@ -1873,7 +1873,11 @@ void handle_calls(CBMExtractCtx *ctx, TSNode node, const CBMLangSpec *spec, Walkif (cbm_kind_in_set(node, spec->call_node_types)) {char *callee = extract_callee_name(ctx->arena, node, ctx->source, ctx->language);- if (callee && callee[0] && !cbm_is_keyword(callee, ctx->language)) {+ // Keyword-filter callees, but keep builtins we mint a node for (len, str,+ // ...) so the LSP-resolved builtin call still forms a CALLS edge.+ if (callee && callee[0] &&+ (!cbm_is_keyword(callee, ctx->language) ||+ cbm_is_resolvable_builtin(callee, ctx->language))) {CBMCall call = {0};call.callee_name = callee;call.enclosing_func_qn = state->enclosing_func_qn;diff --git a/internal/cbm/helpers.c b/internal/cbm/helpers.cindex 5821eefbc..3cea43ab3 100644--- a/internal/cbm/helpers.c+++ b/internal/cbm/helpers.c@@ -210,6 +210,29 @@ bool cbm_is_keyword(const char *name, CBMLanguage lang) {return false;}+// Builtins that appear in the keyword set above (so they are suppressed as bare+// usages) but for which we mint a real graph node and an LSP resolution, so a+// CALL to them must still be extracted. MUST stay in sync with kPyBuiltinNodes+// in internal/cbm/lsp/py_builtins.c — every entry here has a "builtins.<name>"+// node, so the resulting CALLS edge always has a target (never Module-sourced).+static const char *python_resolvable_builtins[] = {"len", "print", "str", "int",+ "list", "dict", "range", NULL};++bool cbm_is_resolvable_builtin(const char *name, CBMLanguage lang) {+ if (!name || !name[0]) {+ return false;+ }+ if (lang != CBM_LANG_PYTHON) {+ return false;+ }+ for (const char **b = python_resolvable_builtins; *b; b++) {+ if (strcmp(name, *b) == 0) {+ return true;+ }+ }+ return false;+}+// --- Export detection ---bool cbm_is_exported(const char *name, CBMLanguage lang) {diff --git a/internal/cbm/helpers.h b/internal/cbm/helpers.hindex 232db84d1..6fb136294 100644--- a/internal/cbm/helpers.h+++ b/internal/cbm/helpers.h@@ -15,6 +15,14 @@ char *cbm_node_text(CBMArena *a, TSNode node, const char *source);// Check if a string is a language keyword (should be skipped as callee/usage).bool cbm_is_keyword(const char *name, CBMLanguage lang);+// Check if a name is a builtin we mint a real graph node for, so a CALL to it+// must NOT be keyword-filtered out of call extraction (the LSP resolves it to+// the injected builtin node and forms a CALLS edge). Narrower than+// cbm_is_keyword: it only covers builtins with a target node, so un-filtering+// them cannot produce a node-less / Module-sourced edge. The Python set MUST+// stay in sync with kPyBuiltinNodes in internal/cbm/lsp/py_builtins.c.+bool cbm_is_resolvable_builtin(const char *name, CBMLanguage lang);+// Classify a string literal as URL, config, or neither.// Returns CBM_STRREF_URL (0), CBM_STRREF_CONFIG (1), or -1 for neither.int cbm_classify_string(const char *str, int len);diff --git a/tests/repro/repro_lsp_go_py.c b/tests/repro/repro_lsp_go_py.cindex d83077ca6..1d037bccf 100644--- a/tests/repro/repro_lsp_go_py.c+++ b/tests/repro/repro_lsp_go_py.c@@ -571,23 +571,14 @@ TEST(repro_lsp_py_operator_dunder) {}TEST(repro_lsp_py_builtin) {- /* PARKED for release: lsp_builtin (len(v)) needs a typeshed/builtins registry- * so builtin functions have target nodes; without it the resolution has no- * node to form a CALLS edge to (callable=0). Tracked for a future builtins- * registry. */- printf(" %sSKIP%s parked: needs builtins/typeshed registry (len has no node)\n", tf_dim(),- tf_reset());- return -1; /* skip — not counted as pass or fail */+ /* len(v) resolves to the injected builtins.len node (py_builtins.c) and+ * emits lsp_builtin with a real CALLS edge. */return assert_lsp_strategy("main.py", kPyBuiltin, "lsp_builtin");}TEST(repro_lsp_py_builtin_constructor) {- /* PARKED for release: lsp_builtin_constructor (str(v)) needs a builtins/- * typeshed registry so the builtin type str has a node to target. Tracked- * for a future builtins registry. */- printf(" %sSKIP%s parked: needs builtins/typeshed registry (str type has no node)\n", tf_dim(),- tf_reset());- return -1; /* skip — not counted as pass or fail */+ /* str(v) resolves to the injected builtins.str type node (py_builtins.c)+ * and emits lsp_builtin_constructor with a real CALLS edge. */return assert_lsp_strategy("main.py", kPyBuiltinConstructor,"lsp_builtin_constructor");}