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: missing function name in signature when hovering over built-in function #51811

Closed
katsusan opened this issue Mar 19, 2022 · 1 comment
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@katsusan
Copy link

gopls version

 ~/go/bin  gopls -v version                                                           
Build info
----------
golang.org/x/tools/gopls v0.8.1
    golang.org/x/tools/gopls@v0.8.1 h1:q5nDpRopYrnF4DN/1o8ZQ7Oar4Yd4I5OtGMx5RyV2/8=
    github.com/BurntSushi/toml@v1.0.0 h1:dtDWrepsVPfW9H/4y7dDgFc2MBUSeJhlaDtK13CxFlU=
    github.com/google/go-cmp@v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
    github.com/sergi/go-diff@v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
    golang.org/x/mod@v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 h1:kQgndtyPBW/JIYERgdxfwMYh3AVStj88WQTlNDi2a+o=
    golang.org/x/sync@v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
    golang.org/x/sys@v0.0.0-20220209214540-3681064d5158 h1:rm+CHSpPEEW2IsXUib1ThaHIjuBVZjxNgSKmBLFfD4c=
    golang.org/x/text@v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
    golang.org/x/tools@v0.1.10-0.20220315142906-0c66750444e6 h1:AOqgMGxa5hFduIlFkKEX87HoRPO9wjyfhqf1yqwybeg=
    golang.org/x/xerrors@v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
    honnef.co/go/tools@v0.2.2 h1:MNh1AVMyVX23VUHE2O27jm6lNj3vjO5DexS4A1xvnzk=
    mvdan.cc/gofumpt@v0.3.0 h1:kTojdZo9AcEYbQYhGuLf/zszYthRdhDNDUi2JKTxas4=
    mvdan.cc/xurls/v2@v2.4.0 h1:tzxjVAj+wSBmDcF6zBB7/myTy3gX9xvi8Tyr28AuQgc=
go: go1.18

go env

 ~/go/bin  go env                                                                           
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/root/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/root/go"
GOPRIVATE=""
GOPROXY="https://goproxy.cn"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.18"
GCCGO="/usr/local/bin/gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1830292990=/tmp/go-build -gno-record-gcc-switches"

What did you do?

  1. create a x.go and use built-in function like panic/recover/make/...
  2. hover on the built-in function.

What did you expect to see?

func(v any)func panic(v any)

image

What did you see instead?

image

Editor and settings

It doesn't seem to be related to editor setting.

Logs

trace logs:

[Trace - 19:18:15.658 PM] Sending request 'textDocument/hover - (7)'.
Params: {"textDocument":{"uri":"file:///root/trygo/x.go"},"position":{"line":13,"character":3}}


[Trace - 19:18:15.663 PM] Received response 'textDocument/hover - (7)' in 4ms.
Result: {"contents":{"kind":"markdown","value":"```go\nfunc(v any)\n```\n\n[`panic` on pkg.go.dev](https://pkg.go.dev/builtin?utm_source=gopls#panic)\n\nThe panic built\\-in function stops normal execution of the current\ngoroutine\\. When a function F calls panic, normal execution of F stops\nimmediately\\. Any functions whose execution was deferred by F are run in\nthe usual way, and then F returns to its caller\\. To the caller G, the\ninvocation of F then behaves like a call to panic, terminating G\\'s\nexecution and running any deferred functions\\. This continues until all\nfunctions in the executing goroutine have stopped, in reverse order\\. At\nthat point, the program is terminated with a non\\-zero exit code\\. This\ntermination sequence is called panicking and can be controlled by the\nbuilt\\-in function recover\\.\n"},"range":{"start":{"line":13,"character":1},"end":{"line":13,"character":6}}}

Possible reason

//https://github.com/golang/tools/blob/5ea13d0d89f92d5ca5468e282dd4ba2ad7503564/internal/lsp/source/hover.go#L576-L581

func FindHoverContext(ctx context.Context, s Snapshot, pkg Package, obj types.Object, pkgNode ast.Node, fullDecl ast.Decl) (*HoverContext, error) {
        ...
	case *ast.FuncDecl:
		switch obj.(type) {
		case *types.Func:
			info = &HoverContext{signatureSource: obj, Comment: node.Doc}
		case *types.Builtin:
			info = &HoverContext{signatureSource: node.Type, Comment: node.Doc}

In the case of *types.Builtin only node.Type (ast.FuncDecl.Type) is reserved while ast.FuncDecl.Name
info is discarded. I tried following change and the function name can be shown correctly.

  info = &HoverContext{signatureSource: node.Type, Comment: node.Doc}
    ↓
  info = &HoverContext{
      signatureSource: &ast.FuncDecl{
	  Name: node.Name,
	  Type: node.Type,
      },
      Comment: node.Doc,
  }
@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Mar 19, 2022
@gopherbot gopherbot added this to the Unreleased milestone Mar 19, 2022
@gopherbot
Copy link

Change https://go.dev/cl/395294 mentions this issue: internal/lsp/source: include builtin name in hovered signature

@findleyr findleyr modified the milestones: Unreleased, gopls/v0.8.2 Mar 23, 2022
@findleyr findleyr self-assigned this Mar 31, 2022
@golang golang locked and limited conversation to collaborators Jun 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

3 participants