mirror of
https://github.com/golang/go
synced 2024-11-18 10:54:40 -07:00
cmd/guru: if query file is not beneath GOPATH, treat it as a package
This allows type-based guru queries to work on arbitrary files at the root or even outside of a GOPATH workspace (as "go run foo.go" does). Fixes golang/go#15797 Change-Id: I2be28f7259448e6398aae84d6ae7e71d8649967a Reviewed-on: https://go-review.googlesource.com/30451 Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
parent
73d2e795b8
commit
27f88d9b7a
@ -173,9 +173,11 @@ func importQueryPackage(pos string, conf *loader.Config) (string, error) {
|
||||
|
||||
_, importPath, err := guessImportPath(filename, conf.Build)
|
||||
if err != nil {
|
||||
return "", err // can't find GOPATH dir
|
||||
}
|
||||
|
||||
// Can't find GOPATH dir.
|
||||
// Treat the query file as its own package.
|
||||
importPath = "command-line-arguments"
|
||||
conf.CreateFromFilenames(importPath, filename)
|
||||
} else {
|
||||
// Check that it's possible to load the queried package.
|
||||
// (e.g. guru tests contain different 'package' decls in same dir.)
|
||||
// Keep consistent with logic in loader/util.go!
|
||||
@ -200,6 +202,7 @@ func importQueryPackage(pos string, conf *loader.Config) (string, error) {
|
||||
return "", fmt.Errorf("package %q doesn't contain file %s",
|
||||
importPath, filename)
|
||||
}
|
||||
}
|
||||
|
||||
conf.TypeCheckFuncBodies = func(p string) bool { return p == importPath }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user