diff options
author | Heschi Kreinick <heschi@google.com> | 2018-12-20 16:09:19 -0500 |
---|---|---|
committer | Heschi Kreinick <heschi@google.com> | 2018-12-21 00:13:48 +0000 |
commit | 537d06c362073e8c95164d0d4709059603cfdb02 (patch) | |
tree | 55a7a121ef512e1213eee3f3d1b4aa08e40d6344 /imports | |
parent | d12035dfdc6da9d82d9f9d0fba01b218324cb314 (diff) | |
download | golang-x-tools-537d06c362073e8c95164d0d4709059603cfdb02.tar.gz |
imports: use LoadFiles everywhere
Since we don't really need type info, and want everything to be fast,
use LoadFiles and do parsing manually. It would be nice if there were a
mode for that.
Change-Id: I33f8a85ffb87a70048c4775058bd0813cf677061
Reviewed-on: https://go-review.googlesource.com/c/155478
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Diffstat (limited to 'imports')
-rw-r--r-- | imports/fix.go | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/imports/fix.go b/imports/fix.go index 8267f087c..691240926 100644 --- a/imports/fix.go +++ b/imports/fix.go @@ -580,7 +580,7 @@ func scanGoPackages(refs map[string]map[string]bool) ([]*pkg, error) { loadQueries = append(loadQueries, "name="+pkgName) } sort.Strings(loadQueries) - cfg := newPackagesConfig(packages.LoadTypes) + cfg := newPackagesConfig(packages.LoadFiles) goPackages, err := packages.Load(cfg, loadQueries...) if err != nil { return nil, err @@ -846,19 +846,29 @@ func VendorlessPath(ipath string) string { // loadExports returns the set of exported symbols in the package at dir. // It returns nil on error or if the package name in dir does not match expectPackage. func loadExports(ctx context.Context, expectPackage string, pkg *pkg) (map[string]bool, error) { + if Debug { + log.Printf("loading exports in dir %s (seeking package %s)", pkg.dir, expectPackage) + } if pkg.goPackage != nil { exports := map[string]bool{} - for _, name := range pkg.goPackage.Types.Scope().Names() { - if ast.IsExported(name) { - exports[name] = true + fset := token.NewFileSet() + for _, fname := range pkg.goPackage.CompiledGoFiles { + f, err := parser.ParseFile(fset, fname, nil, 0) + if err != nil { + if Debug { + log.Printf("Parsing %s: %v", fname, err) + } + return nil, err + } + for name := range f.Scope.Objects { + if ast.IsExported(name) { + exports[name] = true + } } } return exports, nil } - if Debug { - log.Printf("loading exports in dir %s (seeking package %s)", pkg.dir, expectPackage) - } exports := make(map[string]bool) buildCtx := build.Default |