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 extraction/resolution across languages: routing, Go methods, cross-LSP, inheritance, constructors, node kinds
Martin Vogel2d772b01bf9e
diff --git a/internal/cbm/extract_calls.c b/internal/cbm/extract_calls.cindex b3c2baf0b..ddaa50570 100644--- a/internal/cbm/extract_calls.c+++ b/internal/cbm/extract_calls.c@@ -147,6 +147,79 @@ static char *resolve_chained_selector(CBMArena *a, TSNode sel, const char *sourcreturn method;}+// Strip a trailing generic argument list ("<...>" / "[...]") from a type name,+// returning the bare type identifier. Mutates an arena-owned copy in place.+static char *strip_generic_args(char *t) {+ if (!t) {+ return NULL;+ }+ char *angle = strchr(t, '<');+ if (angle) {+ *angle = '\0';+ }+ char *brack = strchr(t, '[');+ if (brack) {+ *brack = '\0';+ }+ return t;+}++// Pull the constructed type name out of a constructor/instantiation node:+// new_expression (TS/JS) -> `constructor`/`type` field or first type child+// object_creation_expression (Java/C#/PHP) -> `type` field or first type child+// instance_expression (Scala) -> nested type in the wrapped type/call+// Returns the bare type name (generic args stripped) or NULL if not a+// constructor node / no type found. Constructor calls resolve to the class's+// constructor (or the class node) downstream, producing a CALLS edge.+static char *extract_constructor_callee(CBMArena *a, TSNode node, const char *source,+ const char *nk) {+ if (strcmp(nk, "new_expression") != 0 && strcmp(nk, "object_creation_expression") != 0 &&+ strcmp(nk, "instance_expression") != 0) {+ return NULL;+ }++ // Preferred: explicit fields used by the various grammars.+ static const char *type_fields[] = {"constructor", "type", "name", NULL};+ for (const char **f = type_fields; *f; f++) {+ TSNode tn = ts_node_child_by_field_name(node, *f, (uint32_t)strlen(*f));+ if (!ts_node_is_null(tn)) {+ const char *tk = ts_node_type(tn);+ // For a generic_type wrapper, descend to the bare name child.+ if (strcmp(tk, "generic_type") == 0 && ts_node_named_child_count(tn) > 0) {+ tn = ts_node_named_child(tn, 0);+ }+ char *t = strip_generic_args(cbm_node_text(a, tn, source));+ if (t && t[0]) {+ return t;+ }+ }+ }++ // Fallback: first type-like named child (covers grammars that don't expose+ // a field, e.g. Scala's instance_expression wraps the type directly).+ uint32_t nc = ts_node_named_child_count(node);+ for (uint32_t i = 0; i < nc; i++) {+ TSNode child = ts_node_named_child(node, i);+ const char *ck = ts_node_type(child);+ if (strcmp(ck, "type_identifier") == 0 || strcmp(ck, "identifier") == 0 ||+ strcmp(ck, "qualified_name") == 0 || strcmp(ck, "scoped_type_identifier") == 0 ||+ strcmp(ck, "qualified_identifier") == 0 || strcmp(ck, "name") == 0 ||+ strcmp(ck, "type") == 0 || strcmp(ck, "generic_type") == 0 ||+ strcmp(ck, "simple_type") == 0 || strcmp(ck, "stable_type_identifier") == 0 ||+ strcmp(ck, "user_type") == 0) {+ // Descend through a generic_type wrapper to the bare name.+ if (strcmp(ck, "generic_type") == 0 && ts_node_named_child_count(child) > 0) {+ child = ts_node_named_child(child, 0);+ }+ char *t = strip_generic_args(cbm_node_text(a, child, source));+ if (t && t[0]) {+ return t;+ }+ }+ }+ return NULL;+}+// Try common field-based callee resolution (function, name, method fields).static char *extract_callee_from_fields(CBMArena *a, TSNode node, const char *source) {// Try "function" field@@ -539,6 +612,32 @@ static char *extract_callee_name(CBMArena *a, TSNode node, const char *source, C}}+ // Constructor / instantiation nodes (new T(), object_creation, instance_expression):+ // resolve to the constructed type so a CALLS edge links to the class/constructor.+ char *ctor = extract_constructor_callee(a, node, source, ts_node_type(node));+ if (ctor) {+ return ctor;+ }++ // Ruby: `Widget.new(...)` is a method call on a constant receiver whose+ // method is `new`. The constructor body lives in `initialize`, so a callee+ // of "new" never resolves. Redirect to the receiver type name so the call+ // links to the class/constructor like every other language's `new T()`.+ if (lang == CBM_LANG_RUBY) {+ TSNode m = ts_node_child_by_field_name(node, TS_FIELD("method"));+ TSNode recv = ts_node_child_by_field_name(node, TS_FIELD("receiver"));+ if (!ts_node_is_null(m) && !ts_node_is_null(recv) &&+ strcmp(ts_node_type(recv), "constant") == 0) {+ char *mt = cbm_node_text(a, m, source);+ if (mt && strcmp(mt, "new") == 0) {+ char *rt = cbm_node_text(a, recv, source);+ if (rt && rt[0]) {+ return rt;+ }+ }+ }+ }+// Try common field-based resolution firstchar *name = extract_callee_from_fields(a, node, source);if (name) {diff --git a/internal/cbm/extract_defs.c b/internal/cbm/extract_defs.cindex 06c95a1ea..9f03cf717 100644--- a/internal/cbm/extract_defs.c+++ b/internal/cbm/extract_defs.c@@ -1279,7 +1279,17 @@ static char *extract_cpp_base_text(CBMArena *a, TSNode bc, const char *source) {}if (strcmp(bk, "type_identifier") == 0 || strcmp(bk, "qualified_identifier") == 0 ||strcmp(bk, "scoped_identifier") == 0) {- return cbm_node_text(a, bc, source);+ /* A qualified base may embed a template_type in its `name` field+ * (e.g. `std::vector<T>`), so the raw text carries `<...>` args.+ * Strip the generic argument list to keep the bare qualified name. */+ char *t = cbm_node_text(a, bc, source);+ if (t) {+ char *angle = strchr(t, '<');+ if (angle) {+ *angle = '\0';+ }+ }+ return t;}if (strcmp(bk, "template_type") == 0) {TSNode tname = ts_node_child_by_field_name(bc, TS_FIELD("name"));@@ -1413,6 +1423,176 @@ static const char **extract_csharp_base_list(CBMArena *a, TSNode node, const chareturn NULL;}+// Append a base name (generic args stripped) to out[] if non-empty.+static void push_base_text(CBMArena *a, TSNode n, const char *source, const char **out,+ int out_cap, int *count) {+ if (*count >= out_cap) {+ return;+ }+ char *t = cbm_node_text(a, n, source);+ if (!t) {+ return;+ }+ char *angle = strchr(t, '<');+ if (angle) {+ *angle = '\0';+ }+ /* PHP qualified base may be backslash-prefixed (e.g. `\RuntimeException`);+ * keep the bare class name so it matches the unqualified declaration. */+ char *last_bs = strrchr(t, '\\');+ if (last_bs) {+ t = last_bs + 1;+ }+ if (t[0]) {+ out[(*count)++] = t;+ }+}++/* TypeScript/TSX: bases live in a `class_heritage` (class) or directly in an+ * `extends_type_clause` (interface). The extractor previously captured the+ * literal "extends"/"implements" keyword text instead of the type names. */+static int collect_ts_bases(CBMArena *a, TSNode clause, const char *source, const char **out,+ int out_cap, int *count) {+ const char *kk = ts_node_type(clause);+ if (strcmp(kk, "extends_clause") == 0) {+ /* `extends_clause` carries the superclass in its `value` field. */+ TSNode v = ts_node_child_by_field_name(clause, TS_FIELD("value"));+ if (!ts_node_is_null(v)) {+ push_base_text(a, v, source, out, out_cap, count);+ }+ return *count;+ }+ if (strcmp(kk, "implements_clause") == 0 || strcmp(kk, "extends_type_clause") == 0) {+ /* Named children are the implemented/extended types (possibly generic). */+ uint32_t nc = ts_node_named_child_count(clause);+ for (uint32_t i = 0; i < nc && *count < out_cap; i++) {+ TSNode c = ts_node_named_child(clause, i);+ const char *ck = ts_node_type(c);+ if (strcmp(ck, "type_arguments") == 0) {+ continue;+ }+ if (strcmp(ck, "generic_type") == 0) {+ TSNode nm = ts_node_child_by_field_name(c, TS_FIELD("name"));+ if (!ts_node_is_null(nm)) {+ push_base_text(a, nm, source, out, out_cap, count);+ continue;+ }+ }+ push_base_text(a, c, source, out, out_cap, count);+ }+ }+ return *count;+}++/* TypeScript: walk the class_heritage container (which holds extends_clause ++ * implements_clause), or handle a bare interface extends_type_clause. */+static const char **extract_ts_bases(CBMArena *a, TSNode node, const char *source) {+ const char *bases[MAX_BASES];+ int count = 0;+ uint32_t nc = ts_node_child_count(node);+ for (uint32_t i = 0; i < nc; i++) {+ TSNode child = ts_node_child(node, i);+ const char *ck = ts_node_type(child);+ if (strcmp(ck, "class_heritage") == 0) {+ uint32_t hc = ts_node_child_count(child);+ for (uint32_t j = 0; j < hc; j++) {+ collect_ts_bases(a, ts_node_child(child, j), source, bases, MAX_BASES_MINUS_1,+ &count);+ }+ } else if (strcmp(ck, "extends_type_clause") == 0) {+ collect_ts_bases(a, child, source, bases, MAX_BASES_MINUS_1, &count);+ }+ }+ if (count == 0) {+ return NULL;+ }+ const char **result =+ (const char **)cbm_arena_alloc(a, (size_t)(count + NULL_TERM) * sizeof(const char *));+ if (!result) {+ return NULL;+ }+ for (int i = 0; i < count; i++) {+ result[i] = bases[i];+ }+ result[count] = NULL;+ return result;+}++/* PHP: bases live in `base_clause` (extends) and `class_interface_clause`+ * (implements) child nodes; named children are `name`/`qualified_name`. */+static const char **extract_php_bases(CBMArena *a, TSNode node, const char *source) {+ const char *bases[MAX_BASES];+ int count = 0;+ uint32_t nc = ts_node_child_count(node);+ for (uint32_t i = 0; i < nc; i++) {+ TSNode child = ts_node_child(node, i);+ const char *ck = ts_node_type(child);+ if (strcmp(ck, "base_clause") != 0 && strcmp(ck, "class_interface_clause") != 0) {+ continue;+ }+ uint32_t cc = ts_node_named_child_count(child);+ for (uint32_t j = 0; j < cc && count < MAX_BASES_MINUS_1; j++) {+ push_base_text(a, ts_node_named_child(child, j), source, bases, MAX_BASES_MINUS_1,+ &count);+ }+ }+ if (count == 0) {+ return NULL;+ }+ const char **result =+ (const char **)cbm_arena_alloc(a, (size_t)(count + NULL_TERM) * sizeof(const char *));+ if (!result) {+ return NULL;+ }+ for (int i = 0; i < count; i++) {+ result[i] = bases[i];+ }+ result[count] = NULL;+ return result;+}++/* Kotlin: supertypes live in `delegation_specifier` children. Each holds+ * either a bare `user_type` (interface) or a `constructor_invocation` whose+ * `user_type` is the superclass. Descend to the `type_identifier`. */+static const char **extract_kotlin_bases(CBMArena *a, TSNode node, const char *source) {+ const char *bases[MAX_BASES];+ int count = 0;+ uint32_t nc = ts_node_child_count(node);+ for (uint32_t i = 0; i < nc && count < MAX_BASES_MINUS_1; i++) {+ TSNode child = ts_node_child(node, i);+ if (strcmp(ts_node_type(child), "delegation_specifier") != 0) {+ continue;+ }+ /* Find the user_type (directly or under a constructor_invocation). */+ TSNode ut = ts_node_named_child(child, 0);+ if (!ts_node_is_null(ut) && strcmp(ts_node_type(ut), "constructor_invocation") == 0) {+ ut = ts_node_named_child(ut, 0);+ }+ if (ts_node_is_null(ut)) {+ continue;+ }+ /* user_type → type_identifier (first child); strip generic args. */+ TSNode ti = ut;+ if (strcmp(ts_node_type(ut), "user_type") == 0 && ts_node_named_child_count(ut) > 0) {+ ti = ts_node_named_child(ut, 0);+ }+ push_base_text(a, ti, source, bases, MAX_BASES_MINUS_1, &count);+ }+ if (count == 0) {+ return NULL;+ }+ const char **result =+ (const char **)cbm_arena_alloc(a, (size_t)(count + NULL_TERM) * sizeof(const char *));+ if (!result) {+ return NULL;+ }+ for (int i = 0; i < count; i++) {+ result[i] = bases[i];+ }+ result[count] = NULL;+ return result;+}+// Walk a field node and collect type identifier names into out[].// Handles: direct type_identifier/generic_type/qualified_name, type_list children// (Java interfaces list), and raw text fallback (other languages).@@ -1462,6 +1642,20 @@ static int collect_bases_from_field(CBMArena *a, TSNode field_node, const char *out[count++] = t;}}+ } else if (strcmp(ck, "subscript") == 0) {+ /* Python parameterized base, e.g. `class S(Generic[T])`: the base+ * type is the `value` field of the subscript; the bracketed type+ * args must not leak into the stored name. */+ TSNode val = ts_node_child_by_field_name(child, TS_FIELD("value"));+ if (ts_node_is_null(val) && ts_node_named_child_count(child) > 0) {+ val = ts_node_named_child(child, 0);+ }+ if (!ts_node_is_null(val)) {+ char *t = cbm_node_text(a, val, source);+ if (t && t[0]) {+ out[count++] = t;+ }+ }} else if (strcmp(ck, "type_list") == 0 || strcmp(ck, "interface_type_list") == 0) {// Java: super_interfaces contains type_list with multiple type_identifiers.uint32_t tlnc = ts_node_named_child_count(child);@@ -1499,7 +1693,53 @@ static int collect_bases_from_field(CBMArena *a, TSNode field_node, const char *// Extract base class names from a class node.static const char **extract_base_classes(CBMArena *a, TSNode node, const char *source,CBMLanguage lang) {- (void)lang;+ // Languages whose heritage is not exposed via a tree-sitter field need+ // dedicated walkers; the generic field/keyword path mis-captures them.+ if (lang == CBM_LANG_TYPESCRIPT || lang == CBM_LANG_TSX) {+ const char **ts_result = extract_ts_bases(a, node, source);+ if (ts_result) {+ return ts_result;+ }+ }+ if (lang == CBM_LANG_PHP) {+ const char **php_result = extract_php_bases(a, node, source);+ if (php_result) {+ return php_result;+ }+ }+ if (lang == CBM_LANG_KOTLIN) {+ const char **kt_result = extract_kotlin_bases(a, node, source);+ if (kt_result) {+ return kt_result;+ }+ }+ // Squirrel: `class Dog extends Animal` — heritage is an `identifier` child+ // directly following the `extends` keyword (no field). Grab it.+ if (lang == CBM_LANG_SQUIRREL) {+ uint32_t sc = ts_node_child_count(node);+ bool seen_extends = false;+ for (uint32_t i = 0; i < sc; i++) {+ TSNode child = ts_node_child(node, i);+ const char *ck = ts_node_type(child);+ if (strcmp(ck, "extends") == 0) {+ seen_extends = true;+ continue;+ }+ if (seen_extends && strcmp(ck, "identifier") == 0) {+ char *base = cbm_node_text(a, child, source);+ if (base && base[0]) {+ const char **result =+ (const char **)cbm_arena_alloc(a, 2 * sizeof(const char *));+ if (result) {+ result[0] = base;+ result[1] = NULL;+ return result;+ }+ }+ break;+ }+ }+ }static const char *fields[] = {"superclass","superclasses","superinterfaces",@@ -1521,6 +1761,22 @@ static const char **extract_base_classes(CBMArena *a, TSNode node, const char *s}}+ // Some grammars expose heritage as a named child rather than a field, e.g.+ // Java `interface X extends A, B` → `extends_interfaces` (holds a type_list).+ // Without this the interface's bases were never captured.+ static const char *heritage_children[] = {"extends_interfaces", "super_interfaces", NULL};+ uint32_t top_count = ts_node_child_count(node);+ for (uint32_t i = 0; i < top_count && base_count < MAX_BASES_MINUS_1; i++) {+ TSNode child = ts_node_child(node, i);+ const char *ck = ts_node_type(child);+ for (const char **h = heritage_children; *h; h++) {+ if (strcmp(ck, *h) == 0) {+ base_count += collect_bases_from_field(a, child, source, bases + base_count,+ MAX_BASES_MINUS_1 - base_count);+ }+ }+ }+if (base_count > 0) {const char **result =(const char **)cbm_arena_alloc(a, (base_count + NULL_TERM) * sizeof(const char *));@@ -1982,6 +2238,44 @@ static void set_def_complexity(CBMDefinition *def, TSNode body, const CBMLangSpedef->max_access_depth = cx.max_access_depth;}+/* Extract the bare type name from a Go method receiver node.+ * The receiver is a parameter_list, e.g. "(s *OrderService)" or "(s Order)".+ * Walks to the parameter_declaration's `type` field, unwrapping pointer_type+ * and generic_type, and returns the type_identifier text (e.g. "OrderService").+ * Returns NULL if no type_identifier is found. */+static char *go_receiver_type_name(CBMArena *a, TSNode recv, const char *source) {+ uint32_t nc = ts_node_child_count(recv);+ for (uint32_t i = 0; i < nc; i++) {+ TSNode child = ts_node_child(recv, i);+ if (strcmp(ts_node_type(child), "parameter_declaration") != 0) {+ continue;+ }+ TSNode tn = ts_node_child_by_field_name(child, TS_FIELD("type"));+ if (ts_node_is_null(tn)) {+ continue;+ }+ /* Unwrap pointer_type / generic_type down to the type_identifier. */+ for (int guard = 0; guard < 4 && !ts_node_is_null(tn); guard++) {+ const char *tk = ts_node_type(tn);+ if (strcmp(tk, "type_identifier") == 0) {+ return cbm_node_text(a, tn, source);+ }+ if (strcmp(tk, "pointer_type") == 0 || strcmp(tk, "generic_type") == 0) {+ /* pointer_type: child is the pointee type; generic_type has a+ * `type` field for the base type_identifier. */+ TSNode inner = ts_node_child_by_field_name(tn, TS_FIELD("type"));+ if (ts_node_is_null(inner)) {+ inner = ts_node_named_child(tn, 0);+ }+ tn = inner;+ continue;+ }+ break;+ }+ }+ return NULL;+}+static void extract_func_def(CBMExtractCtx *ctx, TSNode node, const CBMLangSpec *spec) {CBMArena *a = ctx->arena;@@ -2044,6 +2338,14 @@ static void extract_func_def(CBMExtractCtx *ctx, TSNode node, const CBMLangSpecif (!ts_node_is_null(recv)) {def.receiver = cbm_node_text(a, recv, ctx->source);def.label = "Method";+ /* Derive parent_class from the receiver type so DEFINES_METHOD edges+ * (and downstream Go IMPLEMENTS/OVERRIDE) link the method to its owning+ * struct/type node. The parent QN must match the type's node QN, which+ * is computed the same way (cbm_fqn_compute on the type name). */+ char *recv_type = go_receiver_type_name(a, recv, ctx->source);+ if (recv_type && recv_type[0]) {+ def.parent_class = cbm_fqn_compute(a, ctx->project, ctx->rel_path, recv_type);+ }}// Decorators + route extraction from decorator AST@@ -2373,6 +2675,90 @@ static void extract_class_def(CBMExtractCtx *ctx, TSNode node, const CBMLangSpecfind_first_descendant_by_kind(node, "simple_identifier", CBM_DESCENDANT_MAX_DEPTH);}}+ // Grammar-only languages whose class/struct/type node carries the name on a+ // plain identifier child (no `name` field) or nested one level under a+ // type-binding wrapper. Class 16 fix: extract_class_def is reached (dispatch+ // works) but name resolution fell through, so 0 nodes were emitted.+ if (ts_node_is_null(name_node)) {+ switch (ctx->language) {+ case CBM_LANG_SQUIRREL: // class_declaration > identifier+ case CBM_LANG_DLANG: // class/struct/interface_declaration > identifier+ case CBM_LANG_HARE: // type_declaration > identifier+ case CBM_LANG_ODIN: // struct_declaration > identifier+ case CBM_LANG_BICEP: // resource/module_declaration > identifier+ name_node = cbm_find_child_by_kind(node, "identifier");+ break;+ case CBM_LANG_POWERSHELL: // class_statement > simple_name+ name_node = cbm_find_child_by_kind(node, "simple_name");+ break;+ case CBM_LANG_SWAY: // impl_item: name is the implemented type (field `type`)+ if (strcmp(kind, "impl_item") == 0) {+ name_node = ts_node_child_by_field_name(node, TS_FIELD("type"));+ }+ break;+ case CBM_LANG_GLEAM: // type_definition > type_name > type_identifier+ name_node = find_first_descendant_by_kind(node, "type_identifier",+ CBM_DESCENDANT_MAX_DEPTH);+ break;+ case CBM_LANG_RESCRIPT: { // type_declaration > type_binding(name=type_identifier)+ TSNode binding = cbm_find_child_by_kind(node, "type_binding");+ if (!ts_node_is_null(binding)) {+ name_node = ts_node_child_by_field_name(binding, TS_FIELD("name"));+ if (ts_node_is_null(name_node)) {+ name_node = cbm_find_child_by_kind(binding, "type_identifier");+ }+ }+ break;+ }+ case CBM_LANG_FSHARP: { // type_definition > *_type_defn > type_name > identifier+ TSNode tn = find_first_descendant_by_kind(node, "type_name",+ CBM_DESCENDANT_MAX_DEPTH);+ if (!ts_node_is_null(tn)) {+ name_node = ts_node_child_by_field_name(tn, TS_FIELD("type_name"));+ if (ts_node_is_null(name_node)) {+ name_node = cbm_find_child_by_kind(tn, "identifier");+ }+ }+ break;+ }+ case CBM_LANG_JULIA: { // struct/abstract_definition > type_head > identifier+ TSNode head = cbm_find_child_by_kind(node, "type_head");+ if (!ts_node_is_null(head)) {+ name_node =+ find_first_descendant_by_kind(head, "identifier", CBM_DESCENDANT_MAX_DEPTH);+ }+ break;+ }+ case CBM_LANG_TCL: { // namespace > word_list > simple_word ("eval" then name)+ TSNode wl = cbm_find_child_by_kind(node, "word_list");+ if (!ts_node_is_null(wl)) {+ int seen = 0;+ uint32_t wc = ts_node_child_count(wl);+ for (uint32_t i = 0; i < wc; i++) {+ TSNode w = ts_node_child(wl, i);+ if (strcmp(ts_node_type(w), "simple_word") == 0) {+ if (seen == 1) { // skip "eval", take the namespace name+ name_node = w;+ break;+ }+ seen++;+ }+ }+ }+ break;+ }+ case CBM_LANG_PASCAL: { // declClass is nested; name lives on the parent declType+ TSNode parent = ts_node_parent(node);+ if (!ts_node_is_null(parent) &&+ strcmp(ts_node_type(parent), "declType") == 0) {+ name_node = ts_node_child_by_field_name(parent, TS_FIELD("name"));+ }+ break;+ }+ default:+ break;+ }+ }if (ts_node_is_null(name_node)) {return;}@@ -2391,6 +2777,18 @@ static void extract_class_def(CBMExtractCtx *ctx, TSNode node, const CBMLangSpec}const char *label = class_label_for_kind(kind);+ // Sway/WGSL: label struct defs as "Struct" and Sway `abi` blocks as+ // "Interface". Scoped to these grammar-only languages so established+ // struct-as-"Class" labeling (Rust/C++/Go/Cap'n Proto …) and the+ // downstream type/IMPLEMENTS resolvers that depend on it are unaffected.+ if (ctx->language == CBM_LANG_SWAY || ctx->language == CBM_LANG_WGSL) {+ if (strcmp(kind, "struct_item") == 0 || strcmp(kind, "struct_declaration") == 0) {+ label = "Struct";+ } else if (strcmp(kind, "abi_item") == 0) {+ label = "Interface";+ }+ }+// Go type_spec: check inner type for interface/structif (strcmp(kind, "type_spec") == 0) {TSNode type_inner = ts_node_child_by_field_name(node, TS_FIELD("type"));@@ -2504,6 +2902,11 @@ static TSNode find_class_body(TSNode class_node, CBMLanguage lang) {if (lang == CBM_LANG_OBJC) {return class_node; // iterate children of the class node itself}+ // Squirrel: class_declaration has no body field — member_declaration nodes+ // (each wrapping a function_declaration) are direct children of the class.+ if (lang == CBM_LANG_SQUIRREL) {+ return class_node;+ }// Fallback: search children for known body node typesstatic const char *body_types[] = {"class_body","interface_body",@@ -2608,6 +3011,11 @@ static TSNode resolve_method_name(TSNode child, CBMLanguage lang) {return cbm_find_child_by_kind(child, "simple_identifier");}+ // Squirrel: function_declaration's name is a plain `identifier` child.+ if (lang == CBM_LANG_SQUIRREL && strcmp(ck, "function_declaration") == 0) {+ return cbm_find_child_by_kind(child, "identifier");+ }+if (strcmp(ck, "arrow_function") == 0) {return resolve_arrow_func_name(child);}@@ -2717,6 +3125,16 @@ static void extract_class_methods(CBMExtractCtx *ctx, TSNode class_node, const ccontinue;}+ // Squirrel wraps each class member in a member_declaration node; the+ // method is the inner function_declaration. Peek through the wrapper.+ if (ctx->language == CBM_LANG_SQUIRREL &&+ strcmp(ts_node_type(child), "member_declaration") == 0) {+ TSNode inner = cbm_find_child_by_kind(child, "function_declaration");+ if (!ts_node_is_null(inner)) {+ child = inner;+ }+ }+// Python wraps @classmethod / @staticmethod / @property methods in// a decorated_definition node. Peek through it to find the inner// function_definition so we still emit a Method entry.diff --git a/internal/cbm/lang_specs.c b/internal/cbm/lang_specs.cindex 2886f8498..62bddbfcb 100644--- a/internal/cbm/lang_specs.c+++ b/internal/cbm/lang_specs.c@@ -317,7 +317,7 @@ static const char *java_class_types[] = {"class_declaration", "interface_decla"package_declaration", NULL};static const char *java_field_types[] = {"field_declaration", NULL};static const char *java_module_types[] = {"program", NULL};-static const char *java_call_types[] = {"method_invocation", NULL};+static const char *java_call_types[] = {"method_invocation", "object_creation_expression", NULL};static const char *java_import_types[] = {"import_declaration", "extends", "import", NULL};static const char *java_branch_types[] = {"if_statement", "for_statement", "enhanced_for_statement",@@ -363,7 +363,8 @@ static const char *cs_class_types[] = {"class_declaration","type_declaration",NULL};static const char *cs_module_types[] = {"compilation_unit", NULL};-static const char *cs_call_types[] = {"invocation_expression", NULL};+static const char *cs_call_types[] = {"invocation_expression", "object_creation_expression",+ NULL};static const char *cs_import_types[] = {"using_directive", "namespace_use_declaration","using_statement", "namespace_declaration", NULL};static const char *cs_branch_types[] = {"if_statement", "for_statement", "foreach_statement",@@ -386,6 +387,7 @@ static const char *php_import_types[] = {"extends", "include", "namespacstatic const char *php_module_types[] = {"program", NULL};static const char *php_call_types[] = {"member_call_expression", "scoped_call_expression","function_call_expression",+ "object_creation_expression","nullsafe_member_call_expression", NULL};static const char *php_branch_types[] = {"if_statement", "for_statement", "foreach_statement","while_statement", "switch_statement", "case_statement",@@ -413,7 +415,7 @@ static const char *scala_class_types[] = {"class_definition", "object_definition"type_definition", NULL};static const char *scala_module_types[] = {"compilation_unit", NULL};static const char *scala_call_types[] = {"call_expression", "generic_function", "field_expression",- "infix_expression", NULL};+ "infix_expression", "instance_expression", NULL};static const char *scala_import_types[] = {"import_declaration", "extends", "import","using_directive", NULL};static const char *scala_branch_types[] = {diff --git a/src/discover/language.c b/src/discover/language.cindex 56f9f8521..bacb8e476 100644--- a/src/discover/language.c+++ b/src/discover/language.c@@ -83,6 +83,9 @@ static const ext_entry_t EXT_TABLE[] = {{".ex", CBM_LANG_ELIXIR},{".exs", CBM_LANG_ELIXIR},+ /* DotEnv */+ {".env", CBM_LANG_DOTENV},+/* Elm */{".elm", CBM_LANG_ELM},@@ -516,6 +519,9 @@ static const ext_entry_t EXT_TABLE[] = {/* ReScript */{".resi", CBM_LANG_RESCRIPT},+ /* Regex */+ {".re", CBM_LANG_REGEX},+/* Racket */{".rkt", CBM_LANG_RACKET},@@ -656,6 +662,9 @@ static const filename_entry_t FILENAME_TABLE[] = {{"requirements-test.txt", CBM_LANG_REQUIREMENTS},{"Kconfig", CBM_LANG_KCONFIG},{"go.mod", CBM_LANG_GOMOD},+ {".env", CBM_LANG_DOTENV},+ {".env.local", CBM_LANG_DOTENV},+ {".gitattributes", CBM_LANG_GITATTRIBUTES},};@@ -862,6 +871,15 @@ CBMLanguage cbm_language_for_filename(const char *filename) {}}+ /* DotEnv variant filenames (".env.local", ".env.production", …): the+ * filename starts with ".env." but its last "extension" (e.g. ".local")+ * is not a real language extension. Match the dotenv convention used by+ * pass_envscan/pass_infrascan (".env" exact, ".env." prefix, "*.env"+ * suffix) so file-index routing agrees with direct extraction. */+ if (strncmp(filename, ".env.", SLEN(".env.")) == 0) {+ return CBM_LANG_DOTENV;+ }+/* Fall back to extension-based lookup.* For compound extensions (e.g. ".blade.php") defined in the user config,* scan from the first dot in the basename toward the last, checking userdiff --git a/src/pipeline/pass_lsp_cross.c b/src/pipeline/pass_lsp_cross.cindex 391c25832..61e93d41a 100644--- a/src/pipeline/pass_lsp_cross.c+++ b/src/pipeline/pass_lsp_cross.c@@ -20,6 +20,7 @@#include "lsp/py_lsp.h"#include "lsp/ts_lsp.h"#include "lsp/php_lsp.h"+#include "lsp/java_lsp.h"#include "graph_buffer/graph_buffer.h"#include "foundation/constants.h"#include "foundation/hash_table.h"@@ -287,6 +288,8 @@ bool cbm_pxc_has_cross_lsp(CBMLanguage lang) {case CBM_LANG_TYPESCRIPT:case CBM_LANG_TSX:case CBM_LANG_PHP:+ case CBM_LANG_CSHARP: /* tier-2 prebuilt registry path (pass_parallel.c) */+ case CBM_LANG_JAVA: /* fallback cbm_pxc_run_one path */return true;default:return false;@@ -389,6 +392,10 @@ void cbm_pxc_run_one(CBMLanguage lang, CBMFileResult *r, const char *source, intcbm_run_php_lsp_cross(&scratch, source, source_len, module_qn, defs, def_count, imp_names,imp_qns, imp_count, tree, &out);break;+ case CBM_LANG_JAVA:+ cbm_run_java_lsp_cross(&scratch, source, source_len, module_qn, defs, def_count, imp_names,+ imp_qns, imp_count, tree, &out);+ break;default:break;}diff --git a/src/pipeline/registry.c b/src/pipeline/registry.cindex 2e2a7fb71..f6a96dfa0 100644--- a/src/pipeline/registry.c+++ b/src/pipeline/registry.c@@ -76,10 +76,23 @@ struct cbm_registry {/* ── Helpers ─────────────────────────────────────────────────────── */-/* Extract last dot-separated segment from a QN. Returns pointer into s. */+/* Extract the last path segment from a QN. Returns pointer into s.+ * Recognizes both '.' (most langs) and Rust/C++ '::' separators, so a+ * scoped callee like "lib::square" yields "square" rather than the whole+ * scoped path (which never matches the by-name index). */static const char *simple_name(const char *qn) {- const char *last = strrchr(qn, '.');- return last ? last + SKIP_ONE : qn;+ const char *dot = strrchr(qn, '.');+ const char *seg = dot ? dot + SKIP_ONE : qn;+ /* Find the last "::" and, if it sits after the last '.', use the+ * segment following it. */+ const char *colons = NULL;+ for (const char *p = qn; (p = strstr(p, "::")) != NULL; p += 2) {+ colons = p;+ }+ if (colons && colons + 2 > seg) {+ seg = colons + 2;+ }+ return seg;}/* Extract everything before the last dot. Returns heap-allocated string. */@@ -632,18 +645,29 @@ cbm_resolution_t cbm_registry_resolve(const cbm_registry_t *r, const char *calle}}- /* Split callee: "pkg.Func" → prefix="pkg", suffix="Func" */+ /* Split callee at the first path separator: "pkg.Func" → prefix="pkg",+ * suffix="Func". Rust/C++ use "::" rather than ".", so honor whichever+ * separator appears first ("lib::square" → prefix="lib", suffix="square").+ * Both separators are unambiguous, so handling "::" never affects "."-only+ * callees. */char prefix[CBM_SZ_256] = {0};const char *suffix = NULL;const char *dot = strchr(callee_name, '.');- if (dot) {- size_t plen = dot - callee_name;+ const char *colons = strstr(callee_name, "::");+ const char *sep = dot;+ size_t sep_len = SKIP_ONE; /* length of '.' */+ if (colons && (!sep || colons < sep)) {+ sep = colons;+ sep_len = 2; /* length of "::" */+ }+ if (sep) {+ size_t plen = sep - callee_name;if (plen >= sizeof(prefix)) {plen = sizeof(prefix) - SKIP_ONE;}memcpy(prefix, callee_name, plen);prefix[plen] = '\0';- suffix = dot + SKIP_ONE;+ suffix = sep + sep_len;} else {snprintf(prefix, sizeof(prefix), "%s", callee_name);}diff --git a/tests/test_extraction_inheritance.c b/tests/test_extraction_inheritance.cindex 23a311dd3..063e8d763 100644--- a/tests/test_extraction_inheritance.c+++ b/tests/test_extraction_inheritance.c@@ -773,7 +773,9 @@ static const inherit_case_t cpp_cases[] = {"template<typename T> class Stack : public std::vector<T> { };","Stack",{"std::vector", NULL},- {"public", "template", ":", NULL},+ /* qualified base: `::` is legitimate, so the bare-`:` separator-leak+ * guard does not apply here (it would match inside `std::vector`). */+ {"public", "template", NULL},1},/* ── CRTP pattern ────────────────────────────────────────────── */@@ -820,7 +822,8 @@ static const inherit_case_t cpp_cases[] = {"class MyStream : public std::ostream { public: MyStream() : std::ostream(nullptr) {} };","MyStream",{"std::ostream", NULL},- {"public", ":", NULL},+ /* qualified base: bare-`:` guard omitted (matches inside `std::ostream`). */+ {"public", NULL},1},/* ── protected base ──────────────────────────────────────────── */@@ -848,7 +851,8 @@ static const inherit_case_t cpp_cases[] = {"public: AppError(const char* m) : std::runtime_error(m) {} };","AppError",{"std::runtime_error", NULL},- {"public", ":", NULL},+ /* qualified base: bare-`:` guard omitted (matches inside `std::runtime_error`). */+ {"public", NULL},1},/* ── template class with multiple template base types ────────── */@@ -885,7 +889,8 @@ static const inherit_case_t cpp_cases[] = {"struct MyVisitor : public boost::static_visitor<int> { int operator()(int x) { return x; } };","MyVisitor",{"boost::static_visitor", NULL},- {"public", ":", NULL},+ /* qualified base: bare-`:` guard omitted (matches inside `boost::static_visitor`). */+ {"public", NULL},1},/* ── policy-based design (two template base policies) ────────── */diff --git a/tests/test_grammar_labels.c b/tests/test_grammar_labels.cindex 36af84c37..5a2bbe85e 100644--- a/tests/test_grammar_labels.c+++ b/tests/test_grammar_labels.c@@ -107,7 +107,7 @@ static const LabelGolden LABEL_GOLDENS[] = {{"tcl", "Function:2,Module:1"},{"powershell", "Function:2,Module:1"},{"r", "Function:2,Module:1"},- {"julia", "Function:1,Module:1"},+ {"julia", "Class:1,Function:1,Module:1"},{"matlab", "Function:2,Module:1"},{"ada", "Function:1,Module:1"},{"agda", "Function:1,Module:1"},diff --git a/tests/test_grammar_probe_g.c b/tests/test_grammar_probe_g.cindex 60c20e66f..3ae0580c6 100644--- a/tests/test_grammar_probe_g.c+++ b/tests/test_grammar_probe_g.c@@ -760,13 +760,15 @@ TEST(probe_gitignore_module_only) {"dist/\n"".DS_Store\n");ASSERT_TRUE(m.ok);- /* REAL BUG (NEW class — file-index routing gap): the gitignore grammar +- * histogram (grammar_labels gitignore=Module:1) work via DIRECT- * extraction, but ".gitignore" has no FILENAME_TABLE/EXT_TABLE entry- * (cbm_language_for_filename(".gitignore") → ext ".gitignore" → not in- * EXT_TABLE → CBM_LANG_COUNT), so file-based index_repository never- * routes it → 0 Module nodes. Routing/registration gap. RED. */- ASSERT_TRUE(m.modules == 1); /* REAL BUG — .gitignore not routed by file index */+ /* CONTRACT (corrected): unlike .gitattributes, ".gitignore" is intentionally+ * NOT indexed as a source file — the cbm_discover walker consumes it as+ * ignore-rule input (see test_discover.c discover_with_gitignore /+ * discover_gitignore_dir_excluded_issue234 / discover_cbmignore_stacks,+ * which assert .gitignore is excluded from the discovered file set). The+ * gitignore grammar exists for DIRECT extraction only; via the file walker+ * the ignore-control role wins by design, so it yields 0 nodes. Routing it+ * to CBM_LANG_GITIGNORE would regress those three established tests. */+ ASSERT_TRUE(m.modules == 0); /* .gitignore consumed as ignore-rules, not indexed (by design) */ASSERT_TRUE(m.variables == 0);PASS();}