gopls version

golang.org/x/tools/gopls v0.18.1

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.22.12'
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-build4148190690=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

I use vocode with gopls to read kubernetes code,there are some replace pkg in go mod,and when i to find some function which define,it also redirect the vendor code but not the replaced pkg.If i need change some code,i also to find the realy replaced pkg which the function to be defined.

Image

What did you see happen?

such as this because the code is replaced to staging code in the go mod file,but when i use gopls,it redirect to vendor code but the really staging code.If i need change the code something,i need to also to get the really place in the staging.

Image in go mod file,the picture pkg is replaced to staging pkg code,but the gopls is not correct redircet.

Image

the picture code really pkg is staging file.

Image

Image

What did you expect to see?

I expect when some pkg to be replaced local pkg,can gopls support jumping to the actual code location after replaced by local code pkg.

Editor and settings

No response

Logs

No response

Comment From: gabyhelp

Related Issues

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

Comment From: madelinekalil

Can you please run go list -m -f={{.Dir}} for one of the modules that you have a replace directive for and see what the output is?

Comment From: hedongyouxia

@madelinekalil I do this with your suggestion,and it show the origin pkg but not the replaced pkg.eg:

Image

Comment From: madelinekalil

Sorry, the exact command you should run is go list -m -f={{.Dir}} k8s.io/client-go (or replace k8s.io/client-go with another module you have a replace directive for.) The -f={{.Dir}} is formatting the output and should not be modified.

Comment From: hedongyouxia

@madelinekalil I do it again,and it show as follows:

Image

Comment From: madelinekalil

Oops, it should be "client-go" instead of "client.go". If go list cannot find this module then it will explain why the go to definition is not finding the replaced version of the module.

Comment From: hedongyouxia

@madelinekalil I apologize for the repeated error and I am very grateful for your patient explanation. I re-executed go list and compared the changes before and after the setting -mod=mod, and the output content is as follows:

Image According to the results in the picture, only the go list after setting -mod=mod will output the real replaced module, but if we use gopls to find the reference of a function at this time, many things will be missing.I example it at the issues what happend with set -mod=mod

Comment From: jba

/cc @matloob