gopls version
Build info
----------
golang.org/x/tools/gopls v0.18.1
golang.org/x/tools/gopls@v0.18.1 h1:2xJBNzdImS5u/kV/ZzqDLSvlBSeZX+pWY9uKVP7Pask=
github.com/BurntSushi/toml@v1.4.1-0.20240526193622-a339e1f7089c h1:pxW6RcqyfI9/kWtOwnv/G+AzdKuy2ZrqINhenH4HyNs=
github.com/google/go-cmp@v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
golang.org/x/exp/typeparams@v0.0.0-20241210194714-1829a127f884 h1:1xaZTydL5Gsg78QharTwKfA9FY9CZ1VQj6D/AZEvHR0=
golang.org/x/mod@v0.23.0 h1:Zb7khfcRGKk+kqfxFaP5tZqCnDZMjC5VtUBs87Hr6QM=
golang.org/x/sync@v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w=
golang.org/x/telemetry@v0.0.0-20241220003058-cc96b6e0d3d9 h1:L2k9GUV2TpQKVRGMjN94qfUMgUwOFimSQ6gipyJIjKw=
golang.org/x/text@v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM=
golang.org/x/tools@v0.30.1-0.20250221230316-5055f70f240c h1:Ja/5gV5a9Vvho3p2NC/T2TtxhHjrWS/2DvCKMvA0a+Y=
golang.org/x/vuln@v1.1.3 h1:NPGnvPOTgnjBc9HTaUx+nj+EaUYxl5SJOWqaDYGaFYw=
honnef.co/go/tools@v0.5.1 h1:4bH5o3b5ZULQ4UrBmP+63W9r7qIkqJClEA9ko5YKx+I=
mvdan.cc/gofumpt@v0.7.0 h1:bg91ttqXmi9y2xawvkuMXyvAA/1ZGJqYAEGjXuP0JXU=
mvdan.cc/xurls/v2@v2.5.0 h1:lyBNOm8Wo71UknhUs4QTFUNNMyxy2JEIaKKo0RWOh+8=
go: go1.24.0
go env
[mateusz@arch ~ ]$ 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/mateusz/go/bin'
GOCACHE='/home/mateusz/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/mateusz/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build2202034690=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/dev/null'
GOMODCACHE='/home/mateusz/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/mateusz/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/lib/go'
GOSUMDB='sum.golang.org'
GOTELEMETRY='on'
GOTELEMETRYDIR='/home/mateusz/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/lib/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.24.2'
GOWORK=''
PKG_CONFIG='pkg-config'
What did you do?
package main
type someStruct struct {
field int
}
func main() {
a := someStruct{1}
a = someStruct{field: 1}
_ = a
}
Go to References of someStruct.field
What did you see happen?
Only someStruct{field: 1}
returned.
What did you expect to see?
Both someStruct{1}
, someStruct{field: 1}
Editor and settings
No response
Logs
No response
Comment From: adonovan
The feature is working as intended. A References query reports each identifier in the source that refers to the symbol of interest; but there is no identifier in an unkeyed struct literal. The literal is effectively an implicit reference, and it's not the only place in the language where there's an implicit reference, for example x.z is effectively x.y.z if y is an embedded field.
However, I do think that "References, including implicit ones" would be a useful query for gopls to implement. The main obstacle is that the LSP doesn't provide a way for a server to express that a particular query result should be treated in the client UI exactly like a References query. I can think of many other useful queries that would fit within this schema--see https://github.com/microsoft/language-server-protocol/issues/1911 for eight of them. Technically it would be easy to implement this, but it does require a change to the protocol and to all clients.
Comment From: mateusz834
I see, if this was implemented i would surely use this mode instead of the default one, this is why i considered this as a kind-of bug. In my case i just have been debugging in the wrong direction, because go to references did not include such literals in the result. Then i for some reason looked at references of the struct and the bug was clear (because it shown me the unkeyed literals).
Comment From: findleyr
I'd also use this as the default mode.
I wonder how bad it would be to just implement it.
We already show indirect references through interface satisfaction. Technically, those AREN'T references to the symbol. They are references to another symbol that has the same name, but it's a different symbol.