gopls version

Today,we can find all the references of a variable.

But I want to find the write references only.

How to do that?

Will gopls add a support to this?

var a int

// write 1
a = 1

// read 1
_ = a

// read 2
b := a

// write 2
a = 2

I want to find references to list:

a = 1
a = 2

go env

go env
AR='ar'
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GOAMD64='v1'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN='/home/jd/go/bin'
GOCACHE='/home/jd/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/jd/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build4068807655=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD=''
GOMODCACHE=''
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/jd/go'
GOPRIVATE=''
GOPROXY='https://goproxy.io,https://goproxy.cn,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/jd/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.24.3'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

find write references of a variable.

What did you see happen?

all references will list.

What did you expect to see?

only write references.

Editor and settings

No response

Logs

No response

Comment From: findleyr

I want this feature so badly!

In fact, this is the largest reason why we filed https://github.com/microsoft/language-server-protocol/issues/1911. Unfortunately, it seems to be getting no traction.

We can't do this in LSP, which means it would have to be a custom command and every client would need to implement their own logic. Nevertheless, leaving this open as a wish list item.