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: Unclared name same package different file #33693

Closed
Nokel81 opened this issue Aug 16, 2019 · 12 comments
Closed

x/tools/gopls: Unclared name same package different file #33693

Nokel81 opened this issue Aug 16, 2019 · 12 comments

Comments

@Nokel81
Copy link

@Nokel81 Nokel81 commented Aug 16, 2019

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

$ go version
go version go1.12.7 darwin/amd64

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
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/sebastianmalton/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/sebastianmalton/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.12.7/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.12.7/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/sebastianmalton/repos/connect/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=/var/folders/ry/97wxxdgj26s531q_1yw8w39r0000gq/T/go-build071357332=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Create a file in a package, declare some public token say func Foobar() {...}. Declare a test file for that same file in the same package. Try and use Foobar().

What did you expect to see?

No errors

What did you see instead?

undeclared name: FooBar

@gopherbot gopherbot added this to the Unreleased milestone Aug 16, 2019
@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Aug 16, 2019

Thank you for filing a gopls issue! Please take a look at the Troubleshooting section of the gopls Wiki page, and make sure that you have provided all of the relevant information here.

@stamblerre

This comment has been minimized.

Copy link
Contributor

@stamblerre stamblerre commented Aug 16, 2019

Are you opening your editor from the directory that contains the go.mod file?

@Nokel81

This comment has been minimized.

Copy link
Author

@Nokel81 Nokel81 commented Aug 16, 2019

@stamblerre

This comment has been minimized.

Copy link
Contributor

@stamblerre stamblerre commented Aug 16, 2019

Please provide the output of gopls -rpc.trace -v check /path/to/file.go, as requested in the Troubleshooting section of the gopls Wiki page.

@Nokel81

This comment has been minimized.

Copy link
Author

@Nokel81 Nokel81 commented Aug 19, 2019

2019/08/19 09:44:02 Info:31.313208ms for GOROOT= GOPATH=/Users/sebastianmalton/go GO111MODULE= PWD=/Users/sebastianmalton/repos/cnt go "env" "GOMOD", stderr: <<>>
2019/08/19 09:44:02 Info:44.212733ms for GOROOT= GOPATH=/Users/sebastianmalton/go GO111MODULE= PWD=/Users/sebastianmalton/repos/cnt go "list" "-e" "-json" "-compiled=true" "-test=true" "-export=false" "-deps=true" "-find=false" "--" "builtin", stderr: <<>>
2019/08/19 09:44:02 Info:54.851847ms for GOROOT= GOPATH=/Users/sebastianmalton/go GO111MODULE= PWD=/Users/sebastianmalton/repos/cnt go "list" "-m" "-json" "all", stderr: <<>>
2019/08/19 09:44:02 Info:Build info
----------
version v0.1.3-cmd.gopls, built in $GOPATH mode

Go info
-------
go version go1.12.7 darwin/amd64

GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/sebastianmalton/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/sebastianmalton/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.12.7/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.12.7/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/sebastianmalton/repos/cnt/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=/var/folders/ry/97wxxdgj26s531q_1yw8w39r0000gq/T/go-build396092128=/tmp/go-build -gno-record-gcc-switches -fno-common"
2019/08/19 09:44:02 Info:23.811333ms for GOROOT= GOPATH=/Users/sebastianmalton/go GO111MODULE= PWD=/Users/sebastianmalton/repos/cnt go "env" "GOMOD", stderr: <<>>
2019/08/19 09:44:02 Info:44.130095ms for GOROOT= GOPATH=/Users/sebastianmalton/go GO111MODULE= PWD=/Users/sebastianmalton/repos/cnt go "list" "-m" "-json" "all", stderr: <<>>
2019/08/19 09:44:02 Info:295.344528ms for GOROOT= GOPATH=/Users/sebastianmalton/go GO111MODULE= PWD=/Users/sebastianmalton/repos/cnt go "list" "-e" "-json" "-compiled=true" "-test=true" "-export=false" "-deps=true" "-find=false" "--" "/Users/sebastianmalton/repos/cnt/services/socket", stderr: <<>>
2019/08/19 09:44:02 Info:go/packages.Load
	package = github.com/d/cnt/services/socket
	files = [/Users/sebastianmalton/repos/cnt/services/socket/agent.go /Users/sebastianmalton/repos/cnt/services/socket/agent_test.go]
2019/08/19 09:44:02 Info:go/packages.Load
	packages = 1
@stamblerre

This comment has been minimized.

Copy link
Contributor

@stamblerre stamblerre commented Aug 19, 2019

Ok, so it looks like everything here is correct. What editor are you using? Can you provide gopls logs from when you see this error?

@Nokel81

This comment has been minimized.

Copy link
Author

@Nokel81 Nokel81 commented Aug 19, 2019

I am using vscode:

Version: 1.37.0
Commit: 036a6b1d3ac84e5ca96a17a44e63a87971f8fcc8
Date: 2019-08-08T01:22:37.660Z
Electron: 4.2.7
Chrome: 69.0.3497.128
Node.js: 10.11.0
V8: 6.9.427.31-electron.0
OS: Darwin x64 18.7.0

Logs:

[Info  - 10:07:58 AM] 62.250495ms for GOROOT=/usr/local/Cellar/go/1.12.7/libexec GOPATH=/Users/sebastianmalton/go GO111MODULE= PWD=/Users/sebastianmalton/repos go "list" "-e" "-json" "-compiled=true" "-test=true" "-export=false" "-deps=true" "-find=false" "--" "/Users/sebastianmalton/repos/cnt/services/socket/agent_test.go", stderr: <<>>

[Error - 10:07:58 AM] Request textDocument/codeAction failed.
  Message: go/packages.Load: no packages found for /Users/sebastianmalton/repos/cnt/services/socket/agent_test.go
  Code: 0 

Even though if I run env | grep GO in a new terminal I get GO111MODULE=on

@stamblerre

This comment has been minimized.

Copy link
Contributor

@stamblerre stamblerre commented Aug 19, 2019

Can you try setting "go.toolsEnvVars": { "GO111MODULE": "on" } ?

@Nokel81

This comment has been minimized.

Copy link
Author

@Nokel81 Nokel81 commented Aug 19, 2019

Having set that option and reloaded the Go plugin for vscode the output how has GO111MODULE=on but still no packages found. I am no longer getting a displayed error for unused variables either.

@stamblerre

This comment has been minimized.

Copy link
Contributor

@stamblerre stamblerre commented Aug 19, 2019

Can you share the full gopls logs that you are seeing, starting from the very top of the file?

@Nokel81

This comment has been minimized.

Copy link
Author

@Nokel81 Nokel81 commented Aug 19, 2019

Logs

[Info  - 10:55:11 AM] 23.207675ms for GOROOT=/usr/local/Cellar/go/1.12.7/libexec GOPATH=/Users/sebastianmalton/go GO111MODULE=on PWD=/Users/sebastianmalton/repos go "env" "GOMOD", stderr: <<>>

[Trace - 10:55:11 AM] Received notification 'window/logMessage' in 0ms.
Params: {"type":3,"message":"23.207675ms for GOROOT=/usr/local/Cellar/go/1.12.7/libexec GOPATH=/Users/sebastianmalton/go GO111MODULE=on PWD=/Users/sebastianmalton/repos go \"env\" \"GOMOD\", stderr: \u003c\u003c\u003e\u003e\n"}


[Info  - 10:55:11 AM] 33.620515ms for GOROOT=/usr/local/Cellar/go/1.12.7/libexec GOPATH=/Users/sebastianmalton/go GO111MODULE=on PWD=/Users/sebastianmalton/repos go "list" "-m" "-json" "all", stderr: <<warning: pattern "all" matched no module dependencies
>>

[Trace - 10:55:11 AM] Received notification 'window/logMessage' in 0ms.
Params: {"type":3,"message":"33.620515ms for GOROOT=/usr/local/Cellar/go/1.12.7/libexec GOPATH=/Users/sebastianmalton/go GO111MODULE=on PWD=/Users/sebastianmalton/repos go \"list\" \"-m\" \"-json\" \"all\", stderr: \u003c\u003cwarning: pattern \"all\" matched no module dependencies\n\u003e\u003e\n"}


[Info  - 10:55:11 AM] 23.427142ms for GOROOT=/usr/local/Cellar/go/1.12.7/libexec GOPATH=/Users/sebastianmalton/go GO111MODULE=on PWD=/Users/sebastianmalton/repos go "list" "-e" "-json" "-compiled=true" "-test=true" "-export=false" "-deps=true" "-find=false" "--" "/Users/sebastianmalton/repos/cnt/services/socket", stderr: <<go: cannot find main module; see 'go help modules'
>>

[Trace - 10:55:11 AM] Received notification 'window/logMessage' in 0ms.
Params: {"type":3,"message":"23.427142ms for GOROOT=/usr/local/Cellar/go/1.12.7/libexec GOPATH=/Users/sebastianmalton/go GO111MODULE=on PWD=/Users/sebastianmalton/repos go \"list\" \"-e\" \"-json\" \"-compiled=true\" \"-test=true\" \"-export=false\" \"-deps=true\" \"-find=false\" \"--\" \"/Users/sebastianmalton/repos/cnt/services/socket\", stderr: \u003c\u003cgo: cannot find main module; see 'go help modules'\n\u003e\u003e\n"}


[Trace - 10:55:12 AM] Received response 'textDocument/documentLink - (43)' in 0ms.
Params: {}


[Trace - 10:55:12 AM] Sending notification 'textDocument/documentLink' in 782ms.
Params: {"textDocument":{"uri":"file:///Users/sebastianmalton/repos/cnt/services/socket/agent_test.go"}}


[Trace - 10:55:12 AM] Received notification 'window/logMessage' in 0ms.
Params: {"type":3,"message":"728.217963ms for GOROOT=/usr/local/Cellar/go/1.12.7/libexec GOPATH=/Users/sebastianmalton/go GO111MODULE=on PWD=/Users/sebastianmalton/repos go \"list\" \"-e\" \"-json\" \"-compiled=true\" \"-test=true\" \"-export=false\" \"-deps=true\" \"-find=false\" \"--\" \"/Users/sebastianmalton/repos/cnt/services/socket/agent_test.go\", stderr: \u003c\u003c\u003e\u003e\n"}


[Info  - 10:55:12 AM] 728.217963ms for GOROOT=/usr/local/Cellar/go/1.12.7/libexec GOPATH=/Users/sebastianmalton/go GO111MODULE=on PWD=/Users/sebastianmalton/repos go "list" "-e" "-json" "-compiled=true" "-test=true" "-export=false" "-deps=true" "-find=false" "--" "/Users/sebastianmalton/repos/cnt/services/socket/agent_test.go", stderr: <<>>

[Error - 10:55:12 AM] Request textDocument/documentLink failed.
  Message: go/packages.Load: no packages found for /Users/sebastianmalton/repos/cnt/services/socket/agent_test.go
  Code: 0 
[Info  - 10:55:12 AM] 24.834005ms for GOROOT=/usr/local/Cellar/go/1.12.7/libexec GOPATH=/Users/sebastianmalton/go GO111MODULE=on PWD=/Users/sebastianmalton/repos go "env" "GOMOD", stderr: <<>>

[Trace - 10:55:12 AM] Received notification 'window/logMessage' in 0ms.
Params: {"type":3,"message":"24.834005ms for GOROOT=/usr/local/Cellar/go/1.12.7/libexec GOPATH=/Users/sebastianmalton/go GO111MODULE=on PWD=/Users/sebastianmalton/repos go \"env\" \"GOMOD\", stderr: \u003c\u003c\u003e\u003e\n"}


[Info  - 10:55:12 AM] 28.934931ms for GOROOT=/usr/local/Cellar/go/1.12.7/libexec GOPATH=/Users/sebastianmalton/go GO111MODULE=on PWD=/Users/sebastianmalton/repos go "list" "-m" "-json" "all", stderr: <<warning: pattern "all" matched no module dependencies
>>

[Trace - 10:55:12 AM] Received notification 'window/logMessage' in 0ms.
Params: {"type":3,"message":"28.934931ms for GOROOT=/usr/local/Cellar/go/1.12.7/libexec GOPATH=/Users/sebastianmalton/go GO111MODULE=on PWD=/Users/sebastianmalton/repos go \"list\" \"-m\" \"-json\" \"all\", stderr: \u003c\u003cwarning: pattern \"all\" matched no module dependencies\n\u003e\u003e\n"}


[Info  - 10:55:12 AM] 17.254743ms for GOROOT=/usr/local/Cellar/go/1.12.7/libexec GOPATH=/Users/sebastianmalton/go GO111MODULE=on PWD=/Users/sebastianmalton/repos go "list" "-e" "-json" "-compiled=true" "-test=true" "-export=false" "-deps=true" "-find=false" "--" "/Users/sebastianmalton/repos/cnt/services/socket", stderr: <<go: cannot find main module; see 'go help modules'
>>

[Trace - 10:55:12 AM] Received notification 'window/logMessage' in 0ms.
Params: {"type":3,"message":"17.254743ms for GOROOT=/usr/local/Cellar/go/1.12.7/libexec GOPATH=/Users/sebastianmalton/go GO111MODULE=on PWD=/Users/sebastianmalton/repos go \"list\" \"-e\" \"-json\" \"-compiled=true\" \"-test=true\" \"-export=false\" \"-deps=true\" \"-find=false\" \"--\" \"/Users/sebastianmalton/repos/cnt/services/socket\", stderr: \u003c\u003cgo: cannot find main module; see 'go help modules'\n\u003e\u003e\n"}


[Trace - 10:55:12 AM] Received response 'textDocument/codeAction - (44)' in 0ms.
Params: {}


[Trace - 10:55:12 AM] Sending notification 'textDocument/codeAction' in 1503ms.
Params: {"textDocument":{"uri":"file:///Users/sebastianmalton/repos/cnt/services/socket/agent_test.go"},"range":{"start":{"line":0,"character":0},"end":{"line":0,"character":0}},"context":{"diagnostics":[]}}


[Trace - 10:55:12 AM] Received notification 'window/logMessage' in 0ms.
Params: {"type":3,"message":"682.676715ms for GOROOT=/usr/local/Cellar/go/1.12.7/libexec GOPATH=/Users/sebastianmalton/go GO111MODULE=on PWD=/Users/sebastianmalton/repos go \"list\" \"-e\" \"-json\" \"-compiled=true\" \"-test=true\" \"-export=false\" \"-deps=true\" \"-find=false\" \"--\" \"/Users/sebastianmalton/repos/cnt/services/socket/agent_test.go\", stderr: \u003c\u003c\u003e\u003e\n"}


[Error - 10:55:12 AM] Request textDocument/codeAction failed.
  Message: go/packages.Load: no packages found for /Users/sebastianmalton/repos/cnt/services/socket/agent_test.go
  Code: 0 
[Info  - 10:55:12 AM] 682.676715ms for GOROOT=/usr/local/Cellar/go/1.12.7/libexec GOPATH=/Users/sebastianmalton/go GO111MODULE=on PWD=/Users/sebastianmalton/repos go "list" "-e" "-json" "-compiled=true" "-test=true" "-export=false" "-deps=true" "-find=false" "--" "/Users/sebastianmalton/repos/cnt/services/socket/agent_test.go", stderr: <<>>

[Info  - 10:55:12 AM] 19.94865ms for GOROOT=/usr/local/Cellar/go/1.12.7/libexec GOPATH=/Users/sebastianmalton/go GO111MODULE=on PWD=/Users/sebastianmalton/repos go "env" "GOMOD", stderr: <<>>

[Trace - 10:55:12 AM] Received notification 'window/logMessage' in 0ms.
Params: {"type":3,"message":"19.94865ms for GOROOT=/usr/local/Cellar/go/1.12.7/libexec GOPATH=/Users/sebastianmalton/go GO111MODULE=on PWD=/Users/sebastianmalton/repos go \"env\" \"GOMOD\", stderr: \u003c\u003c\u003e\u003e\n"}


[Info  - 10:55:12 AM] 26.64683ms for GOROOT=/usr/local/Cellar/go/1.12.7/libexec GOPATH=/Users/sebastianmalton/go GO111MODULE=on PWD=/Users/sebastianmalton/repos go "list" "-m" "-json" "all", stderr: <<warning: pattern "all" matched no module dependencies
>>

[Trace - 10:55:12 AM] Received notification 'window/logMessage' in 0ms.
Params: {"type":3,"message":"26.64683ms for GOROOT=/usr/local/Cellar/go/1.12.7/libexec GOPATH=/Users/sebastianmalton/go GO111MODULE=on PWD=/Users/sebastianmalton/repos go \"list\" \"-m\" \"-json\" \"all\", stderr: \u003c\u003cwarning: pattern \"all\" matched no module dependencies\n\u003e\u003e\n"}


[Info  - 10:55:12 AM] 15.922659ms for GOROOT=/usr/local/Cellar/go/1.12.7/libexec GOPATH=/Users/sebastianmalton/go GO111MODULE=on PWD=/Users/sebastianmalton/repos go "list" "-e" "-json" "-compiled=true" "-test=true" "-export=false" "-deps=true" "-find=false" "--" "/Users/sebastianmalton/repos/cnt/services/socket", stderr: <<go: cannot find main module; see 'go help modules'
>>

[Trace - 10:55:12 AM] Received notification 'window/logMessage' in 0ms.
Params: {"type":3,"message":"15.922659ms for GOROOT=/usr/local/Cellar/go/1.12.7/libexec GOPATH=/Users/sebastianmalton/go GO111MODULE=on PWD=/Users/sebastianmalton/repos go \"list\" \"-e\" \"-json\" \"-compiled=true\" \"-test=true\" \"-export=false\" \"-deps=true\" \"-find=false\" \"--\" \"/Users/sebastianmalton/repos/cnt/services/socket\", stderr: \u003c\u003cgo: cannot find main module; see 'go help modules'\n\u003e\u003e\n"}


[Trace - 10:55:13 AM] Received response 'textDocument/codeAction - (45)' in 0ms.
Params: {}


[Trace - 10:55:13 AM] Sending notification 'textDocument/codeAction' in 1950ms.
Params: {"textDocument":{"uri":"file:///Users/sebastianmalton/repos/cnt/services/socket/agent_test.go"},"range":{"start":{"line":21,"character":2},"end":{"line":21,"character":2}},"context":{"diagnostics":[]}}


[Trace - 10:55:13 AM] Sending notification '$/cancelRequest' in 1950ms.
Params: {"id":44}


[Trace - 10:55:13 AM] Received notification 'window/logMessage' in 0ms.
Params: {"type":3,"message":"637.683088ms for GOROOT=/usr/local/Cellar/go/1.12.7/libexec GOPATH=/Users/sebastianmalton/go GO111MODULE=on PWD=/Users/sebastianmalton/repos go \"list\" \"-e\" \"-json\" \"-compiled=true\" \"-test=true\" \"-export=false\" \"-deps=true\" \"-find=false\" \"--\" \"/Users/sebastianmalton/repos/cnt/services/socket/agent_test.go\", stderr: \u003c\u003c\u003e\u003e\n"}


[Error - 10:55:13 AM] Request textDocument/codeAction failed.
  Message: go/packages.Load: no packages found for /Users/sebastianmalton/repos/cnt/services/socket/agent_test.go
  Code: 0 
[Info  - 10:55:13 AM] 637.683088ms for GOROOT=/usr/local/Cellar/go/1.12.7/libexec GOPATH=/Users/sebastianmalton/go GO111MODULE=on PWD=/Users/sebastianmalton/repos go "list" "-e" "-json" "-compiled=true" "-test=true" "-export=false" "-deps=true" "-find=false" "--" "/Users/sebastianmalton/repos/cnt/services/socket/agent_test.go", stderr: <<>>

@Nokel81

This comment has been minimized.

Copy link
Author

@Nokel81 Nokel81 commented Aug 19, 2019

I tried reboot my computer (which didn't work) but then I just created a new workspace from scratch and it did work. So I would say that a fresh workspace after turning on GO111MODULES was the fix

@Nokel81 Nokel81 closed this Aug 19, 2019
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.