Skip to content

x/tools/gopls: Extend hover ability to get the type of selected expression #69058

Open
@xzbdmw

Description

@xzbdmw

gopls version

golang.org/x/tools/gopls v0.0.0-20240816163142-66adacf20fc4
golang.org/x/tools/gopls@v0.0.0-20240816163142-66adacf20fc4 h1:iSreTB1mHFYjQkoNmGjFjKRGkrhedt4wmfg
47nKSo28=
github.com/BurntSushi/toml@v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=
github.com/google/go-cmp@v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
golang.org/x/exp/typeparams@v0.0.0-20221212164502-fae10dda9338 h1:2O2DON6y3XMJiQRAS1UWU+54aec2uopH
3x7MAiqGW6Y=
golang.org/x/mod@v0.20.0 h1:utOm6MM3R3dnawAiJgn0y+xvuYRsm1RKM/4giyfDgV0=
golang.org/x/sync@v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/telemetry@v0.0.0-20240712210958-268b4a8ec2d7 h1:nU8/tAV/21mkPrCjACUeSibjhynTovgRMXc32
+Y1Aec=
golang.org/x/text@v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
golang.org/x/tools@v0.24.1-0.20240816163142-66adacf20fc4 h1:PoPnfVMls3TamN2+Zq6FsI1uSjUOqW1mt6AXfY
w3kdw=
golang.org/x/vuln@v1.0.4 h1:SP0mPeg2PmGCu03V+61EcQiOjmpri2XijexKdzv8Z1I=
honnef.co/go/tools@v0.4.7 h1:9MDAWxMoSnB6QoSqiVr7P5mtkT9pOc1kSxchzPCnqJs=
mvdan.cc/gofumpt@v0.6.0 h1:G3QvahNDmpD+Aek/bNOLrFR2XC6ZAdo62dZu65gmwGo=
mvdan.cc/xurls/v2@v2.5.0 h1:lyBNOm8Wo71UknhUs4QTFUNNMyxy2JEIaKKo0RWOh+8=
go: go1.22.4

go env

GO111MODULE='auto'
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/xzb/Library/Caches/go-build'
GOENV='/Users/xzb/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/xzb/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/xzb/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.22.4'
GCCGO='gccgo'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/Users/xzb/Project/go/tools/go.mod'
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/gv/r110hgbx1gbgzp95kf_q71x40000gn/T/go-build4205968761=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

As the title says, get the type info of seleted range.
in Goland
https://github.com/user-attachments/assets/7eea395f-490f-420f-8c8e-d1897f679f0e

in rust-analyzer
documentation

iShot_2024-08-25_10.07.24.mp4

What did you see happen?

We can't hover in selection state to get type information

What did you expect to see?

Get the type info of seleted range.
related:rust-lang/rust-analyzer#9693

Editor and settings

No response

Logs

No response

Activity

added
goplsIssues related to the Go language server, gopls.
ToolsThis label describes issues relating to any tools in the x/tools repository.
on Aug 25, 2024
added this to the Unreleased milestone on Aug 25, 2024
findleyr

findleyr commented on Aug 29, 2024

@findleyr
Member

Thanks.

We've talked about such a feature in the past, but have always been limited by the fact that textDocument/hover accepts a position, not a range (https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#hoverParams).

Looks like rust-analyzer added a hoverRange extension. I wonder how many clients support this?

CC @adonovan, who I believe has thought about this exact feature.

added
FeatureRequestIssues asking for a new feature that does not need a proposal.
on Aug 29, 2024
adonovan

adonovan commented on Aug 29, 2024

@adonovan
Member
gopherbot

gopherbot commented on Aug 29, 2024

@gopherbot
Contributor

Change https://go.dev/cl/609656 mentions this issue: gopls/internal/golang: hover: show type of selected expr

xzbdmw

xzbdmw commented on Aug 30, 2024

@xzbdmw
Author

https://go.dev/cl/609656

It already works in neovim, amazing 🚀

findleyr

findleyr commented on Aug 30, 2024

@findleyr
Member

@xzbdmw are you using the built in neovim lsp client, or some LSP plugin?

Send screenshots, please :)

@adonovan should we follow the Rust team's lead and just ship first and ask questions later? :)

adonovan

adonovan commented on Aug 30, 2024

@adonovan
Member

@adonovan should we follow the Rust team's lead and just ship first and ask questions later? :)

I nudged the 377 issue last night and I think the dominoes may be close to toppling.

xzbdmw

xzbdmw commented on Aug 31, 2024

@xzbdmw
Author

are you using the built in neovim lsp client

Yes, by adding range param to requst of TextDocument/Hover, something like

local range = require("vim.lsp.buf").range_from_selection(0, mode)
local param = vim.lsp.util.make_position_params(0, nil)
param.range = range
vim.lsp.buf_request(0, "textDocument/hover", param, handler)

screenshot:

iShot_2024-08-31_11.11.43.mp4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureRequestIssues asking for a new feature that does not need a proposal.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

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @adonovan@gopherbot@findleyr@xzbdmw@gabyhelp

        Issue actions

          x/tools/gopls: Extend hover ability to get the type of selected expression · Issue #69058 · golang/go