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: Error due to trying to respect transient replace #44622

Closed
alvaroaleman opened this issue Feb 25, 2021 · 4 comments
Closed

x/tools/gopls: Error due to trying to respect transient replace #44622

alvaroaleman opened this issue Feb 25, 2021 · 4 comments

Comments

@alvaroaleman
Copy link

@alvaroaleman alvaroaleman commented Feb 25, 2021

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

$ go version
go version go1.16 linux/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
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/alvaro/.gocache"
GOENV="/home/alvaro/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/alvaro/git/golang/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/alvaro/git/golang"
GOPRIVATE=""
GOPROXY="direct"
GOROOT="/usr/local/go"
GOSUMDB="off"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.16"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/alvaro/git/golang/src/github.com/hashicorp/vault/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-build1791460678=/tmp/go-build -gno-record-gcc-switches"
$ gopls version
golang.org/x/tools/gopls v0.6.6
    golang.org/x/tools/gopls@v0.6.6 h1:GmCsAKZMEb1BD1BTWnQrMyx4FmNThlEsmuFiJbLBXio=

What did you do?

I have a go project that imports "github.com/hashicorp/vault/api". That module in turn depends on github.com/hashicorp/vault/sdk but replaces it: github.com/hashicorp/vault/sdk => ../sdk

This seems to break the gopls completion, it throws errors like this:

[Error - Received] 16:00:45.865 PM #5 err: exit status 1: stderr: go: github.com/hashicorp/vault/sdk@v0.1.14-0.20200519221530-14615acda45f (replaced by ../sdk): reading ../sdk/go.mod: open /home/alvaro/git/golang/src/github.com/openshift/ci-tools/vendor/github.com/hashicorp/vault/sdk/go.mod: no such file or directory
: packages.Load error

To my understanding, a replace should never get propagated. In this case it appears that happens for gopls, because my own project does not have this replace:

$ rg vault go.mod 
37:	github.com/hashicorp/vault/api v1.0.5-0.20200519221902-385fac77e20f
38:	github.com/hashicorp/vault/sdk v0.1.14-0.20200519221838-e0cfd64bc267

Project building and testing works fine, so this issue appears to be specific to gopls

What did you expect to see?

gopls to ignore the transient replace directive and not throwing an error when accessing objects in there

What did you see instead?

@gopherbot gopherbot added this to the Unreleased milestone Feb 25, 2021
@heschi
Copy link
Contributor

@heschi heschi commented Feb 25, 2021

Do you have experimentalWorkspaceModule enabled, or any other unusual flags set in your settings? Please follow the instructions at https://github.com/golang/vscode-go/blob/master/docs/troubleshooting.md#collect-gopls-information for VS Code to generate a log file and collect settings.

A repro would also be helpful. If you're working on github.com/openshift/ci-tools, I tried opening that project and it seemed to go fine with default gopls settings.

@alvaroaleman
Copy link
Author

@alvaroaleman alvaroaleman commented Feb 25, 2021

@heschik doesn't happen on master, but here: openshift/ci-tools@c50dc4e

I don't have any special settings. I do not use vscode but vim-go/coc.nvim:

$ ps xf|rg gopls|rg -v rg
3392140 ?        Sl     0:00  |       |   \_ gopls -remote=auto -logfile=auto -debug=:0 -remote.debug=:0 -rpc.trace
3392085 ?        Ssl    0:00  |       \_ /home/alvaro/git/golang/bin/gopls -remote=auto -logfile=auto -debug=:0 -remote.debug=:0 -rpc.trace
3392126 ?        Ssl    0:21  |           \_ /home/alvaro/git/golang/bin/gopls serve -listen unix;/run/user/1000/gopls-d12775-daemon.alvaro -listen.timeout 1m0s -debug :

Logs:

The error are in the second log towards the end go/packages.Load: err: exit status 1: stderr: go:[...]

@heschi
Copy link
Contributor

@heschi heschi commented Feb 25, 2021

Thanks for the logs. It appears that when you jumped to definition on a type in the vault module, your editor added that folder as a workspace root:

[Trace - 17:58:55.290 PM] Received response 'textDocument/definition - (3)' in 480ms.
Result: [{"uri":"file:///home/alvaro/git/golang/src/github.com/openshift/ci-tools/vendor/github.com/hashicorp/vault/api/sys_auth.go","range":{"start":{"line":76,"character":5},"end":{"line":76,"character":22}}}]


[Trace - 17:58:55.336 PM] Sending notification 'workspace/didChangeWorkspaceFolders'.
Params: {"event":{"added":[{"uri":"file:///home/alvaro/git/golang/src/github.com/openshift/ci-tools/vendor/github.com/hashicorp/vault/api","name":"/home/alvaro/git/golang/src/github.com/openshift/ci-tools/vendor/github.com/hashicorp/vault/api"}],"removed":[]}}

At that point I think gopls is working as intended, though I could be wrong. I don't know enough about vim to tell you how to avoid this behavior. @findleyr might.

@alvaroaleman
Copy link
Author

@alvaroaleman alvaroaleman commented Feb 26, 2021

It appears this is vim-go. I didn't intend to use the vim-go lsp integration in the first place, I only have it for the highlighting and coc-nvim for the lsp integration. The latter doesn't have any issues with this.

Thanks a lot for your help!

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