gopls version

Image

go env

GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/didi/Library/Caches/go-build'
GOENV='/Users/didi/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/didi/WorkSpace/gopath/pkg/mod'
GONOPROXY='git.xiaojukeji.com'
GONOSUMDB='git.xiaojukeji.com'
GOOS='darwin'
GOPATH='/Users/didi/WorkSpace/gopath'
GOPRIVATE='git.xiaojukeji.com'
GOPROXY='https://goproxy.cn,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.21.7'
GCCGO='gccgo'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/v4/7ds055qn1v36dxgvzj88xxmh0000ks/T/go-build14232451=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

in my project i set "go.toolsEnvVars": { "GOFLAGS": "-mod=mod" } to fit the code can redirect staging file or vendor.in vendor file we can't change the code.

What did you see happen?

when i use vscode with gopls ready kubernetes code,there are some replace mod in go mod file, inorder to fit the editor can redirct right file, i set "go.toolsEnvVars": { "GOFLAGS": "-mod=mod" } in my editor. But when i find the struct or params reference us this,the gopls can't give right define or reference.

What did you expect to see?

I wan't when i set "go.toolsEnvVars": { "GOFLAGS": "-mod=mod" } in editors ,the gopls can give the right struct or params define and reference.

Editor and settings

vscode set "go.toolsEnvVars": { "GOFLAGS": "-mod=mod" }

Logs

No response

examples:

  1. At k8s code,there are more package is replaced by local staging in go mod file.

Image

  1. If i don't set the "go.toolsEnvVars": { "GOFLAGS": "-mod=mod" },the gopls will index with vendor,and need to update vendor dir,with this gopls can work success,but if i need change some code,i need to find the right code in staging file,because code in vendor change is not useful.

Image

Image i exec go mod vendor to update vendor dir and gopls will index the vendor code,it also support correct reference.It show have 50 reference for this struct filed.

Image

  1. but if i set "go.toolsEnvVars": { "GOFLAGS": "-mod=mod" },the gopls will index the really replace staging code,and it work failed,when i find the same struct filed reference,it only show 3 result.

Image when set -mod=mod ,gopls will redirect correct code with staging file .but find the struct filed reference ,it work bad.

Image

Comment From: hedongyouxia

@gopherbot Is the problem of this is already fit or support?Because i see it have been changed to unreleased,expect to your reply,thanks。

Comment From: findleyr

We don't support -mod=mod, because it means that the go command can mutate the go.mod and go.sum file when we run things like go list, and if we allow those types of side effects then it's too complicated (or impossible) to keep coherent state. See also https://go.dev/issue/65546.

But why do you need to set -mod=mod? Gopls should honor replace directives. Maybe you want to set -mod=readonly?

The short answer is: if go list ./... can find your packages, gopls should work.

Comment From: hedongyouxia

@findleyr I set -mod=mod is because when use vendor,gopls can not index the really pkg(staging,the pkg is replaced in go.mod)and i show this in examples。I also set the -mod=readonly with your suggestion,it not work,as same with set -mod=mod. your answer is go list ./... work good,the gopls will work. It useful for github pkg not local pkg replace,in kubernetes code,there are more pkg will be replaced local staging pkg. And i think it should be also support,because in some case , we should change the really staging pkg,but not vendor, in vendor it changed is not useful.

Image