1
0
mirror of https://github.com/golang/go synced 2024-11-18 14:54:40 -07:00

go/packages: fix support for ad-hoc packages to handle errors

This change retries the query even if go/packages returns an error, not
just an empty response.

This also fixes support for ad-hoc packages in gopls.

Change-Id: I7bc07c225568efd18f4e5759f7eb3c23cd12bfa4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/182580
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
This commit is contained in:
Rebecca Stambler 2019-06-17 14:37:25 -04:00
parent 6fea9ef05e
commit 1d40570c5c

View File

@ -229,12 +229,11 @@ func runContainsQueries(cfg *Config, driver driver, response *responseDeduper, q
}
dirResponse, err := driver(cfg, pattern)
if err != nil {
return err
}
if len(dirResponse.Roots) == 0 {
// Couldn't find a package for the directory. Try to load the file as an ad-hoc package.
var queryErr error
dirResponse, err = driver(cfg, query)
if err != nil {
if queryErr != nil {
// Return the original error if the attempt to fall back failed.
return err
}
}