Skip to content

x/tools/gopls: DocumentSymbol returns incorrect selectionRange #73521

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
MischaPanch opened this issue Apr 28, 2025 · 2 comments
Open

x/tools/gopls: DocumentSymbol returns incorrect selectionRange #73521

MischaPanch opened this issue Apr 28, 2025 · 2 comments
Labels
BugReport Issues describing a possible bug in the Go implementation. Documentation Issues describing a change to documentation. gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@MischaPanch
Copy link

Go version

go version go1.24.2 linux/amd64

Output of go env in your module/workspace:

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/mpanchen/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/mpanchen/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build1575410318=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/dev/null'
GOMODCACHE='/home/mpanchen/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/mpanchen/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/mpanchen/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.24.2'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

This issue is about gopls. The selectionRange attribute of a symbol coincides with range, but it shouldn't. This means it becomes impossible to reference a symbol (e.g., find references to it programatically) from the info retrieved through the language server, as one would need the selectionRange for it (specifically, the character).

What did you see happen?

For example, for something like this

func main() {
    fmt.Println("Hello, Go!")
    Helper()
}

the document_symbol request will return a selectionRange with starting character 0.

What did you expect to see?

It should return the starting character 5 in the selection range.

@MischaPanch MischaPanch changed the title import/path: issue title gopls returns incorrect selectionRange Apr 28, 2025
@gopherbot gopherbot added the gopls Issues related to the Go language server, gopls. label Apr 28, 2025
@seankhliao seankhliao changed the title gopls returns incorrect selectionRange x/tools/gopls returns incorrect selectionRange Apr 28, 2025
@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Apr 28, 2025
@gopherbot gopherbot added this to the Unreleased milestone Apr 28, 2025
@seankhliao seankhliao changed the title x/tools/gopls returns incorrect selectionRange x/tools/gopls: returns incorrect selectionRange Apr 28, 2025
@gabyhelp
Copy link

@gabyhelp gabyhelp added the BugReport Issues describing a possible bug in the Go implementation. label Apr 28, 2025
@adonovan
Copy link
Member

the document_symbol request will return a selectionRange with starting character 0.
It should return the starting character 5 in the selection range.

Could you provide a complete sequence of steps to reproduce the problem? The logic looks fine to me, and I can't reproduce the problem on your example:

xtools$ cat a.go
package main

import "fmt"

func main() {
    fmt.Println("Hello, Go!")
    Helper()
}

xtools$ gopls symbols ./a.go 
main Function 5:6-5:10

@adonovan adonovan added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Apr 28, 2025
@adonovan adonovan changed the title x/tools/gopls: returns incorrect selectionRange x/tools/gopls: DocumentSymbol returns incorrect selectionRange Apr 28, 2025
@gopherbot gopherbot added the Documentation Issues describing a change to documentation. label Apr 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BugReport Issues describing a possible bug in the Go implementation. Documentation Issues describing a change to documentation. gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants