Skip to content

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

Open
@hedongyouxia

Description

@hedongyouxia

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

Activity

added
goplsIssues related to the Go language server, gopls.
ToolsThis label describes issues relating to any tools in the x/tools repository.
on Apr 30, 2025
added this to the Unreleased milestone on Apr 30, 2025
changed the title [-]x/tools/gopls: can support really pkg redirect[/-] [+]x/tools/gopls: go to definition should go to replaced version of module[/+] on Apr 30, 2025
added
FeatureRequestIssues asking for a new feature that does not need a proposal.
on Apr 30, 2025
madelinekalil

madelinekalil commented on May 8, 2025

@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?

added
WaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.
on May 8, 2025
hedongyouxia

hedongyouxia commented on May 9, 2025

@hedongyouxia
Author

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

Image
madelinekalil

madelinekalil commented on May 9, 2025

@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.

hedongyouxia

hedongyouxia commented on May 9, 2025

@hedongyouxia
Author

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

Image
madelinekalil

madelinekalil commented on May 9, 2025

@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.

hedongyouxia

hedongyouxia commented on May 10, 2025

@hedongyouxia
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
added
NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
and removed
WaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.
on May 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureRequestIssues asking for a new feature that does not need a proposal.NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.ToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @gopherbot@seankhliao@hedongyouxia@madelinekalil@gabyhelp

        Issue actions

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