You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
bug(indexer): Go grouped import (...) blocks yield zero imports — gofmt always groups, so nearly every Go file loses all imports #1521
The imports query requires import_spec to be a direct child of import_declaration. That shape only occurs for a single-line import "fmt". A grouped block nests the specs one level deeper, inside import_spec_list:
import_declaration
└── import_spec_list <- the query does not account for this
├── import_spec "context"
└── import_spec "fmt"
Reproduction
$ .venv/bin/python -c "from codegraphcontext.tools.tree_sitter_parser import TreeSitterParserfrom codegraphcontext.tools.languages.go import GoTreeSitterParserimport tempfile, pathlibd = pathlib.Path(tempfile.mkdtemp())g = d/'m.go'; g.write_text('package main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n)\n\nfunc main() {}\n')print('grouped:', [i.get('name') for i in GoTreeSitterParser(TreeSitterParser('go')).parse(str(g))['imports']])s = d/'s.go'; s.write_text('package main\nimport \"fmt\"\nfunc main(){}\n')print('single: ', [i.get('name') for i in GoTreeSitterParser(TreeSitterParser('go')).parse(str(s))['imports']])"grouped: []single: ['fmt']
Against the repo's own fixture tests/fixtures/sample_projects/sample_project_go/main.go, the current query returns 0 captures; the same query with the import_declaration parent constraint removed returns 2.
Impact
gofmt always rewrites multiple imports into a grouped block, so essentially every real-world Go file loses every import. Across the Go fixtures only 4 imports are found where roughly 30 exist. With no Module nodes and no IMPORTS edges, cross-file call resolution for Go has nothing to work from — local_imports is empty, so every imported symbol falls back to heuristics.
Suggested fix
Match import_spec at both depths, e.g. add an alternative for (import_declaration (import_spec_list (import_spec) @import)).
Environment
Commit
c0e0bed (main)
Python
3.12.3, Linux
Reproduced with the snippet above and against the repo's Go fixture.
The imports query now matches import_spec at both depths — as a direct child of import_declaration and nested inside import_spec_list — for both the plain and aliased forms.
The repo's own sample_project_go/main.go fixture went from 0 imports to 2, and the regenerated golden gained 14 Module nodes (2 → 16) with nothing lost.
Activity
github-actions commentedon Aug 1, 2026
Hi! 👋 Join our CodeGraphContext Discord channel to collaborate: https://discord.gg/dR4QY32uYQ
fix(parsers): recover Python annotated parameters and Go grouped impo…
Shashankss1205 commentedon Aug 2, 2026
Fixed in #1561 (merged as
458fd50).The imports query now matches
import_specat both depths — as a direct child ofimport_declarationand nested insideimport_spec_list— for both the plain and aliased forms.Verified after the fix:
The repo's own
sample_project_go/main.gofixture went from 0 imports to 2, and the regenerated golden gained 14 Module nodes (2 → 16) with nothing lost.chore(release): bump version to 0.5.5 (#1569)