go/packages: add some documentation for extractPackage

Change-Id: I68d4824157d389c0f08e871eec2b594f52717bae
Reviewed-on: https://go-review.googlesource.com/c/tools/+/173478
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
This commit is contained in:
Rebecca Stambler 2019-04-23 13:49:20 -04:00
parent 15bbd99efc
commit bb3b3ca95a
1 changed files with 6 additions and 1 deletions

View File

@ -105,6 +105,10 @@ func extractImports(filename string, contents []byte) ([]string, error) {
return res, nil return res, nil
} }
// extractPackage attempts to extract a package defined in an overlay.
//
// If the package has errors and has no Name, GoFiles, or Imports,
// then it's possible that it doesn't yet exist on disk.
func extractPackage(pkg *Package, filename string, contents []byte) bool { func extractPackage(pkg *Package, filename string, contents []byte) bool {
// TODO(rstambler): Check the message of the actual error? // TODO(rstambler): Check the message of the actual error?
// It differs between $GOPATH and module mode. // It differs between $GOPATH and module mode.
@ -124,10 +128,11 @@ func extractPackage(pkg *Package, filename string, contents []byte) bool {
if err != nil { if err != nil {
return false return false
} }
// TODO(rstambler): This doesn't work for main packages.
if filepath.Base(pkg.PkgPath) != f.Name.Name { if filepath.Base(pkg.PkgPath) != f.Name.Name {
return false return false
} }
pkg.Name = f.Name.Name pkg.Name = f.Name.Name
pkg.Errors = []Error{} pkg.Errors = nil
return true return true
} }