From 663269851cdddc898f963782f74ea574bcd5c814 Mon Sep 17 00:00:00 2001 From: Brad Jones Date: Fri, 31 Mar 2017 15:27:27 -0700 Subject: [PATCH] imports: allow dirPackageInfo to be overridden Change-Id: Ie90d2681e364e2a3f905675db266cb8960e08277 Reviewed-on: https://go-review.googlesource.com/39995 Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- imports/fix.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/imports/fix.go b/imports/fix.go index 1387c997..61a5f062 100644 --- a/imports/fix.go +++ b/imports/fix.go @@ -73,8 +73,11 @@ type packageInfo struct { Globals map[string]bool // symbol => true } -// dirPackageInfo gets information from other files in the package. -func dirPackageInfo(srcDir, filename string) (*packageInfo, error) { +// dirPackageInfo exposes the dirPackageInfoFile function so that it can be overridden. +var dirPackageInfo = dirPackageInfoFile + +// dirPackageInfoFile gets information from other files in the package. +func dirPackageInfoFile(pkgName, srcDir, filename string) (*packageInfo, error) { considerTests := strings.HasSuffix(filename, "_test.go") // Handle file from stdin @@ -178,7 +181,7 @@ func fixImports(fset *token.FileSet, f *ast.File, filename string) (added []stri } if !loadedPackageInfo { loadedPackageInfo = true - packageInfo, _ = dirPackageInfo(srcDir, filename) + packageInfo, _ = dirPackageInfo(f.Name.Name, srcDir, filename) } if decls[pkgName] == nil && (packageInfo == nil || !packageInfo.Globals[pkgName]) { refs[pkgName][v.Sel.Name] = true