-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: fuzzy matching in unimported completion interferes with "good" (prefix/substring) choices #36591
Comments
Thank you for filing a gopls issue! Please take a look at the Troubleshooting guide, and make sure that you have provided all of the relevant information here. |
cc @muirmanders for fuzzy matching issues, but I'm confident there are unimported completion scoring issues in here too so I'll take it for now. |
Change https://golang.org/cl/215023 mentions this issue: |
It appears the fuzzy matcher gives the same (perfect) score to candidates "New" and "NewFoo" when searching on "New". We can either change the fuzzy matcher to add a penalty for non-exact matches, or we can change gopls to prefer shorter candidates when the scores are otherwise identical. I would guess the latter is a better approach, especially considering that there are different matchers beyond fuzzy. |
Actually, the existing sort by candidate label should already order shorter candidates first when scores are equal. If "NewFoo" shows up before "New", it must be because "NewFoo" has a higher score than "New". |
We were assuming that all in-memory packages were equally useful. That's not true for projects with a large dependency tree. Call into the imports code to score them. While I'm here, score the main module above direct deps. Updates golang/go#36591. Change-Id: I07c56dd3ff7338e76f3643e18d35abc1b52d6763 Reviewed-on: https://go-review.googlesource.com/c/tools/+/215023 Run-TryBot: Heschi Kreinick <heschi@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
You're right, something is giving the worse candidates a much higher score than I set by a factor of 10. All my scores are .01 * 7 at most.
|
maybe? I think we should have a rule that scores only go one direction, probably down, from the ones passed in. |
All non-typed candidates end up getting the highScore multiplier: https://github.com/golang/tools/blob/6edc0a871e694a1c8728996c84668863c13d2b4f/internal/lsp/source/completion.go#L1682
The code that discovers a candidate doesn't normally need to be concerned with the quality of the candidate. If the candidate ends up being a good match, it gets the highScore multiplier. If it is a poor match, it gets the lowScore multiplier. If it is a maybe-annoying candidate it gets a more moderate score penalty. We could make it only go down, but then the caller of The untyped unimported candidates are tricky to rank properly relative to typed candidates. I would make typed unimported candidates use |
I don't think that's true? Anywhere we multiply by 10 today, the caller could pass score*10 and we could divide by 10 everywhere we aren't multiplying now. Just so that it's more predictable what the score range of any given call could be. I reviewed all the callers of matchingCandidate, and it looks like it will be harmless to return false instead of true -- it controls stuff like creating composite literals and taking references, none of which makes sense if you don't know the type. That resolves the immediate complaint in this bug. CL shortly. |
Change https://golang.org/cl/215322 mentions this issue: |
Claiming that untyped candidates matched the type of whatever we were looking for messed up rankings in found(). The only other places that use it will all work better with false. Return false. Updates golang/go#36591. Change-Id: I5e1e8af7cc5c27422740cbb77f9a4a20edb1e447 Reviewed-on: https://go-review.googlesource.com/c/tools/+/215322 Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Hopefully this is fixed enough for v0.3. @muirdm, do you think we need to make the changes you described above, or just keep them in mind in case of future issues? I don't fully understand the implications. |
We don't need to do anything now. We should keep it in mind if we get reports like "unimported candidate xyz not ranked first after typing xy" or similar unexpected ranking issues. |
Cool, closing. |
Please answer these questions before submitting your issue. Thanks!
What did you do?
In my project (https://github.com/hortbot/hortbot, relatively large overall dependency set), add a new test file with no imports, then make a new test and complete on unimported packages.
What did you expect to see?
Typing something like
errors.New
orassert.NilError
gives me a resonable set of choices. I.e. I want to seeerrors.New
, orpkg/errors.New
, etc, at the top as they are perfect matches.What did you see instead?
For
errors.New
, I getNew
from a few packages, then a bunch of other results I don't care about that contain the letters "NEW" in order (NewResourceCreationErrorEnum
,LabelErrorEnum_CANNOT_ATTACH_NON_MANAGER_LABEL_TO_CUSTOMER
), then more exactNew
matches, and them more fuzzy matches, and so on.Logs: https://gist.github.com/zikaeroh/385ca2756bffd1af9ab49e199c526a2b
Build info
Go info
The text was updated successfully, but these errors were encountered: