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
co-authored by Claude Opus 5.5
parent 16d1c95f92
commit 22e9f7b337
5 changed files with 194 additions and 10 deletions
+8 -6
View File
@@ -3558,10 +3558,12 @@ export class TreeSitterExtractor {
}
} else if (this.language === 'go') {
// Go: var_declaration, short_var_declaration, const_declaration
// These can have multiple identifiers on the left
const specs = node.namedChildren.filter(c =>
c.type === 'var_spec' || c.type === 'const_spec'
);
// These can have multiple identifiers on the left. A `var ( … )` group
// wraps its specs in a `var_spec_list`; a `const ( … )` group holds them
// directly.
const specs = node.namedChildren
.flatMap((c) => (c.type === 'var_spec_list' ? c.namedChildren : [c]))
.filter((c) => c.type === 'var_spec' || c.type === 'const_spec');
for (const spec of specs) {
const nameNode = spec.namedChild(0);
@@ -3572,8 +3574,8 @@ export class TreeSitterExtractor {
const initValue = valueNode ? getNodeText(valueNode, this.source).slice(0, 100) : undefined;
const initSignature = initValue ? `= ${initValue}${initValue.length >= 100 ? '...' : ''}` : undefined;
// 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.
varNode = this.createNode(node.type === 'const_declaration' ? 'constant' : 'variable', name, spec, {
docstring: this.docstringFor(spec) ?? docstring,
signature: initSignature,