Skip to content

gopls: could not import package and variable detection in same package stopped working #996

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

Closed
TheDhejavu opened this issue Dec 3, 2020 · 10 comments
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@TheDhejavu
Copy link

TheDhejavu commented Dec 3, 2020

What version of Go, VS Code & VS Code Go extension are you using?

  • Run go version to get version of Go
    • go version go1.15.5 darwin/amd64
  • Run gopls -v version to get version of Gopls if you are using the language server.
    • golang.org/x/tools/gopls v0.5.4
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders
    • 1.51.1
  • Check your installed extensions to get the version of the VS Code Go extension
    • 0.19.0
  • Run go env to get the go development environment details

GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/ayodeji/Library/Caches/go-build"
GOENV="/Users/ayodeji/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/ayodeji/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/ayodeji/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/opt/go/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/opt/go/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/ayodeji/go/src/github.com/workspace/simple-bank/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/yq/s2hqwwn519z_lgl7mqr_496c0000gn/T/go-build473978771=/tmp/go-build -gno-record-gcc-switches -fno-common"

Share the Go related settings you have added/edited

Run Preferences: Open Settings (JSON) command to open your settings.json file.
Share all the settings with the go. or ["go"] or gopls prefixes.

{
   "go.autocompleteUnimportedPackages": true,
"go.useLanguageServer": true,
"go.formatTool": "goimports",
"[go]": {
    "editor.formatOnSave": true,
    "editor.codeActionsOnSave": {
        "source.organizeImports": true,
    },
    // Optional: Disable snippets, as they conflict with completion ranking.
    "editor.snippetSuggestions": "none",
},
"[go.mod]": {
    "editor.formatOnSave": true,
    "editor.codeActionsOnSave": {
        "source.organizeImports": true,
    },
},
  }

Screenshots or recordings

If applicable, add screenshots or recordings to help explain your problem.
Screenshot 2020-12-03 at 1 08 35 PM
Screenshot 2020-12-03 at 1 09 28 PM

@TheDhejavu TheDhejavu changed the title could not import package and variable detection in same package stopped working gopls: could not import package and variable detection in same package stopped working Dec 3, 2020
@hyangah
Copy link
Contributor

hyangah commented Dec 3, 2020

@TheDhejavu thanks for reporting an issue. Did you open the editor from the directory where go.mod file is? Currently the language server requires to open the directory (workspace root) where the corresponding go.mod file is located #275 (comment) In your case, it looks like the workspace root should be simple-bank directory.

If opening from the directory doesn't fix the problem, please share the gopls trace. https://github.com/golang/tools/blob/master/gopls/doc/troubleshooting.md#vs-code

@hyangah hyangah added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Dec 3, 2020
@TheDhejavu
Copy link
Author

TheDhejavu commented Dec 3, 2020

@hyangah i opened the project from the root. Here is the tracer for golps

[Info  - 2:44:47 PM] 2020/12/03 14:44:47 go env for /Users/ayodeji/go/src/github.com/workspace/simple-bank
(root /Users/ayodeji/go/src/github.com/workspace/simple-bank)
(go version go version go1.15.5 darwin/amd64)
(valid build configuration = true)
(build flags: [])
GOMOD=/Users/ayodeji/go/src/github.com/workspace/simple-bank/go.mod
GOPROXY=https://proxy.golang.org,direct
GOSUMDB=sum.golang.org
GOCACHE=/Users/ayodeji/Library/Caches/go-build
GOMODCACHE=/Users/ayodeji/go/pkg/mod
GOPATH=/Users/ayodeji/go
GO111MODULE=
GOFLAGS=
GOINSECURE=
GONOSUMDB=
GOROOT=/usr/local/opt/go/libexec
GONOPROXY=
GOPRIVATE=


[Error - 2:44:47 PM] 2020/12/03 14:44:47 go/packages.Load: go [-e -json -compiled=true -test=true -export=false -deps=true -find=false -- builtin github.com/workspace/simple-bank/...]: exit status 1: open /Users/ayodeji/Library/Caches/go-build/76/76f1b07ead1a0346b7fa6859db4aeac3cda03a63af9b7d7a58e4c990224ccdd4-d: permission denied

	snapshot=0
	directory=/Users/ayodeji/go/src/github.com/workspace/simple-bank
	query=[builtin github.com/workspace/simple-bank/...]
	packages=0

[Error - 2:44:47 PM] 2020/12/03 14:44:47 initial workspace load failed: source error list:
	file:///Users/ayodeji/go/src/github.com/workspace/simple-bank/go.mod:0:0-0:39: go [-e -json -compiled=true -test=true -export=false -deps=true -find=false -- builtin github.com/workspace/simple-bank/...]: exit status 1: open /Users/ayodeji/Library/Caches/go-build/76/76f1b07ead1a0346b7fa6859db4aeac3cda03a63af9b7d7a58e4c990224ccdd4-d: permission denied


[Error - 2:44:47 PM] 2020/12/03 14:44:47 warning: diagnose go.mod: source error list:
	file:///Users/ayodeji/go/src/github.com/workspace/simple-bank/go.mod:0:0-0:39: go [-e -json -compiled=true -test=true -export=false -deps=true -find=false -- builtin github.com/workspace/simple-bank/...]: exit status 1: open /Users/ayodeji/Library/Caches/go-build/76/76f1b07ead1a0346b7fa6859db4aeac3cda03a63af9b7d7a58e4c990224ccdd4-d: permission denied

	directory=/Users/ayodeji/go/src/github.com/workspace/simple-bank
	snapshot=0

[Error - 2:44:47 PM] 2020/12/03 14:44:47 errors diagnosing workspace: source error list:
	file:///Users/ayodeji/go/src/github.com/workspace/simple-bank/go.mod:0:0-0:39: go [-e -json -compiled=true -test=true -export=false -deps=true -find=false -- builtin github.com/workspace/simple-bank/...]: exit status 1: open /Users/ayodeji/Library/Caches/go-build/76/76f1b07ead1a0346b7fa6859db4aeac3cda03a63af9b7d7a58e4c990224ccdd4-d: permission denied

	snapshot=0
	directory=file:///Users/ayodeji/go/src/github.com/workspace/simple-bank

[Error - 2:45:21 PM] 2020/12/03 14:45:21 go/packages.Load: go [-e -json -compiled=true -test=true -export=false -deps=true -find=false -- builtin github.com/workspace/simple-bank/...]: exit status 1: open /Users/ayodeji/Library/Caches/go-build/76/76f1b07ead1a0346b7fa6859db4aeac3cda03a63af9b7d7a58e4c990224ccdd4-d: permission denied

	snapshot=1
	directory=/Users/ayodeji/go/src/github.com/workspace/simple-bank
	query=[builtin github.com/workspace/simple-bank/...]
	packages=0

[Error - 2:45:21 PM] 2020/12/03 14:45:21 initial workspace load failed: source error list:
	file:///Users/ayodeji/go/src/github.com/workspace/simple-bank/go.mod:0:0-0:39: go [-e -json -compiled=true -test=true -export=false -deps=true -find=false -- builtin github.com/workspace/simple-bank/...]: exit status 1: open /Users/ayodeji/Library/Caches/go-build/76/76f1b07ead1a0346b7fa6859db4aeac3cda03a63af9b7d7a58e4c990224ccdd4-d: permission denied


[Error - 2:45:21 PM] Request textDocument/codeAction failed.
Message: source error list:
	file:///Users/ayodeji/go/src/github.com/workspace/simple-bank/go.mod:0:0-0:39: go [-e -json -compiled=true -test=true -export=false -deps=true -find=false -- builtin github.com/workspace/simple-bank/...]: exit status 1: open /Users/ayodeji/Library/Caches/go-build/76/76f1b07ead1a0346b7fa6859db4aeac3cda03a63af9b7d7a58e4c990224ccdd4-d: permission denied

Code: 0 
[Error - 2:45:21 PM] 2020/12/03 14:45:21 warning: diagnose go.mod: source error list:
	file:///Users/ayodeji/go/src/github.com/workspace/simple-bank/go.mod:0:0-0:39: go [-e -json -compiled=true -test=true -export=false -deps=true -find=false -- builtin github.com/workspace/simple-bank/...]: exit status 1: open /Users/ayodeji/Library/Caches/go-build/76/76f1b07ead1a0346b7fa6859db4aeac3cda03a63af9b7d7a58e4c990224ccdd4-d: permission denied

	directory=/Users/ayodeji/go/src/github.com/workspace/simple-bank
	snapshot=1

[Error - 2:45:21 PM] 2020/12/03 14:45:21 errors diagnosing workspace: source error list:
	file:///Users/ayodeji/go/src/github.com/workspace/simple-bank/go.mod:0:0-0:39: go [-e -json -compiled=true -test=true -export=false -deps=true -find=false -- builtin github.com/workspace/simple-bank/...]: exit status 1: open /Users/ayodeji/Library/Caches/go-build/76/76f1b07ead1a0346b7fa6859db4aeac3cda03a63af9b7d7a58e4c990224ccdd4-d: permission denied

	snapshot=1
	directory=file:///Users/ayodeji/go/src/github.com/workspace/simple-bank

[Error - 2:45:23 PM] Request textDocument/codeAction failed.
Message: source error list:
	file:///Users/ayodeji/go/src/github.com/workspace/simple-bank/go.mod:0:0-0:39: go [-e -json -compiled=true -test=true -export=false -deps=true -find=false -- builtin github.com/workspace/simple-bank/...]: exit status 1: open /Users/ayodeji/Library/Caches/go-build/76/76f1b07ead1a0346b7fa6859db4aeac3cda03a63af9b7d7a58e4c990224ccdd4-d: permission denied

Code: 0 
[Error - 2:45:48 PM] 2020/12/03 14:45:48 go/packages.Load: go [-e -json -compiled=true -test=true -export=false -deps=true -find=false -- builtin github.com/workspace/simple-bank/...]: exit status 1: open /Users/ayodeji/Library/Caches/go-build/76/76f1b07ead1a0346b7fa6859db4aeac3cda03a63af9b7d7a58e4c990224ccdd4-d: permission denied

	snapshot=2
	directory=/Users/ayodeji/go/src/github.com/workspace/simple-bank
	query=[builtin github.com/workspace/simple-bank/...]
	packages=0

[Error - 2:45:48 PM] 2020/12/03 14:45:48 warning: diagnose go.mod: source error list:
	file:///Users/ayodeji/go/src/github.com/workspace/simple-bank/go.mod:0:0-0:39: go [-e -json -compiled=true -test=true -export=false -deps=true -find=false -- builtin github.com/workspace/simple-bank/...]: exit status 1: open /Users/ayodeji/Library/Caches/go-build/76/76f1b07ead1a0346b7fa6859db4aeac3cda03a63af9b7d7a58e4c990224ccdd4-d: permission denied

	directory=/Users/ayodeji/go/src/github.com/workspace/simple-bank
	snapshot=2

[Error - 2:45:48 PM] 2020/12/03 14:45:48 initial workspace load failed: source error list:
	file:///Users/ayodeji/go/src/github.com/workspace/simple-bank/go.mod:0:0-0:39: go [-e -json -compiled=true -test=true -export=false -deps=true -find=false -- builtin github.com/workspace/simple-bank/...]: exit status 1: open /Users/ayodeji/Library/Caches/go-build/76/76f1b07ead1a0346b7fa6859db4aeac3cda03a63af9b7d7a58e4c990224ccdd4-d: permission denied


[Error - 2:45:48 PM] 2020/12/03 14:45:48 errors diagnosing workspace: source error list:
	file:///Users/ayodeji/go/src/github.com/workspace/simple-bank/go.mod:0:0-0:39: go [-e -json -compiled=true -test=true -export=false -deps=true -find=false -- builtin github.com/workspace/simple-bank/...]: exit status 1: open /Users/ayodeji/Library/Caches/go-build/76/76f1b07ead1a0346b7fa6859db4aeac3cda03a63af9b7d7a58e4c990224ccdd4-d: permission denied

	snapshot=2
	directory=file:///Users/ayodeji/go/src/github.com/workspace/simple-bank

[Info  - 2:45:48 PM] 2020/12/03 14:45:48 go/packages.Load
	snapshot=3
	package_path="/Users/ayodeji/go/src/github.com/workspace/simple-bank/db/sqlc/account_test.go"
	files=[/Users/ayodeji/go/src/github.com/workspace/simple-bank/db/sqlc/account_test.go]

[Info  - 2:45:48 PM] 2020/12/03 14:45:48 go/packages.Load
	snapshot=3
	directory=/Users/ayodeji/go/src/github.com/workspace/simple-bank
	query=[file=/Users/ayodeji/go/src/github.com/workspace/simple-bank/db/sqlc/account_test.go]
	packages=1

[Info  - 2:45:48 PM] 2020/12/03 14:45:48 go/packages.Load
	snapshot=3
	package_path="/Users/ayodeji/go/src/github.com/workspace/simple-bank/db/sqlc/account_test.go"
	files=[/Users/ayodeji/go/src/github.com/workspace/simple-bank/db/sqlc/account_test.go]

[Info  - 2:45:48 PM] 2020/12/03 14:45:48 go/packages.Load
	snapshot=3
	directory=/Users/ayodeji/go/src/github.com/workspace/simple-bank
	query=[file=/Users/ayodeji/go/src/github.com/workspace/simple-bank/db/sqlc/account_test.go]
	packages=1

@hyangah
Copy link
Contributor

hyangah commented Dec 3, 2020

@TheDhejavu Thanks for the trace. Looks like go commands encountered permission issues.

file:///Users/ayodeji/go/src/github.com/workspace/simple-bank/go.mod:0:0-0:39: go [-e -json -compiled=true -test=true -export=false -deps=true -find=false -- builtin github.com/workspace/simple-bank/...]: exit status 1: open /Users/ayodeji/Library/Caches/go-build/76/76f1b07ead1a0346b7fa6859db4aeac3cda03a63af9b7d7a58e4c990224ccdd4-d: permission denied

Can you try to clear the build cache (go build -cache) and see if it helps?

@TheDhejavu
Copy link
Author

TheDhejavu commented Dec 3, 2020

@hyangah thanks, go build -cache didn't work but I tried sudo go clean -cache -modcache -i -r and it works.

@hyangah
Copy link
Contributor

hyangah commented Dec 3, 2020

@TheDhejavu Glad to hear that the problem is resolved.

@stamblerre I will leave this open for you to see. Is there any planned work to surface this type of errors in a different way from gopls side? Feel free to close this issue.
As part of CL/274449 work, the language client will be configured to reveal the gopls output channel in case of errors, and I hope this helps.

@riccardomanfrin
Copy link

I kind of had same issue.. the initial comment by @hyangah in my case was enlightening. I was generating some OpenAPI code which among the many things also placed a main.go and go.mod file in some nested folder. This was ruining the day to VSCode.

@hyangah
Copy link
Contributor

hyangah commented Dec 3, 2020

@riccardomanfrin Yeah, a typical "the-same-symptom-many-different-reasons" problem. We need a better error reporting and troubleshooting story.

@stamblerre
Copy link
Contributor

@stamblerre I will leave this open for you to see. Is there any planned work to surface this type of errors in a different way from gopls side? Feel free to close this issue.

The error should've showed up in the status bar at the bottom of the screen. @TheDhejavu did you see the pop-up or was it not noticeable?

@TheDhejavu
Copy link
Author

Hi @stamblerre, I didn't notice any pop-up message.

@stamblerre
Copy link
Contributor

Thanks for following up, @TheDhejavu. It's unfortunate that an error message didn't appear, but it's difficult to test this exact scenario. I do think an error message will pop-up with the new logic in v0.6.0. I'm going to close this issue as a result.

@golang golang locked and limited conversation to collaborators Dec 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

5 participants