go icon indicating copy to clipboard operation
go copied to clipboard

x/tools/gopls: Tooltip shows distracting documentation for append() function when writing a struct literal

Open davidben opened this issue 1 year ago • 5 comments

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 avatar Feb 12 '24 19:02 davidben

Huh, I couldn't immediately reproduce this, which turned out to be because I was using the prerelease. I can reproduce with [email protected], but not with [email protected].

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

go install golang.org/x/tools/[email protected]

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.

findleyr avatar Feb 13 '24 22:02 findleyr

@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.

adonovan avatar Feb 14 '24 22:02 adonovan

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.

meling avatar Feb 14 '24 22:02 meling

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.

davidben avatar Feb 15 '24 00:02 davidben

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.

findleyr avatar Feb 15 '24 13:02 findleyr