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