From f26c0dd9827dd9101d2f009d372f9ec43be250ed Mon Sep 17 00:00:00 2001 From: Muir Manders Date: Thu, 30 Apr 2020 14:38:17 -0700 Subject: [PATCH] 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 TryBot-Result: Gobot Gobot Reviewed-by: Heschi Kreinick --- internal/lsp/source/completion.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/lsp/source/completion.go b/internal/lsp/source/completion.go index 33dcaab9e1..9b6d1902d0 100644 --- a/internal/lsp/source/completion.go +++ b/internal/lsp/source/completion.go @@ -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,