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: symbol ranking algorithm edge case #60201

Closed
myitcv opened this issue May 15, 2023 · 6 comments
Closed

x/tools/gopls: symbol ranking algorithm edge case #60201

myitcv opened this issue May 15, 2023 · 6 comments
Assignees
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. NeedsFix The path to resolution is known, but the work has not been done. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@myitcv
Copy link
Member

myitcv commented May 15, 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.9.2-0.20230511211205-01128f9fbc93
$ go list -m golang.org/x/tools/gopls
golang.org/x/tools/gopls v0.0.0-20230511211205-01128f9fbc93

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=""
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/.vim/plugged/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-build2021304014=/tmp/go-build -gno-record-gcc-switches"

What did you do?

cd $(mktemp -d)
git init
git fetch https://review.gerrithub.io/cue-lang/cuelang.org refs/changes/96/553896/2
git checkout FETCH_HEAD

Then open your editor at the root of the repo and perform a symbol search for parseside

What did you expect to see?

The result:

github.com/cue-lang/cuelang.org/internal/cmd/preprocessor/cmd.parseContext.parse_sidebyside

to be returned as the best match.

What did you see instead?

The result:

github.com/cue-lang/cuelang.org/playground/internal/cuelang_org_go_internal/third_party/yaml.yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE

returned as the best match, with the desired best match second.

@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 15, 2023
@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label May 15, 2023
@gopherbot gopherbot added this to the Unreleased milestone May 15, 2023
@findleyr
Copy link
Member

Thanks, eyeballing the match, I would have expected the desired result to be first. I'll debug.

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

Sorry, we're trying to get the v0.12.0 release out, and this is something of an edge case, so it will have to wait for v0.13.0. Still a priority.

@findleyr findleyr modified the milestones: gopls/v0.12.0, gopls/v0.13.0 May 19, 2023
@myitcv
Copy link
Member Author

myitcv commented May 19, 2023

Sorry, we're trying to get the v0.12.0 release out, and this is something of an edge case, so it will have to wait for v0.13.0. Still a priority.

No problems, appreciate you finding the time to update the issue!

@adonovan
Copy link
Member

adonovan commented Jul 4, 2023

I can repro this using git clone https://github.com/cue-lang/cuelang.org.git and git checkout alpha. (The gerrit URL resulted in a password challenge.) I'm using the gopls defaults of "fast fuzzy matcher" and "dynamic symbolizer".

The cause appears to be the scoring algorithm implemented by (*fuzzy.SymbolMatcher).Match, which ranks yaml_[PARSE]_FLOW_[S]EQUENCE_ENTRY_MAPP[I]NG_EN[D]_STAT[E] very highly because it contains "parse" as a substring and the letters s, i, d, e in that order, following, as indicated by the square brackets. Paradoxically, the length of the identifier counts in its favor for scoring because of the "streak" logic, even though the connection with the search term is very tenous.

I'm out of my depth on how to fix it though. Assigning to @findleyr.

@adonovan adonovan added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Jul 4, 2023
@myitcv
Copy link
Member Author

myitcv commented Jul 5, 2023

I can repro this using git clone https://github.com/cue-lang/cuelang.org.git and git checkout alpha. (The gerrit URL resulted in a password challenge.)

Apologies, I didn't run the repro steps in a clean environment to catch that. Now updated to remove the authenticated GerritHub URL.

Paradoxically, the length of the identifier counts in its favor for scoring because of the "streak" logic, even though the connection with the search term is very tenous.

Thanks for investigating in any case!

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/531697 mentions this issue: internal/fuzzy: several improvements for symbol matching

@golang golang locked and limited conversation to collaborators Oct 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. NeedsFix The path to resolution is known, but the work has not been done. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

4 participants