go icon indicating copy to clipboard operation
go copied to clipboard

x/tools/gopls: workspace symbols orders external symbols before local module symbols

Open alecthomas opened this issue 1 year ago • 6 comments

What version of Go, VS Code & VS Code Go extension are you using?

Version Information
  • Run go version to get version of Go from the VS Code integrated terminal.
    • go version go1.22.1 darwin/arm64
  • Run gopls -v version to get version of Gopls from the VS Code integrated terminal.
    • golang.org/x/tools/gopls v0.15.2
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders.
    • 1.87.2 863d2581ecda6849923a2118d93a088b0745d9d6 arm64
  • Check your installed extensions to get the version of the VS Code Go extension
    • v0.41.2
  • Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > Go: Locate Configured Go Tools command.
# Tools Configuration


## Environment

GOBIN: /Users/alec/dev/ftl/.hermit/go/bin
toolsGopath: 
gopath: /Users/alec/go
GOROOT: /Users/alec/Library/Caches/hermit/pkg/go-1.22.1
PATH: /Users/alec/Library/Caches/hermit/pkg/go-1.22.1/bin:/Users/alec/dev/ftl/scripts:/Users/alec/dev/ftl/frontend/node_modules/.bin:/Users/alec/dev/ftl/node_modules/.bin:/Users/alec/dev/ftl/.hermit/node/bin:/Users/alec/dev/ftl/.hermit/go/bin:/Users/alec/dev/ftl/bin:/Users/alec/.local/bin:/Users/alec/bin:/opt/homebrew/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/Apple/usr/bin:/Applications/kitty.app/Contents/MacOS:/Users/alec/.orbstack/bin
PATH (vscode launched with): /Users/alec/dev/ftl/scripts:/Users/alec/dev/ftl/frontend/node_modules/.bin:/Users/alec/dev/ftl/node_modules/.bin:/Users/alec/dev/ftl/.hermit/node/bin:/Users/alec/dev/ftl/.hermit/go/bin:/Users/alec/dev/ftl/bin:/Users/alec/.local/bin:/Users/alec/bin:/opt/homebrew/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/Apple/usr/bin:/Applications/kitty.app/Contents/MacOS:/Users/alec/.orbstack/bin

## Tools

	go:	/Users/alec/Library/Caches/hermit/pkg/go-1.22.1/bin/go: go version go1.22.1 darwin/arm64

	gopls:	/Users/alec/dev/ftl/.hermit/go/bin/gopls	(version: v0.15.2 built with go: go1.22.1)
	gotests:	/Users/alec/dev/ftl/.hermit/go/bin/gotests	(version: v1.6.0 built with go: go1.22.1)
	gomodifytags:	/Users/alec/dev/ftl/.hermit/go/bin/gomodifytags	(version: v1.16.0 built with go: go1.22.1)
	impl:	/Users/alec/dev/ftl/.hermit/go/bin/impl	(version: v1.1.0 built with go: go1.22.1)
	goplay:	/Users/alec/dev/ftl/.hermit/go/bin/goplay	(version: v1.0.0 built with go: go1.22.1)
	dlv:	/Users/alec/dev/ftl/.hermit/go/bin/dlv	(version: v1.22.1 built with go: go1.22.1)
	staticcheck:	/Users/alec/dev/ftl/.hermit/go/bin/staticcheck	(version: v0.4.7 built with go: go1.22.1)

## Go env

Workspace Folder (ftl): /Users/alec/dev/ftl

	GO111MODULE=''
	GOARCH='arm64'
	GOBIN='/Users/alec/dev/ftl/.hermit/go/bin'
	GOCACHE='/Users/alec/Library/Caches/go-build'
	GOENV='/Users/alec/Library/Application Support/go/env'
	GOEXE=''
	GOEXPERIMENT=''
	GOFLAGS=''
	GOHOSTARCH='arm64'
	GOHOSTOS='darwin'
	GOINSECURE=''
	GOMODCACHE='/Users/alec/go/pkg/mod'
	GONOPROXY='*.sqcorp.co,github.com/squareup'
	GONOSUMDB='*.sqcorp.co,github.com/squareup'
	GOOS='darwin'
	GOPATH='/Users/alec/go'
	GOPRIVATE='*.sqcorp.co,github.com/squareup'
	GOPROXY='https://proxy.golang.org,direct'
	GOROOT='/Users/alec/Library/Caches/hermit/pkg/go-1.22.1'
	GOSUMDB='sum.golang.org'
	GOTMPDIR=''
	GOTOOLCHAIN='local'
	GOTOOLDIR='/Users/alec/Library/Caches/hermit/pkg/go-1.22.1/pkg/tool/darwin_arm64'
	GOVCS=''
	GOVERSION='go1.22.1'
	GCCGO='gccgo'
	AR='ar'
	CC='clang'
	CXX='clang++'
	CGO_ENABLED='1'
	GOMOD='/Users/alec/dev/ftl/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 -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/h2/_9k30gds1dbdjsv1m3yw834w0000gn/T/go-build2722364599=/tmp/go-build -gno-record-gcc-switches -fno-common'
	

Share the Go related settings you have added/edited

Run Preferences: Open Settings (JSON) command to open your settings.json file. Share all the settings with the go. or ["go"] or gopls prefixes.

Describe the bug

"Go to Symbol in Workspace" orders external symbols before local module symbols. I would expect any matching local symbols to always be before external symbols.

Steps to reproduce the behavior:

This seems to repeatable anywhere, but the example is from https://github.com/TBD54566975/ftl. See the screenshot for the symbol I used.

Screenshots or recordings

If applicable, add screenshots or recordings to help explain your problem.

image

alecthomas avatar Mar 25 '24 21:03 alecthomas

In this case, the fact that the local symbol is a method contributes to its ranked below the external symbols.

suzmue avatar Mar 25 '24 22:03 suzmue

Alas, I'm not sure this is fixable. I think we've already implemented these heuristics in gopls and it is VS Code doing its own sorting and fuzzy matching of the results.

To prove this, compare the output of

gopls workspace_symbol -matcher=fastfuzzy graph

That's the sorting returned by gopls. Does it make more sense?

findleyr avatar Apr 26 '24 20:04 findleyr

It does, the ordering directly from gopls makes sense. So is this occurring in the Go VSCode extension, or in VSCode itself? Where should I re-raise the bug?

alecthomas avatar Apr 26 '24 22:04 alecthomas

This closed ticket from 2019 does not fill me with confidence.

alecthomas avatar Apr 27 '24 03:04 alecthomas

Though this comment suggests that there are existing mechanisms for extensions to control completion ordering, though there are a lot of comments to wade through so it's not really clear what they're referring to.

alecthomas avatar Apr 27 '24 03:04 alecthomas

It seems like this issue should be transferred back to vscode-go?

alecthomas avatar Apr 27 '24 03:04 alecthomas

VS Code Go already does some hack to preserve the ordering for completion (code), but not for workspace symbol search . Unfortunately, I don't see a way to prevent client-side sorting/filtering for workspace symbols in VS Code API yet. (The linked issue was mostly discussing the completion item ordering if I understand it correctly)

https://code.visualstudio.com/api/references/vscode-api#SymbolInformation https://code.visualstudio.com/api/references/vscode-api#WorkspaceSymbolProvider https://code.visualstudio.com/api/references/vscode-api#SymbolInformation

I think the best path going forward is to open a new issue in the vscode repo. There was a similar issue https://github.com/microsoft/vscode/issues/71951 but from the look, the vscode team took the path to improve their client-side sorting algorithm rather than preserving ordering from the language server.

Related: https://github.com/microsoft/vscode/issues/98125

hyangah avatar May 01 '24 14:05 hyangah

As explained in https://github.com/golang/go/issues/66523#issuecomment-2088591686, currently this depends on support or advice from vscode side. Since gopls is doing the right thing already, closing this issue.

hyangah avatar May 28 '24 16:05 hyangah