1
0
mirror of https://github.com/golang/go synced 2024-11-18 10:54:40 -07:00

internal/lsp/source: improve unimported package member ranking

Untyped members from unimported packages are scored the same as typed
members from unimported packages. We depended on the unimported
package relevance to rank the probably-more-relevant typed members
higher. However, there are some unrelated score penalties that can
only be applied to typed candidates, so the untyped candidates ended
up being ranked higher. Fix by increasing the relevance coefficient so
the relevance score overpowers other less important scoring
adjustments.

Fixes golang/go#38104.

Change-Id: Ie43f769a41511f9cc3747ce6936130be7a29cd31
Reviewed-on: https://go-review.googlesource.com/c/tools/+/231238
Run-TryBot: Muir Manders <muir@mnd.rs>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
This commit is contained in:
Muir Manders 2020-04-30 14:38:17 -07:00 committed by Heschi Kreinick
parent 2840dafb9e
commit f26c0dd982

View File

@ -804,7 +804,7 @@ func (c *completer) unimportedMembers(ctx context.Context, id *ast.Ident) error
if imports.ImportPathToAssumedName(path) != pkg.GetTypes().Name() {
imp.name = pkg.GetTypes().Name()
}
c.packageMembers(ctx, pkg.GetTypes(), stdScore+.01*float64(relevance), imp)
c.packageMembers(ctx, pkg.GetTypes(), stdScore+.1*float64(relevance), imp)
if len(c.items) >= unimportedMemberTarget {
return nil
}
@ -824,7 +824,7 @@ func (c *completer) unimportedMembers(ctx context.Context, id *ast.Ident) error
// Continue with untyped proposals.
pkg := types.NewPackage(pkgExport.Fix.StmtInfo.ImportPath, pkgExport.Fix.IdentName)
for _, export := range pkgExport.Exports {
score := stdScore + 0.01*float64(pkgExport.Fix.Relevance)
score := stdScore + 0.1*float64(pkgExport.Fix.Relevance)
c.found(ctx, candidate{
obj: types.NewVar(0, pkg, export, nil),
score: score,