Skip to content

x/tools/gopls: vscode 'sticky scroll' doesn't work for ginkgo test files unless there's only a single top-level entity #3820

@mdbooth

Description

@mdbooth

Go version

go version go1.24.4 linux/amd64

Output of go env in your module/workspace:

AR='ar'
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GOAMD64='v1'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/home/mbooth/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/mbooth/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'                                                                                                                                                                                                                                                                                                       GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build1384982302=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/home/mbooth/src/openshift/cluster-capi-operator/go.mod'
GOMODCACHE='/home/mbooth/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/mbooth/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/mbooth/.go-distro/1.24.4'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/mbooth/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/home/mbooth/.go-distro/1.24.4/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.24.4'
GOWORK='/home/mbooth/src/openshift/cluster-capi-operator/go.work'
PKG_CONFIG='pkg-config'

What did you do?

Unfortunately I don't understand the interactions between vscode and gopls, so the following will likely require translation before being actionable.

VS Code (Cursor in this screenshot, but it's the same thing) has a feature called 'sticky scroll' which retains lines leading to the current lexical scope at the top of the window when scrolling. It looks like this:

Image

It is my understanding that the metadata required to do this is produced by gopls, but as noted I unfortunately can't confirm this or explain how.

Sticky scroll works in the following file. When the cursor is positioned on one of the fmt.Println()s the context shows:

  • Describe...
    • Context...
      • It...
package main

import (
	"fmt"

	. "github.com/onsi/ginkgo/v2"
)

var _ = Describe("Top level", func() {
	Context("Some context", func() {
		It("Should do something", func() {
			fmt.Println("Hello, world!")
			fmt.Println("Hello, world!")
			fmt.Println("Hello, world!")
			fmt.Println("Hello, world!")
			fmt.Println("Hello, world!")
			fmt.Println("Hello, world!")
			fmt.Println("Hello, world!")
		})
	})
})

Sticky scroll does not work in this file. When the cursor is positioned on one of the foo() calls there is no context displayed in the editor window.

package main

import (
	"fmt"

	. "github.com/onsi/ginkgo/v2"
)

var _ = Describe("Top level", func() {
	Context("Some context", func() {
		It("Should do something", func() {
			foo()
			foo()
			foo()
			foo()
			foo()
			foo()
			foo()
		})
	})
})

func foo() {
	fmt.Println("Hello, world!")
}

What did you see happen?

Sticky scroll does not work: the lines leading to the current lexical scope are not displayed at the top of the IDE's editor window.

What did you expect to see?

Sticky scroll should work in my IDE when the file has more than one top-level element.

Metadata

Metadata

Assignees

No one assigned

    Labels

    WaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.goplsgopls related issues

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions