From 1d40570c5c726e05e8ab95c7fb86a26cd5fa0f8b Mon Sep 17 00:00:00 2001 From: Rebecca Stambler Date: Mon, 17 Jun 2019 14:37:25 -0400 Subject: [PATCH] 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 TryBot-Result: Gobot Gobot Reviewed-by: Michael Matloob --- go/packages/golist.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/go/packages/golist.go b/go/packages/golist.go index a931fcaa52..2d30457e7e 100644 --- a/go/packages/golist.go +++ b/go/packages/golist.go @@ -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 } }