go: x/tools/gopls: remove workspace packages that no longer exist

What version of Go are you using (go version)?

$ go version
go version go1.13 linux/amd64

Does this issue reproduce with the latest release?

Yes (v0.16.1)

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE="auto"
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/nakama/.cache/go-build"
GOENV="/home/nakama/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/nakama/.gvm/pkgsets/go1.13/global"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/nakama/.gvm/gos/go1.13"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/nakama/.gvm/gos/go1.13/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/nakama/workspace/tokopedia/rechargeapp/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build894095586=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Nothing. The error message pops up frequently out of nowhere, almost randomly without any root cause / action trigger (when I’m changing branch, just moving mouse, or even without doing anything)

What did you expect to see?

Nothing

What did you see instead?

image

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 3
  • Comments: 16 (5 by maintainers)

Commits related to this issue

Most upvoted comments

Thanks for the repro case, @cretz. I am able to reproduce. I think that https://golang.org/cl/250949 should fix the pop-up, but I’ll investigate the underlying causes here.

I am experiencing this issue and have narrowed down when it occurs. It occurs whenever you have a package where the only test files are in package _test instead of the same package as the rest of the files. For example, if you have foo/foo.go with package foo, and foo/foo_test.go as package foo_test, this error will come up as:

The code in the workspace failed to compile (see the error message below). If you believe this is a mistake, please file an issue: https://github.com/golang/go/issues/new. path/to/foo [path/to/foo.test] has no metadata

But if you make any test in that same dir that uses the same package (e.g. foo/bar_test.go with package foo) it will work. From the outside, it makes sense from the message why this bug exists. The tool is erroneously looking for a foo.test package if any test is present, not realizing that all tests might be in a separate foo_test.test package.

EDIT: To repeatedly replicate after a restart/reload, you may have to create that foo/bar_test.go with package foo, then delete it.