go/packages: fix handling of NeedExportFile in go list

If we need the export file, can't use -find,
which stops the go command too early.

Change-Id: I82adca728e3e8a2435cddad14cfed97665ea4234
Reviewed-on: https://go-review.googlesource.com/c/tools/+/310510
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
Auto-Submit: Russ Cox <rsc@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
diff --git a/go/packages/golist.go b/go/packages/golist.go
index 645f0c7..7aa97f7 100644
--- a/go/packages/golist.go
+++ b/go/packages/golist.go
@@ -819,7 +819,7 @@
 		fmt.Sprintf("-deps=%t", cfg.Mode&NeedImports != 0),
 		// go list doesn't let you pass -test and -find together,
 		// probably because you'd just get the TestMain.
-		fmt.Sprintf("-find=%t", !cfg.Tests && cfg.Mode&findFlags == 0),
+		fmt.Sprintf("-find=%t", !cfg.Tests && cfg.Mode&findFlags == 0 && !usesExportData(cfg)),
 	}
 	fullargs = append(fullargs, cfg.BuildFlags...)
 	fullargs = append(fullargs, "--")