Motivation
We can currently query packages.Load for a package import path with pattern=string, and a path to a Go file within a package of interest with file=path/to/file.go. It would be very useful to be able to query for a package given its directory.
go/build can do this very easily with ImportDir, but x/tools/go/packages lacks the equivalent.
Proposal
A new query "dir=path/to/package" matches the package or packages in the directory path/to/package. For example "dir=~/go/src/fmt" might return the packages "fmt" and "fmt [fmt.test]".
Workaround
Use filepath.Glob to query for all *.go files in a given directory, pick the first one, then perform a file= query. This has much more overhead due to the glob, and is very undesirable when performing a large recursive package import traversal.
Thanks for your consideration.
Motivation
We can currently query
packages.Loadfor a package import path withpattern=string, and a path to a Go file within a package of interest withfile=path/to/file.go. It would be very useful to be able to query for a package given its directory.go/buildcan do this very easily withImportDir, butx/tools/go/packageslacks the equivalent.Proposal
A new query "dir=path/to/package" matches the package or packages in the directory path/to/package. For example "dir=~/go/src/fmt" might return the packages "fmt" and "fmt [fmt.test]".
Workaround
Use
filepath.Globto query for all*.gofiles in a given directory, pick the first one, then perform afile=query. This has much more overhead due to the glob, and is very undesirable when performing a large recursive package import traversal.Thanks for your consideration.