keyify: don't assume that file is in first package
Due to external tests, there can be two packages in one directory. We
have to find the correct package based on the provided file name.
@@ -102,13 +102,16 @@ func main() {
}
var tf *token.File
var af *ast.File
- pkg := lprog.InitialPackages()[0]
+ var pkg *loader.PackageInfo
+outer:
+ for _, pkg = range lprog.InitialPackages() {
for _, ff := range pkg.Files {
file := lprog.Fset.File(ff.Pos())
if file.Name() == name {
af = ff
tf = file
- break
+ break outer
+ }
}
}
tstart, tend, err := fileOffsetToPos(tf, start, start)
