From 49a3e744a42570834b70bfa2a7308c73f5bc6bc3 Mon Sep 17 00:00:00 2001 From: Muir Manders Date: Fri, 13 Dec 2019 16:17:40 -0800 Subject: [PATCH] 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 TryBot-Result: Gobot Gobot Reviewed-by: Rebecca Stambler --- internal/lsp/source/completion_literal.go | 9 ++++++++- internal/lsp/testdata/snippets/literal_snippets.go.in | 2 +- internal/lsp/testdata/summary.txt.golden | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/internal/lsp/source/completion_literal.go b/internal/lsp/source/completion_literal.go index 7f62e57d30..858fc48d4e 100644 --- a/internal/lsp/source/completion_literal.go +++ b/internal/lsp/source/completion_literal.go @@ -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 diff --git a/internal/lsp/testdata/snippets/literal_snippets.go.in b/internal/lsp/testdata/snippets/literal_snippets.go.in index 7233b07e69..dfb210b63c 100644 --- a/internal/lsp/testdata/snippets/literal_snippets.go.in +++ b/internal/lsp/testdata/snippets/literal_snippets.go.in @@ -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\\}") diff --git a/internal/lsp/testdata/summary.txt.golden b/internal/lsp/testdata/summary.txt.golden index 7ca0e4203d..4695f20e43 100644 --- a/internal/lsp/testdata/summary.txt.golden +++ b/internal/lsp/testdata/summary.txt.golden @@ -1,5 +1,5 @@ -- summary -- -CompletionsCount = 222 +CompletionsCount = 223 CompletionSnippetCount = 53 UnimportedCompletionsCount = 4 DeepCompletionsCount = 5