diff --git a/internal/lsp/source/completion.go b/internal/lsp/source/completion.go index 788a528ebd9..342d095c64c 100644 --- a/internal/lsp/source/completion.go +++ b/internal/lsp/source/completion.go @@ -696,7 +696,10 @@ func (c *completer) lexical() error { } scopes = append(scopes, c.pkg.GetTypes().Scope(), types.Universe) - builtinIota := types.Universe.Lookup("iota") + var ( + builtinIota = types.Universe.Lookup("iota") + builtinNil = types.Universe.Lookup("nil") + ) // Track seen variables to avoid showing completions for shadowed variables. // This works since we look at scopes from innermost to outermost. @@ -736,10 +739,17 @@ func (c *completer) lexical() error { continue } + score := stdScore + + // Dowrank "nil" a bit so it is ranked below more interesting candidates. + if obj == builtinNil { + score /= 2 + } + // If we haven't already added a candidate for an object with this name. if _, ok := seen[obj.Name()]; !ok { seen[obj.Name()] = struct{}{} - c.found(obj, stdScore, nil) + c.found(obj, score, nil) } } } diff --git a/internal/lsp/testdata/builtins/builtins.go b/internal/lsp/testdata/builtins/builtins.go index d9d384313b9..25c29f21e6c 100644 --- a/internal/lsp/testdata/builtins/builtins.go +++ b/internal/lsp/testdata/builtins/builtins.go @@ -1,7 +1,7 @@ package builtins func _() { - //@complete("", append, bool, byte, cap, close, complex, complex128, complex64, copy, delete, error, _false, float32, float64, imag, int, int16, int32, int64, int8, len, make, new, _nil, panic, print, println, real, recover, rune, string, _true, uint, uint16, uint32, uint64, uint8, uintptr) + //@complete("", append, bool, byte, cap, close, complex, complex128, complex64, copy, delete, error, _false, float32, float64, imag, int, int16, int32, int64, int8, len, make, new, panic, print, println, real, recover, rune, string, _true, uint, uint16, uint32, uint64, uint8, uintptr, _nil) } /* Create markers for builtin types. Only for use by this test.