Describe the bug
cldk/analysis/commons/treesitter/models.py:50-53 rebinds self.captures inside its loop instead of extending it:
def __init__(self, captures: Dict[str, List[Node]]):
self.captures = []
for capture_name, captures in captures.items():
self.captures = [self.Capture(node=node, name=capture_name) for node in captures]
Every iteration discards the previous one, so a query with more than one capture name returns only the nodes of whichever name the dict yields last. A single-capture query is unaffected, which is why this has gone unnoticed.
The loop variable also shadows the parameter, which is what makes the bug hard to see on a quick read.
Any tree-sitter query in the SDK with two or more capture names silently returns a subset. TreesitterJava.get_calling_lines and get_methods_with_annotations both go through this type. It surfaced while investigating a call-line ordering divergence between the Java backends: the symptom looked like an ordering problem, but the cause is dropped captures.
Whether a caller sees wrong results today depends on how many capture names its query declares, so the blast radius needs checking per query rather than assumed.
To Reproduce
Not stated in the original issue.
Expected behavior
Additional context
Scope boundary
In scope: the accumulation bug, the shadowed parameter, and an audit of every tree-sitter query in the SDK for how many capture names it declares. Out of scope: redesigning the tree-sitter layer.
Goals
Describe the bug
cldk/analysis/commons/treesitter/models.py:50-53rebindsself.capturesinside its loop instead of extending it:Every iteration discards the previous one, so a query with more than one capture name returns only the nodes of whichever name the dict yields last. A single-capture query is unaffected, which is why this has gone unnoticed.
The loop variable also shadows the parameter, which is what makes the bug hard to see on a quick read.
Any tree-sitter query in the SDK with two or more capture names silently returns a subset.
TreesitterJava.get_calling_linesandget_methods_with_annotationsboth go through this type. It surfaced while investigating a call-line ordering divergence between the Java backends: the symptom looked like an ordering problem, but the cause is dropped captures.Whether a caller sees wrong results today depends on how many capture names its query declares, so the blast radius needs checking per query rather than assumed.
To Reproduce
Not stated in the original issue.
Expected behavior
Additional context
Scope boundary
In scope: the accumulation bug, the shadowed parameter, and an audit of every tree-sitter query in the SDK for how many capture names it declares. Out of scope: redesigning the tree-sitter layer.
Goals
Capturesaccumulates across capture names