go: x/tools/gopls: error when adding a new file to a package
I am using the latest version of gopls in vscode. when create a new directory, and create a new go file in the directory, open the new go file, I type the package hello.

I get the error:
file:///d:/code/go/src/github.com/mgxian/tdd-practice/hello/hello_test.go is not part of a package
When I reload the vscode window, the error disappear.
What version of Go are you using (go version)?
$ go version
go version go1.12.5 windows/amd64
$ gopls version
golang.org/x/tools/cmd/gopls
golang.org/x/tools@v0.0.0-20190606050223-4d9ae51c2468 h1:fTfk6GjmihJbK0mSUFgPPgYpsdmApQ86Mcd4GuKax9U=
go env Output
$ go env set GOARCH=amd64 set GOBIN= set GOCACHE=C:\Users\will\AppData\Local\go-build set GOEXE=.exe set GOFLAGS= set GOHOSTARCH=amd64 set GOHOSTOS=windows set GOOS=windows set GOPATH=D:\code\go set GOPROXY=https://goproxy.io set GORACE= set GOROOT=C:\Go set GOTMPDIR= set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64 set GCCGO=gccgo set CC=gcc set CXX=g++ set CGO_ENABLED=1 set GOMOD=D:\code\go\src\github.com\mgxian\tdd-practice\go.mod set CGO_CFLAGS=-g -O2 set CGO_CPPFLAGS= set CGO_CXXFLAGS=-g -O2 set CGO_FFLAGS=-g -O2 set CGO_LDFLAGS=-g -O2 set PKG_CONFIG=pkg-config set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\will\AppData\Local\Temp\go-build905230974=/tmp/go-build -gno-record-gcc-switches
What did you do?
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 16
- Comments: 15 (6 by maintainers)
Thanks for confirming.
@rssathe, @Thomas2500, and anyone with similar issues - it seems like
goplsis not working for you more generally, so please see the information under https://github.com/golang/go/wiki/gopls#troubleshooting and open new separate issues if you are still seeing these problems.This particular error should be fixed as of https://go-review.googlesource.com/c/tools/+/184258. Please update to master to get the fix. However, it looks like there is something else going wrong when type-checking your package. Are you opening VSCode to the directory of your module root?
@stamblerre
The newest version fixed this, indeed (the problem with existing go files).
@gabstv: Can you sync to the latest version of
goplson master (go get -u golang.org/x/tools/gopls@master)? We have made some changes recently that should have solved most of those problems.There will still be some latency in adding a new file because
goplscan’t distinguish between a new file and a newly-opened one, so, leaving this issue open.