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: workspace symbols orders external symbols before local module symbols #66523

Open
alecthomas opened this issue Mar 25, 2024 · 7 comments
Labels
gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@alecthomas
Copy link

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
@suzmue suzmue changed the title "Go to Symbol in Workspace" orders external symbols before local module symbols x/tools/gopls: workspace symbols orders external symbols before local module symbols Mar 25, 2024
@suzmue
Copy link
Contributor

suzmue commented Mar 25, 2024

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

@suzmue suzmue transferred this issue from golang/vscode-go Mar 25, 2024
@suzmue suzmue added this to the gopls/backlog milestone Mar 25, 2024
@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 25, 2024
@findleyr
Copy link
Contributor

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 findleyr added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Apr 26, 2024
@findleyr findleyr modified the milestones: gopls/v0.16.0, gopls/v0.17.0 Apr 26, 2024
@alecthomas
Copy link
Author

alecthomas commented Apr 26, 2024

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
Copy link
Author

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

@alecthomas
Copy link
Author

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
Copy link
Author

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

@hyangah
Copy link
Contributor

hyangah commented May 1, 2024

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 microsoft/vscode#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: microsoft/vscode#98125

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

5 participants