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: Tooltip shows distracting documentation for append() function when writing a struct literal #65681

Open
davidben opened this issue Feb 12, 2024 · 5 comments
Labels
Documentation 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

@davidben
Copy link
Contributor

gopls version

golang.org/x/tools/gopls v0.14.2

go env

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/usr/local/google/home/davidben/.cache/go-build'
GOENV='/usr/local/google/home/davidben/.config/go/env'
GOEXE=''
GOEXPERIMENT='fieldtrack,boringcrypto'
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/usr/local/google/home/davidben/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/usr/local/google/home/davidben/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/lib/google-golang'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/lib/google-golang/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.22-20240109-RC01 cl/597041403 +dcbe772469 X:fieldtrack,boringcrypto'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/usr/local/google/home/davidben/tmp/gopls-tooltip/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 -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build427257999=/tmp/go-build -gno-record-gcc-switches'

What did you do?

Say you're building up some list of some complex struct. It's reasonable to write expressions of the form:

	l = append(l, Foo{
		A: "hello",
		B: "world",
	})

Here's a longer example.

package main

type Foo struct {
	A, B, C, D, E, F, G, H, I, J string
}

func distractingPopup() {
	var l []Foo
	l = append(l, Foo{
		A: "hello",
		B: "world",
	})

	l = append(l, Foo{
		A: "hello",
		B: "world",
		// Start adding fields here.
	})

	l = append(l, Foo{
		A: "hello",
		B: "world",
	})

	l = append(l, Foo{
		A: "hello",
		B: "world",
	})

	l = append(l, Foo{
		A: "hello",
		B: "world",
	})
}

What did you see happen?

gopls in VS Code will keep the very, very long documentation for append persistently on screen. This is not very helpful because I'd rather have information about the struct I'm filing in. More importantly, it's distracting because the append documentation is very very long and invariably covers up all the context I need. I end up needing to press Esc after every few keystrokes to code effectively.

See attached screenshot.
Screenshot from 2024-02-12 14-04-32

What did you expect to see?

gopls does not cover up my code and instead displays useful information about the struct I'm filling in, not append. If showing append is unavoidable, it should be much, much shorter so that it doesn't cover up important context.

Editor and settings

No response

Logs

No response

@davidben davidben 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 Feb 12, 2024
@gopherbot gopherbot added this to the Unreleased milestone Feb 12, 2024
@findleyr
Copy link
Contributor

Huh, I couldn't immediately reproduce this, which turned out to be because I was using the prerelease. I can reproduce with gopls@v0.14.2, but not with gopls@v0.15.0-pre.3.

Could you please try installing the prerelease, to see if it reproduces for you?

go install golang.org/x/tools/gopls@v0.15.0-pre.3

With that said, I don't yet know when we would have fixed this (though we did refactor some code related to signatureHelp). I will try to bisect. In the meantime, I'm very curious if the prerelease also fixes the bug for you.

@adonovan
Copy link
Member

adonovan commented Feb 14, 2024

@findleyr, I can reproduce this with go@master and gopls@master. Much though I would love to have fixed this by accident in CL 542057, I don't think I can take credit for that. ;-)

Repro instructions: use the example above, and where it says // Start adding fields here, type C: 1, and the append message appears. Type backspaces and it doesn't go away. This behavior also occurs at the parent commit of CL 542057.

@meling
Copy link

meling commented Feb 14, 2024

Maybe some other UI element could be used instead of overlaying with a tooltip, especially when the box would be large. Maybe this type of information could be shown in a separate panel on the side of the editor window or something.

@davidben
Copy link
Contributor Author

Yeah, to be honest, I often find VS code's tooltips to be a bit hectic. I'm sure it's confirmation bias, but it feels like it's never there when I want it, and it's always there when I don't want it, usually covering something up. 😄 Then again, when it is what I want, tooltip is a very convenient location.

Maybe if the type signature (short) were in a tooltip and the full docs were further to the side? Or maybe, for big multi-line statements, the tooltip could be anchored to the start or end of the statement instead of the cursor? (I assume those are all VS Code issues rather than LSP issues.)

But I think there's also an LSP-level issue, which might address the immediate problem: I don't actually want the documentation for append in this scenario. I want the documentation for the struct field I'm filling in.

@findleyr
Copy link
Contributor

Elsewhere in the codebase (e.g. documentHighlight) there is short-circuit logic when the cursor is in a composite literal. I think we need the same logic for signatureHelp: if you're inside a composite literal, you probably don't need to see the signature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation 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

5 participants