diff --git a/internal/lsp/source/completion.go b/internal/lsp/source/completion.go index 43f5d797f48..4aff81bf0b4 100644 --- a/internal/lsp/source/completion.go +++ b/internal/lsp/source/completion.go @@ -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 diff --git a/internal/lsp/testdata/builtins/iota.go b/internal/lsp/testdata/builtins/constants.go similarity index 59% rename from internal/lsp/testdata/builtins/iota.go rename to internal/lsp/testdata/builtins/constants.go index 44427245965..7ad07bd1f3a 100644 --- a/internal/lsp/testdata/builtins/iota.go +++ b/internal/lsp/testdata/builtins/constants.go @@ -11,3 +11,9 @@ func _() { iota //@complete(" //", iotaVar) } + +func _() { + var twoRedUpEnd bool //@item(TRUEVar, "twoRedUpEnd", "bool", "var") + + var _ bool = true //@rank(" //", _true, TRUEVar) +} diff --git a/internal/lsp/testdata/summary.txt.golden b/internal/lsp/testdata/summary.txt.golden index 33ac397edaf..25d58cebe2f 100644 --- a/internal/lsp/testdata/summary.txt.golden +++ b/internal/lsp/testdata/summary.txt.golden @@ -4,7 +4,7 @@ CompletionSnippetCount = 61 UnimportedCompletionsCount = 4 DeepCompletionsCount = 5 FuzzyCompletionsCount = 8 -RankedCompletionsCount = 32 +RankedCompletionsCount = 33 CaseSensitiveCompletionsCount = 4 DiagnosticsCount = 35 FoldingRangesCount = 2