1
0
mirror of https://github.com/golang/go synced 2024-09-30 22:58:34 -06:00

internal/lsp/source: don't downrank builtin constant completions

We downrank untyped constant candidates so that we prefer candidates
whose type matches exactly. However, this was causing builtin
constants like "true" to be outranked by candidates that fuzzily match
"true". Fix by not downranking builtin constants.

Fixes golang/go#36363.

Change-Id: I14801688c96efdbb7ff9fee69f66028530df984c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/213137
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Muir Manders 2020-01-02 13:26:21 -08:00 committed by Rebecca Stambler
parent 7201abb308
commit a222fb47e2
3 changed files with 11 additions and 5 deletions

View File

@ -1665,10 +1665,10 @@ func (c *completer) matchingCandidate(cand *candidate) bool {
// This doesn't take into account the constant value, so there will be some
// false positives due to integer sign and overflow.
if candBasic.Info()&types.IsConstType == wantBasic.Info()&types.IsConstType {
// Lower candidate score if the types are not identical.
// This avoids ranking untyped integer constants above
// candidates with an exact type match.
if !types.Identical(candType, expType) {
// Lower candidate score if the types are not identical. This avoids
// ranking untyped constants above candidates with an exact type
// match. Don't lower score of builtin constants (e.g. "true").
if !types.Identical(candType, expType) && cand.obj.Parent() != types.Universe {
cand.score /= 2
}
return true

View File

@ -11,3 +11,9 @@ func _() {
iota //@complete(" //", iotaVar)
}
func _() {
var twoRedUpEnd bool //@item(TRUEVar, "twoRedUpEnd", "bool", "var")
var _ bool = true //@rank(" //", _true, TRUEVar)
}

View File

@ -4,7 +4,7 @@ CompletionSnippetCount = 61
UnimportedCompletionsCount = 4
DeepCompletionsCount = 5
FuzzyCompletionsCount = 8
RankedCompletionsCount = 32
RankedCompletionsCount = 33
CaseSensitiveCompletionsCount = 4
DiagnosticsCount = 35
FoldingRangesCount = 2