internal/lsp: remove useless signature cast completion candidate

In a previous change I inadvertently added completion candidates like:

var f func(int)
f = <> // useless candidate "func(int)(<>)"

Ignoring the fact it is a syntax error without more parens around the
signature, it isn't a useful candidate because you don't need to cast
when assigning a named signature type to an unnamed type.

Change-Id: Ic261817af344ee47193240a11dca5d3a32cbd293
Reviewed-on: https://go-review.googlesource.com/c/tools/+/211319
Run-TryBot: Muir Manders <muir@mnd.rs>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
This commit is contained in:
Muir Manders 2019-12-13 16:17:40 -08:00 committed by Rebecca Stambler
parent 04c2e8eff9
commit 49a3e744a4
3 changed files with 10 additions and 3 deletions

View File

@ -125,7 +125,14 @@ func (c *completer) literal(literalType types.Type, imp *importInfo) {
switch t := literalType.Underlying().(type) {
case *types.Struct, *types.Array, *types.Slice, *types.Map:
c.compositeLiteral(t, typeName, float64(score), addlEdits)
case *types.Basic, *types.Signature:
case *types.Signature:
// Add a literal completion for a signature type that implements
// an interface. For example, offer "http.HandlerFunc()" when
// expected type is "http.Handler".
if isInterface(expType) {
c.basicLiteral(t, typeName, float64(score), addlEdits)
}
case *types.Basic:
// Add a literal completion for basic types that implement our
// expected interface (e.g. named string type http.Dir
// implements http.FileSystem), or are identical to our expected

View File

@ -125,7 +125,7 @@ func _() {
func _() {
_ = "func(...) {}" //@item(litFunc, "func(...) {}", "", "var")
sort.Slice(nil, f) //@snippet(")", litFunc, "func(i, j int) bool {$0\\}", "func(i, j int) bool {$0\\}")
sort.Slice(nil, fun) //@complete(")", litFunc),snippet(")", litFunc, "func(i, j int) bool {$0\\}", "func(i, j int) bool {$0\\}")
http.HandleFunc("", f) //@snippet(")", litFunc, "", "func(${1:rw} http.ResponseWriter, ${2:r} *http.Request) {$0\\}")

View File

@ -1,5 +1,5 @@
-- summary --
CompletionsCount = 222
CompletionsCount = 223
CompletionSnippetCount = 53
UnimportedCompletionsCount = 4
DeepCompletionsCount = 5