Skip to content

x/tools/gopls: can't find definition using -mod=mod #73492

Open
@hedongyouxia

Description

@hedongyouxia

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    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

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions