mirror of
https://github.com/golang/go
synced 2024-11-18 18:44:42 -07: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:
parent
7201abb308
commit
a222fb47e2
@ -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
|
||||
|
@ -11,3 +11,9 @@ func _() {
|
||||
|
||||
iota //@complete(" //", iotaVar)
|
||||
}
|
||||
|
||||
func _() {
|
||||
var twoRedUpEnd bool //@item(TRUEVar, "twoRedUpEnd", "bool", "var")
|
||||
|
||||
var _ bool = true //@rank(" //", _true, TRUEVar)
|
||||
}
|
2
internal/lsp/testdata/summary.txt.golden
vendored
2
internal/lsp/testdata/summary.txt.golden
vendored
@ -4,7 +4,7 @@ CompletionSnippetCount = 61
|
||||
UnimportedCompletionsCount = 4
|
||||
DeepCompletionsCount = 5
|
||||
FuzzyCompletionsCount = 8
|
||||
RankedCompletionsCount = 32
|
||||
RankedCompletionsCount = 33
|
||||
CaseSensitiveCompletionsCount = 4
|
||||
DiagnosticsCount = 35
|
||||
FoldingRangesCount = 2
|
||||
|
Loading…
Reference in New Issue
Block a user