gopls version
(Built from https://github.com/golang/tools/commit/95aad07923cb9d64eb951e4512c9e62bc3b8e275)
Build info
----------
golang.org/x/tools/gopls (devel)
golang.org/x/tools/gopls@(devel)
github.com/BurntSushi/toml@v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg=
github.com/fatih/camelcase@v1.0.0 h1:hxNvNX/xYBp0ovncs8WyWZrOrpBNub/JfaMvbURyft8=
github.com/fatih/gomodifytags@v1.17.1-0.20250423142747-f3939df9aa3c h1:dDSgAjoOMp8da3egfz0t2S+t8RGOpEmEXZubcGuc0Bg=
github.com/fatih/structtag@v1.2.0 h1:/OdNE99OxoI/PqaW/SuSK9uxxT3f/tcSZgon/ssNSx4=
github.com/fsnotify/fsnotify@v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=
github.com/google/go-cmp@v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
golang.org/x/exp/typeparams@v0.0.0-20250620022241-b7579e27df2b h1:KdrhdYPDUvJTvrDK9gdjfFd6JTk8vA1WJoldYSi0kHo=
golang.org/x/mod@v0.26.0 h1:EGMPT//Ezu+ylkCijjPc+f4Aih7sZvaAr+O3EHBxvZg=
golang.org/x/sync@v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw=
golang.org/x/sys@v0.34.0 h1:H5Y5sJ2L2JRdyv7ROF1he/lPdvFsd0mJHFw2ThKHxLA=
golang.org/x/telemetry@v0.0.0-20250710130107-8d8967aff50b h1:DU+gwOBXU+6bO0sEyO7o/NeMlxZxCZEvI7v+J4a1zRQ=
golang.org/x/text@v0.27.0 h1:4fGWRpyh641NLlecmyl4LOe6yDdfaYNrGb2zdfo4JV4=
golang.org/x/tools@v0.34.1-0.20250613162507-3f93fece84c7 => ../
golang.org/x/vuln@v1.1.4 h1:Ju8QsuyhX3Hk8ma3CesTbO8vfJD9EvUBgHvkxHBzj0I=
honnef.co/go/tools@v0.7.0-0.dev.0.20250523013057-bbc2f4dd71ea h1:fj8r9irJSpolAGUdZBxJIRY3lLc4jH2Dt4lwnWyWwpw=
mvdan.cc/gofumpt@v0.8.0 h1:nZUCeC2ViFaerTcYKstMmfysj6uhQrA2vJe+2vwGU6k=
mvdan.cc/xurls/v2@v2.6.0 h1:3NTZpeTxYVWNSokW3MKeyVkz/j7uYXYiMtXRUfmjbgI=
go: go1.24.5
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=''
GOCACHE='/home/jon/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/jon/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build3007033306=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/dev/null'
GOMODCACHE='/home/jon/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/jon/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/lib/go'
GOSUMDB='sum.golang.org'
GOTELEMETRY='off'
GOTELEMETRYDIR='/home/jon/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/lib/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.24.5'
GOWORK=''
PKG_CONFIG='pkg-config'
What did you do?
Query for semantic tokens in a file referencing both exported variable V
and unexported variable v
in comment links:
gopls semtok <(cat <<EOF
package main
var v any
var V any
// [v]
// [V]
EOF
)
What did you see happen?
A semantic token is generated for V
, but not for v
:
/*⇒7,keyword,[]*/package /*⇒4,namespace,[]*/main
/*⇒3,keyword,[]*/var /*⇒1,variable,[definition interface]*/v /*⇒3,type,[defaultLibrary interface]*/any
/*⇒3,keyword,[]*/var /*⇒1,variable,[definition interface]*/V /*⇒3,type,[defaultLibrary interface]*/any
/*⇒6,comment,[]*/// [v]
/*⇒4,comment,[]*/// [/*⇒1,variable,[interface]*/V/*⇒1,comment,[]*/]
What did you expect to see?
Semantic tokens should also have been generated for v
.
I also observe that invoking "go to definition" on the v
in the [v]
comment navigates to its definition, so it's being interpreted correctly for that flow.
Editor and settings
No response
Logs
No response
Comment From: gabyhelp
Related Issues
- x/tools/gopls: Missing semantic tokens in the declaration of function type variables #66809 (closed)
- x/tools/gopls: missing semantic tokens for function parameters in block #56257 (closed)
- x/tools/gopls: References: report unkeyed composite literals as implicit references to struct fields #74307
- x/tools/gopls: semantic tokens appear to have broken since v0.13.2 #63415 (closed)
- x/tools/gopls: Missing defaultLibrary semantic token modifier for builtin interface types #70251 (closed)
- x/tools/gopls: Missing defaultLibrary semantic token modifier for builtin constants #70219 (closed)
- x/tools/gopls: references doesn't work properly. #60676 (closed)
- x/tools/gopls: doesn't honor staticcheck's //lint:ignore (etc) directives #74273
- x/tools/gopls: strange output with gopls >= 0.3.0, no actual errors detected #37046 (closed)
- x/tools/gopls: undeclared name when accessing symbols from other files #35337 (closed)
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
Comment From: h9jiang
I can reproduce the issue and the place where this got filtered is here.
Gopls will look up this name in the scope of package and only send semantic token if the obj is exported.
Is that reasonable to allow the unexported? Or allow the unexported obj in the same package?
cc @adonovan
I think this is reasonable ask since the hover over for both v and V works. So we should align some consistency.