fix(go): variables declared in a var ( … ) block are indexed (#2682)

tree-sitter-go wraps the specs of a var group in a var_spec_list node,
unlike a const group's, which sit directly in the declaration. Both
extractors read only the specs directly inside a declaration, so every
variable declared in a var ( ... ) block was missing from the graph: no
node, no call or construction recorded from its initializer, and nothing
for code that reads it, or for a call made through it, to point at.

Each member of a var group is now a variable, as one declared on its
own already was, with its own doc comment or the group's, and its
initializer walked under it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Colby Mchenry
2026-10-19 21:23:07 +00:00
committed by GitHub
parent 16d1c95f92
commit 22e9f7b337
5 changed files with 194 additions and 10 deletions
+14 -4
View File
@@ -682,8 +682,18 @@ impl<'t> Walker<'t> {
let docstring = self.docstring_of(node);
let is_const_decl = node.kind() == "const_declaration";
// A `var ( … )` group wraps its specs in a `var_spec_list`; a
// `const ( … )` group holds them directly.
let mut specs: Vec<Node<'t>> = Vec::new();
for i in 0..node.named_child_count() {
let Some(spec) = node.named_child(i) else { continue };
let Some(child) = node.named_child(i) else { continue };
if child.kind() == "var_spec_list" {
specs.extend((0..child.named_child_count()).filter_map(|j| child.named_child(j)));
} else {
specs.push(child);
}
}
for spec in specs {
if !matches!(spec.kind(), "var_spec" | "const_spec") {
continue;
}
@@ -697,9 +707,9 @@ impl<'t> Walker<'t> {
None
};
let signature = value_node.map(|v| util::init_signature(self.text(v)));
// A member of a `const ( … )` group has its own doc
// comment beside it in the parentheses; one without keeps
// the group's.
// A member of a `const ( … )` or `var ( … )` group has its
// own doc comment beside it in the parentheses; one without
// keeps the group's.
let doc = self.docstring_of(spec).or_else(|| docstring.clone());
var_row = self.create_node(
if is_const_decl { "constant" } else { "variable" },