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): scan every attribute_list sibling, not just the first
Jumaga20156b23078c9da9
diff --git a/internal/cbm/extract_defs.c b/internal/cbm/extract_defs.cindex f9854b03e..611cb6906 100644--- a/internal/cbm/extract_defs.c+++ b/internal/cbm/extract_defs.c@@ -23,6 +23,8 @@#define MAX_PARAMS_MINUS_1 31#define MAX_RETURN_TYPES 16#define MAX_RETURN_TYPES_MINUS_1 15+#define MAX_ATTR_WRAPPERS 16 // stacked C#/PHP attribute_list siblings per declaration (#1692)+#define MAX_ATTR_WRAPPERS_MINUS_1 15// Tree traversal limits.enum {@@ -1287,7 +1289,7 @@ static const char *extract_docstring(CBMArena *a, TSNode node, const char *sourcreturn NULL;}-static TSNode find_jvm_modifiers(TSNode node, CBMLanguage lang);+static int find_jvm_modifiers(TSNode node, CBMLanguage lang, TSNode *out, int max);/* HTTP method names recognized in decorator calls (e.g., @router.post → "POST") */static const char *decorator_method_name(const char *attr_text) {@@ -1673,12 +1675,9 @@ static void scan_route_annotations(CBMArena *a, TSNode owner, const char *source*out_method = NULL;*out_jax_path = NULL;- TSNode wrappers[2];- int wn = 0;- TSNode modifiers = find_jvm_modifiers(owner, spec->language);- if (!ts_node_is_null(modifiers)) {- wrappers[wn++] = modifiers;- }+ /* MINUS_1: the owner node itself is appended below, after the wrappers. */+ TSNode wrappers[MAX_ATTR_WRAPPERS];+ int wn = find_jvm_modifiers(owner, spec->language, wrappers, MAX_ATTR_WRAPPERS_MINUS_1);/* Direct-child annotations (some grammars attach the annotation as a child* of the method node rather than under `modifiers`). */wrappers[wn++] = owner;@@ -1832,13 +1831,23 @@ static int count_modifier_annotations(TSNode modifiers, const CBMLangSpec *spec)return count;}-// Find the wrapper child that holds annotations/attributes for languages where-// they are nested under an intermediate node rather than being a prev-sibling:-// Java/Kotlin/C#/Swift → `modifiers` (contains annotation/attribute)-// PHP 8 → `attribute_list` (contains attribute_group)-// Returns a null node when the language has no such wrapper.-static TSNode find_jvm_modifiers(TSNode node, CBMLanguage lang) {- TSNode null_node = {0};+// Find every wrapper child that holds annotations/attributes for languages+// where they are nested under an intermediate node rather than being a+// prev-sibling:+// Java/Kotlin/Swift → `modifiers` (one node, contains every annotation)+// C#/PHP 8 → `attribute_list` (contains attribute/attribute_group)+//+// C#/PHP attribute stacks are NOT a single wrapper: each bracketed group+// (`[Foo]`, `[Bar]`, ...) compiles to its own `attribute_list` node, so+// `[A] [B] [C]` above a declaration produces three separate `attribute_list`+// siblings among that declaration's children — not one `attribute_list`+// holding three entries. A field-name lookup (`ts_node_child_by_field_name`)+// only ever returns the first child registered under a given field, so using+// it here silently dropped every attribute after the first bracket group+// (#1692). Scanning all children by kind fixes that for C#/PHP and is a+// no-op change for Java/Kotlin/Swift, where `modifiers` never repeats.+// Writes up to `max` wrapper nodes into `out`; returns how many were found.+static int find_jvm_modifiers(TSNode node, CBMLanguage lang, TSNode *out, int max) {const char *wrapper = NULL;switch (lang) {case CBM_LANG_JAVA:@@ -1848,19 +1857,12 @@ static TSNode find_jvm_modifiers(TSNode node, CBMLanguage lang) {break;case CBM_LANG_CSHARP:case CBM_LANG_PHP:- /* C# attributes live in an `attribute_list` child (modifiers like- * `public` are separate `modifier` nodes); PHP 8 likewise nests- * `attribute_group` under `attribute_list`. */wrapper = "attribute_list";break;default:- return null_node;- }- TSNode w = ts_node_child_by_field_name(node, wrapper, (uint32_t)strlen(wrapper));- if (ts_node_is_null(w)) {- w = cbm_find_child_by_kind(node, wrapper);+ return 0;}- return w;+ return cbm_find_children_by_kind(node, wrapper, out, max);}// Count direct children of `node` that are decorator/annotation nodes (used by@@ -1938,13 +1940,14 @@ static const char **extract_decorators(CBMArena *a, TSNode node, const char *souprev = ts_node_prev_sibling(prev);}- TSNode modifiers = {0};+ TSNode wrappers[MAX_ATTR_WRAPPERS];+ int wn = 0;int mod_count = 0;int child_count = 0;if (count == 0) {- modifiers = find_jvm_modifiers(node, lang);- if (!ts_node_is_null(modifiers)) {- mod_count = count_modifier_annotations(modifiers, spec);+ wn = find_jvm_modifiers(node, lang, wrappers, MAX_ATTR_WRAPPERS);+ for (int w = 0; w < wn; w++) {+ mod_count += count_modifier_annotations(wrappers[w], spec);}/* Languages like Scala attach the annotation directly as a child of the* definition node (no wrapper, no prev-sibling). */@@ -1974,8 +1977,8 @@ static const char **extract_decorators(CBMArena *a, TSNode node, const char *sou}prev = ts_node_prev_sibling(prev);}- if (!ts_node_is_null(modifiers)) {- idx = collect_modifier_decorators(a, modifiers, source, spec, result, idx, total);+ for (int w = 0; w < wn && mod_count > 0; w++) {+ idx = collect_modifier_decorators(a, wrappers[w], source, spec, result, idx, total);}if (child_count > 0) {idx = collect_child_decorators(a, node, source, spec, result, idx, total);diff --git a/internal/cbm/helpers.c b/internal/cbm/helpers.cindex f139ff61e..b9b9ab8cf 100644--- a/internal/cbm/helpers.c+++ b/internal/cbm/helpers.c@@ -364,6 +364,18 @@ TSNode cbm_find_child_by_kind(TSNode parent, const char *kind) {return null_node;}+int cbm_find_children_by_kind(TSNode parent, const char *kind, TSNode *out, int max) {+ int n = 0;+ uint32_t count = ts_node_child_count(parent);+ for (uint32_t i = 0; i < count && n < max; i++) {+ TSNode child = ts_node_child(parent, i);+ if (strcmp(ts_node_type(child), kind) == 0) {+ out[n++] = child;+ }+ }+ return n;+}+/* ── Node-type classification: TSSymbol bitset acceleration ───────────────* cbm_kind_in_set is called for nearly every AST node (function/class/call/* import/branching sets), so a linear strcmp over the type-name array is a hotdiff --git a/internal/cbm/helpers.h b/internal/cbm/helpers.hindex b03ef3743..2e7ffcf4e 100644--- a/internal/cbm/helpers.h+++ b/internal/cbm/helpers.h@@ -122,6 +122,13 @@ char *cbm_cpp_out_of_line_parent_class(CBMArena *a, TSNode node, const char *sou// Find a child node by kind string.TSNode cbm_find_child_by_kind(TSNode parent, const char *kind);+// Find every child node matching `kind` (unlike cbm_find_child_by_kind,+// which stops at the first match). Writes up to `max` nodes into `out`;+// returns how many were found. Repeated sibling nodes of the same kind are+// common in some grammars (e.g. C#/PHP stack each `[Attr]` as its own+// attribute_list child) — see #1692.+int cbm_find_children_by_kind(TSNode parent, const char *kind, TSNode *out, int max);+// Check if node kind matches a set of types (NULL-terminated array of strings).bool cbm_kind_in_set(TSNode node, const char **types);