aboutsummaryrefslogtreecommitdiff
path: root/go/packages/golist.go
diff options
context:
space:
mode:
authorRebecca Stambler <rstambler@golang.org>2020-06-26 00:33:40 -0400
committerRebecca Stambler <rstambler@golang.org>2020-07-10 04:28:08 +0000
commitf1c4188a97a1cbc0a5408db2e5b0d7b0dca73271 (patch)
tree449b31ee28105a0fd523ff227d3140bf4efa9bc5 /go/packages/golist.go
parent125cc70a4027cda5812e28e63f852aea8df190d5 (diff)
downloadgolang-x-tools-f1c4188a97a1cbc0a5408db2e5b0d7b0dca73271.tar.gz
internal/lsp, go/packages: reproduce and fix golang/go#39646
This test exposes a lot of fundamental issues with `go list` overlays. Now that we have the regression test framework, we can copy it over and make any flakes completely reproducible by waiting for each change to complete. The issue here ended up being that initial workspace load returns workspace packages with no associated files due to golang/go#39986. Working around this allows invalidation to proceed as usual. In the process of debugging this, I also noticed that packages can get loaded as command-line-arguments even when we can get the correct package path for them. It's pretty complicated to fix this, so restructured the code a tiny bit and left a TODO. I'd like to come back to this at some point, but it's not pressing since I was able to fix this bug. Fixes golang/go#39646. Updates golang/go#39986. Change-Id: Id6b08a5e92d28eddc731feb0ef3fd3b3fc69e64b Reviewed-on: https://go-review.googlesource.com/c/tools/+/240098 Run-TryBot: Rebecca Stambler <rstambler@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org>
Diffstat (limited to 'go/packages/golist.go')
-rw-r--r--go/packages/golist.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/go/packages/golist.go b/go/packages/golist.go
index 6e91391ce..1a5aba9f9 100644
--- a/go/packages/golist.go
+++ b/go/packages/golist.go
@@ -635,6 +635,23 @@ func (state *golistState) createDriverResponse(words ...string) (*driverResponse
pkg.CompiledGoFiles = pkg.GoFiles
}
+ // Temporary work-around for golang/go#39986. Parse filenames out of
+ // error messages. This happens if there are unrecoverable syntax
+ // errors in the source, so we can't match on a specific error message.
+ if err := p.Error; err != nil && len(err.ImportStack) == 0 && len(pkg.CompiledGoFiles) == 0 {
+ if split := strings.Split(err.Pos, ":"); len(split) > 1 {
+ if filename := split[0]; filename != "" {
+ if !filepath.IsAbs(filename) {
+ filename = filepath.Join(state.cfg.Dir, filename)
+ }
+ if info, _ := os.Stat(filename); info != nil {
+ pkg.CompiledGoFiles = append(pkg.CompiledGoFiles, filename)
+ pkg.GoFiles = append(pkg.GoFiles, filename)
+ }
+ }
+ }
+ }
+
if p.Error != nil {
msg := strings.TrimSpace(p.Error.Err) // Trim to work around golang.org/issue/32363.
// Address golang.org/issue/35964 by appending import stack to error message.