Skip to content

Commit 6dbb3c2

Browse files
wzekinclaude
andcommitted
fix(go): fill File-level metadata for pre-parsed packages
When a package was pre-parsed via cross-module referCodes, only Functions were populated but File.Package/Imports were left empty. This broke downstream reachability analysis based on the package import graph. Now we still fill File-level metadata for such packages while skipping duplicate function-body parsing. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent f7385d6 commit 6dbb3c2

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

lang/golang/parser/pkg.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,18 @@ func (p *GoParser) loadPackages(mod *Module, dir string, pkgPath PkgPath) (err e
217217
fmt.Fprintf(os.Stderr, "[loadPackages] mod: %s, dir: %s, pkgPath: %s, hasCGO: %v\n", mod.Name, dir, pkgPath, hasCGO)
218218

219219
for _, pkg := range pkgs {
220+
// The package may have been pre-parsed by referCodes for cross-module
221+
// references (only Functions populated, no File-level Package/Imports).
222+
// We must not skip entirely: otherwise File.Package and File.Imports
223+
// remain empty, breaking downstream reachability analysis based on
224+
// the package import graph. Instead, still fill File-level metadata
225+
// but skip duplicate function body parsing and package-level finalization.
226+
alreadyParsed := false
220227
if mm := p.repo.Modules[mod.Name]; mm != nil && (*mm).Packages[pkg.ID] != nil {
221-
continue
228+
alreadyParsed = true
222229
}
223230
if pp, ok := mod.Packages[pkg.ID]; ok && pp != nil {
224-
continue
231+
alreadyParsed = true
225232
}
226233
for idx, file := range pkg.Syntax {
227234
var filePath string
@@ -278,10 +285,17 @@ func (p *GoParser) loadPackages(mod *Module, dir string, pkgPath PkgPath) (err e
278285
f.Package = pkg.ID
279286
f.Imports = imports.Origins
280287
}
288+
// Skip duplicate function body parsing when package was pre-parsed.
289+
if alreadyParsed {
290+
continue
291+
}
281292
if err := p.parseFile(ctx, file); err != nil {
282293
return err
283294
}
284295
}
296+
if alreadyParsed {
297+
continue
298+
}
285299
if obj := mod.Packages[pkg.ID]; obj != nil {
286300
// obj.Dependencies = make([]PkgPath, 0, len(pkg.Imports))
287301
// for _, imp := range pkg.Imports {

0 commit comments

Comments
 (0)