Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/tools/gopls: undeclared name error in package with multiple files #41965

Open
dieseldesai opened this issue Oct 14, 2020 · 6 comments
Open

x/tools/gopls: undeclared name error in package with multiple files #41965

dieseldesai opened this issue Oct 14, 2020 · 6 comments

Comments

@dieseldesai
Copy link

@dieseldesai dieseldesai commented Oct 14, 2020

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

$ go version
1.15

Does this issue reproduce with the latest release?

Yes

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/.cache/go-build"
GOENV="/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT=""
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/go/src/path/to/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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build617375105=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I'm using VSCode with a remote server. When opening a file, everything is ok. After typing some code and saving, the language server does some stuff and comes back with a bunch of undeclared name errors for types declared in the same package but in different files. The code still compiles fine using go build

I noticed the following log lines in gopls server (directory paths elided):

[Info  - 8:31:27 PM] 2020/10/13 20:31:27 go/packages.Load
	snapshot=30
	directory=<my-root-dir>
	query=[file=<my-root-dir>/path/to/<working-file>.go]
	packages=1

[Info  - 8:31:27 PM] 2020/10/13 20:31:27 go/packages.Load
	snapshot=30
	package_path="command-line-arguments"
	files=[<my-root-dir>/path/to/<working-file>.go]

From previous issues, it seems like the second log message is the issue because of "command-line-arguments"

This is a single module repository and I've tried Add Folder to Workspace on the root dir (that contains go.mod)

What did you expect to see?

No undeclared name errors

What did you see instead?

Many undeclared name errors

@gopherbot gopherbot added this to the Unreleased milestone Oct 14, 2020
@stamblerre
Copy link
Contributor

@stamblerre stamblerre commented Oct 14, 2020

@dieseldesai: Can you please share the output of gopls -rpc.trace -v check path/to/file.go?

@dieseldesai
Copy link
Author

@dieseldesai dieseldesai commented Oct 14, 2020

The problem seems to have disappeared overnight. The only change was I had to reconnect to the remote SSH session and I assume the language server had to restart when the vscode window was reloaded.

Would the output of that command still be useful right now?

@stamblerre
Copy link
Contributor

@stamblerre stamblerre commented Oct 14, 2020

If the issue is no longer happening, then we can go ahead and close this.
If you see the problem again, the output of that command would help with investigation.

@dieseldesai
Copy link
Author

@dieseldesai dieseldesai commented Oct 14, 2020

Ok, I'll reopen this issue if the problem recurs

@dieseldesai
Copy link
Author

@dieseldesai dieseldesai commented Oct 16, 2020

The problem came back today. Here's the result of running the rpc.trace command on the file:

2020/10/16 13:33:23 Info:2020/10/16 13:33:23 go env for <home>/go/src/<repo-root>
(root <home>/go/src/<repo-root>)
(go version go version go1.15 linux/amd64
)
(valid build configuration = true)
(build flags: [])
GOMODCACHE=<home>/go/pkg/mod
GONOPROXY=
GONOSUMDB=
GOSUMDB=sum.golang.org
GOCACHE=<home>/.cache/go-build
GOMOD=<home>/go/src/<repo-root>/go.mod
GOPATH=<home>/go
GOPROXY=https://proxy.golang.org,direct
GOFLAGS=
GOPRIVATE=
GO111MODULE=
GOINSECURE=
GOROOT=/usr/lib/google-golang

2020/10/16 13:33:26 Info:2020/10/16 13:33:26 go/packages.Load
        snapshot=0
        directory=<home>/go/src/<repo-root>
        query=[./... builtin]
        packages=334
@dieseldesai dieseldesai reopened this Oct 16, 2020
@stamblerre
Copy link
Contributor

@stamblerre stamblerre commented Oct 16, 2020

Thanks for sharing that. Looks like there's nothing wrong the packages in your directory--it's likely that some edit you are making is causing the problems. Are you able to share a full (possibly redacted) log from an editor session?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.