Skip to content

x/tools/gopls: go to definition should go to replaced version of module #73545

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

Open
hedongyouxia opened this issue Apr 30, 2025 · 7 comments
Open
Labels
FeatureRequest Issues asking for a new feature that does not need a proposal. gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@hedongyouxia
Copy link

hedongyouxia commented Apr 30, 2025

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

@hedongyouxia hedongyouxia added gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. labels Apr 30, 2025
@gopherbot gopherbot added this to the Unreleased milestone Apr 30, 2025
@seankhliao seankhliao changed the title x/tools/gopls: can support really pkg redirect x/tools/gopls: go to definition should go to replaced version of module Apr 30, 2025
@gabyhelp gabyhelp added the FeatureRequest Issues asking for a new feature that does not need a proposal. label Apr 30, 2025
@madelinekalil
Copy link

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?

@madelinekalil madelinekalil added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label May 8, 2025
@hedongyouxia
Copy link
Author

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

Image

@madelinekalil
Copy link

madelinekalil commented May 9, 2025

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.

@hedongyouxia
Copy link
Author

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

Image

@madelinekalil
Copy link

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.

@hedongyouxia
Copy link
Author

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FeatureRequest Issues asking for a new feature that does not need a proposal. gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants