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: WorkspaceSymbol returns strange results in strange order #60027

Closed
myitcv opened this issue May 6, 2023 · 3 comments
Closed
Labels
gopls Issues related to the Go language server, gopls. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@myitcv
Copy link
Member

myitcv commented May 6, 2023

What version of Go are you using (go version)?

$ go version
go version go1.20.2 linux/arm64
$ go list -m golang.org/x/tools
golang.org/x/tools v0.8.1-0.20230424202313-71ea8f168c16
$ go list -m golang.org/x/tools/gopls
golang.org/x/tools/gopls v0.0.0-20230424202313-71ea8f168c16

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE="on"
GOARCH="arm64"
GOBIN=""
GOCACHE="/home/myitcv/.cache/go-build"
GOENV="/home/myitcv/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/myitcv/gostuff/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/myitcv/gostuff"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/myitcv/gos"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/myitcv/gos/pkg/tool/linux_arm64"
GOVCS=""
GOVERSION="go1.20.2"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/myitcv/gostuff/src/github.com/myitcv/govim/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 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build235298812=/tmp/go-build -gno-record-gcc-switches"

What did you do?

cd $(mktemp -d)
git clone https://github.com/mvdan/sh
cd sh
git checkout 1e9de6acbbb76e4387751bda2bba2cbd42a0ee5d
vi syntax/parser.go

Then perform a symbol search for rune, in an attempt to locate the symbol mvdan.cc/sh/v3/syntax.Parser.rune.

The results are ordered as follows (best match first):

mvdan.cc/sh/v3/interp.Runner
mvdan.cc/sh/v3/interp.runnerOpts
mvdan.cc/sh/v3/interp.RunnerOption
mvdan.cc/sh/v3/interp_test.runTest
mvdan.cc/sh/v3/interp_test.runTests
mvdan.cc/sh/v3/interp_test.runnerCtx
mvdan.cc/sh/v3/cmd/gosh.runInteractive
mvdan.cc/sh/v3/interp_test.runTestsUnix
mvdan.cc/sh/v3/interp_test.runTests64bit
mvdan.cc/sh/v3/interp_test.runTestsWindows
mvdan.cc/sh/v3/syntax.Parser.rune
mvdan.cc/sh/v3/syntax.singleRuneParam
mvdan.cc/sh/v3/interp_test.TestRunnerDir
...

I've included ~20% of the results returned. Notice that I performed this search when in the context of the syntax package.

The one row (in the first 20% of results) where there is a full match on the last element (i.e. the symbol itself), the row I actually want, is at position 11. There are less good matches in the first 10 rows, some of which are in test packages. None of those first 10 are in the package of interest (given the current file cursor position in syntax/parser.go).

This problem is related to #37237. That said, #37236 (comment) makes clear that there are currently no plans to implement such an approach.

Therefore I think the current matching logic should be better here.

I've not looked at this part of the code recently, but it seems like the scoring of perfect matches for the symbol itself could/should score much higher?

What did you expect to see?

mvdan.cc/sh/v3/syntax.Parser.rune returned as the first result.

What did you see instead?

As above.

@myitcv myitcv added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. gopls Issues related to the Go language server, gopls. labels May 6, 2023
@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label May 6, 2023
@gopherbot gopherbot added this to the Unreleased milestone May 6, 2023
@findleyr
Copy link
Contributor

findleyr commented May 8, 2023

Thanks, this is a regression that we had not noticed since other clients perform their own sorting.

I'll fix this presently.

@findleyr findleyr modified the milestones: Unreleased, gopls/v0.12.0 May 8, 2023
@findleyr
Copy link
Contributor

findleyr commented May 8, 2023

Correction, this is not a regression, but rather a poor downranking of nested fields/methods.

The raw matching score for "rune" is 100%, but is downranked to 80% for being a method.
The raw matching score for "Runner" is 90%, and is not downranked as it is a top-level declaration.

I think the downranking for fields/methods is far too high, as it should only be a tie-breaker. I'll reduce it significantly.

@gopherbot
Copy link

Change https://go.dev/cl/493623 mentions this issue: internal/fuzzy: improvements to the symbol scoring algorithm

myitcv pushed a commit to myitcvforks/tools that referenced this issue May 9, 2023
Based on feedback in golang/go#60027, tweak the fuzzy symbol scoring
algorithm to much more strongly prefer sequential and exact matches.

Fixes golang/go#60027

Change-Id: I1c6d019065c4dff4adf2db9e94397a635e13d50f
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. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

3 participants