Skip to content
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

x/tools/gopls: get signature when cursor is over the function name #68922

Closed
crazyhulk opened this issue Aug 17, 2024 · 6 comments
Closed

x/tools/gopls: get signature when cursor is over the function name #68922

crazyhulk opened this issue Aug 17, 2024 · 6 comments
Labels
gopls Issues related to the Go language server, gopls. help wanted Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@crazyhulk
Copy link

crazyhulk commented Aug 17, 2024

gopls version

Build info

golang.org/x/tools/gopls v0.16.1
golang.org/x/tools/[email protected] h1:1hO/dCeUvjEYx3V0rVvCtOkwnpEpqS29paE+Jw4dcAc=
github.com/BurntSushi/[email protected] h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=
github.com/google/[email protected] h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
golang.org/x/exp/[email protected] h1:2O2DON6y3XMJiQRAS1UWU+54aec2uopH3x7MAiqGW6Y=
golang.org/x/[email protected] h1:5+9lSbEzPSdWkH32vYPBwEpX8KwDbM52Ud9xBUvNlb0=
golang.org/x/[email protected] h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/[email protected] h1:3Wt8mZlbFwG8llny+t18kh7AXxyWePFycXMuVdHxnyM=
golang.org/x/[email protected] h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
golang.org/x/[email protected] h1:Kd+Z5Pm6uwYx3T2KEkeHMHUMZxDPb/q6b1m+zEcy62c=
golang.org/x/[email protected] h1:SP0mPeg2PmGCu03V+61EcQiOjmpri2XijexKdzv8Z1I=
honnef.co/go/[email protected] h1:9MDAWxMoSnB6QoSqiVr7P5mtkT9pOc1kSxchzPCnqJs=
mvdan.cc/[email protected] h1:G3QvahNDmpD+Aek/bNOLrFR2XC6ZAdo62dZu65gmwGo=
mvdan.cc/xurls/[email protected] h1:lyBNOm8Wo71UknhUs4QTFUNNMyxy2JEIaKKo0RWOh+8=
go: go1.21.0

go env

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/zx/.cache/go-build'
GOENV='/home/zx/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/zx/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/zx/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/linux_amd64'
GOVCS=''
GOVERSION='go1.21.0'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/zx/workspace/go/tools/gopls/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 -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build2830052148=/tmp/go-build -gno-record-gcc-switches'

What did you do?

I cannot get function signatures without the parentheses when use lsp."textDocument/signatureHelp" when I make a code snippet plugin for neovim.

cmp-sign

What did you see happen?

Get nil by exec lua vim.lsp.buf.signature_help() in the neovim when cursor over the function name.

image image

What did you expect to see?

We prefere to use "." to trigger a code complete menu, we also need the ability to retrieve function signatures when cursor over the function name.

image image

I have made a pull request to fix this.

Editor and settings

nvim, it works well.

Logs

No response

@crazyhulk crazyhulk added gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. labels Aug 17, 2024
@gopherbot gopherbot added this to the Unreleased milestone Aug 17, 2024
crazyhulk added a commit to crazyhulk/tools that referenced this issue Aug 19, 2024
Currently, signatures can only be returned
within the parentheses when use
lsp."textDocument/signatureHelp"; they
cannot be returned on the function name.

Because we prefere to use "." to trigger a
code complete menu, we also need the ability
to retrieve function signatures

Fixes golang/go#68922
@findleyr findleyr changed the title x/tools/gopls: get signature when cusor is over the function name x/tools/gopls: get signature when cursor is over the function name Aug 21, 2024
@findleyr
Copy link
Contributor

Thanks, it seems reasonable to support this, and agree that it is a good help-wanted issue. Thanks for the contribution, we'll review your CL.

@findleyr findleyr modified the milestones: Unreleased, gopls/v0.17.0 Aug 21, 2024
crazyhulk added a commit to crazyhulk/tools that referenced this issue Aug 22, 2024
Currently, signatures can only be returned
within the parentheses when use
lsp."textDocument/signatureHelp"; they
cannot be returned on the function name.

Because we prefere to use "." to trigger a
code complete menu, we also need the ability
to retrieve function signatures

Fixes golang/go#68922
@adonovan
Copy link
Member

I agree that the feature seems like a reasonable interpretation of SignatureHelp and its SignatureInformation result type, which represents "the signature of something callable".

@crazyhulk
Copy link
Author

crazyhulk commented Aug 23, 2024

I agree that the feature seems like a reasonable interpretation of SignatureHelp and its SignatureInformation result type, which represents "the signature of something callable".

/**

  • Signature help represents the signature of something
  • callable. There can be multiple signature but only one
  • active and only one active parameter.
    */

Callable, not calling?

" Signature help represents the signature of something callable." which refers to the entire set of method, sel, function, etc.

Gopls provides tremendous help while we write code, consider the following situation:

func foo(a, b int) int {
}

foo.

I want a complete menu here, and I must call foo.
In this situation, if signature help is provided only after I’ve completed writing the function, it’s no longer useful.

In other words, we should provide function signatures for everything that is callable, not just for functions that are already being called.

@adonovan
Copy link
Member

We agree. :-)

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/605983 mentions this issue: SignatureHelp: report signature of Ident if no enclosing CallExpr

crazyhulk added a commit to crazyhulk/tools that referenced this issue Aug 30, 2024
Currently, signatures can only be returned
within the parentheses when use
lsp."textDocument/signatureHelp"; they
cannot be returned on the function name.

Because we prefere to use "." to trigger a
code complete menu, we also need the ability
to retrieve function signatures

Fixes golang/go#68922
crazyhulk added a commit to crazyhulk/tools that referenced this issue Sep 12, 2024
Currently, signatures can only be returned
within the parentheses when use
lsp."textDocument/signatureHelp"; they
cannot be returned on the function name.

Because we prefere to use "." to trigger a
code complete menu, we also need the ability
to retrieve function signatures

Fixes golang/go#68922
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls Issues related to the Go language server, gopls. help wanted Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants