internal/lsp/source: respect user's hover kind in signature help

I had originally wanted to create a shared code path for hover in all
cases, but hover has a lot more differences from the documentation in
signature help and completion than I expected. You can't use markdown,
and you probably don't want links--it would take a bigger refactor to
extract something that worked for each feature.

Handling the Structured and SingleLine hover setting also doesn't seem
necessary--those settings are really specific to the way the client
presents the hover, which isn't related to signature help or completion.

For completion, all we need is an extra check on the hover kind for the
NoDocumentation option.

Fixes golang/go#38577

Change-Id: Ib2037906c13f5be26813fcd2c20989e4d1b6c9bd
Reviewed-on: https://go-review.googlesource.com/c/tools/+/266139
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Trust: Rebecca Stambler <rstambler@golang.org>
diff --git a/internal/lsp/source/completion/completion.go b/internal/lsp/source/completion/completion.go
index 417b287..78dac5b 100644
--- a/internal/lsp/source/completion/completion.go
+++ b/internal/lsp/source/completion/completion.go
@@ -510,7 +510,7 @@
 		opts: &completionOptions{
 			matcher:           opts.Matcher,
 			unimported:        opts.CompleteUnimported,
-			documentation:     opts.CompletionDocumentation,
+			documentation:     opts.CompletionDocumentation && opts.HoverKind != source.NoDocumentation,
 			fullDocumentation: opts.HoverKind == source.FullDocumentation,
 			placeholders:      opts.UsePlaceholders,
 			literal:           opts.LiteralCompletions && opts.InsertTextFormat == protocol.SnippetTextFormat,
diff --git a/internal/lsp/source/signature_help.go b/internal/lsp/source/signature_help.go
index b49880d..03ac4e8 100644
--- a/internal/lsp/source/signature_help.go
+++ b/internal/lsp/source/signature_help.go
@@ -7,7 +7,6 @@
 import (
 	"context"
 	"go/ast"
-	"go/doc"
 	"go/token"
 	"go/types"
 
@@ -123,7 +122,7 @@
 	}
 	return &protocol.SignatureInformation{
 		Label:         name + s.Format(),
-		Documentation: doc.Synopsis(s.doc),
+		Documentation: s.doc,
 		Parameters:    paramInfo,
 	}, activeParam, nil
 }
@@ -140,7 +139,7 @@
 	activeParam := activeParameter(callExpr, len(sig.params), sig.variadic, pos)
 	return &protocol.SignatureInformation{
 		Label:         sig.name + sig.Format(),
-		Documentation: doc.Synopsis(sig.doc),
+		Documentation: sig.doc,
 		Parameters:    paramInfo,
 	}, activeParam, nil
 
diff --git a/internal/lsp/source/types_format.go b/internal/lsp/source/types_format.go
index 2455bdf..5ddd8e0 100644
--- a/internal/lsp/source/types_format.go
+++ b/internal/lsp/source/types_format.go
@@ -9,6 +9,7 @@
 	"context"
 	"fmt"
 	"go/ast"
+	"go/doc"
 	"go/printer"
 	"go/token"
 	"go/types"
@@ -79,8 +80,8 @@
 
 // NewBuiltinSignature returns signature for the builtin object with a given
 // name, if a builtin object with the name exists.
-func NewBuiltinSignature(ctx context.Context, snapshot Snapshot, name string) (*signature, error) {
-	builtin, err := snapshot.BuiltinPackage(ctx)
+func NewBuiltinSignature(ctx context.Context, s Snapshot, name string) (*signature, error) {
+	builtin, err := s.BuiltinPackage(ctx)
 	if err != nil {
 		return nil, err
 	}
@@ -103,10 +104,17 @@
 			variadic = true
 		}
 	}
-	params, _ := formatFieldList(ctx, snapshot, decl.Type.Params, variadic)
-	results, needResultParens := formatFieldList(ctx, snapshot, decl.Type.Results, false)
+	params, _ := formatFieldList(ctx, s, decl.Type.Params, variadic)
+	results, needResultParens := formatFieldList(ctx, s, decl.Type.Results, false)
+	d := decl.Doc.Text()
+	switch s.View().Options().HoverKind {
+	case SynopsisDocumentation:
+		d = doc.Synopsis(d)
+	case NoDocumentation:
+		d = ""
+	}
 	return &signature{
-		doc:              decl.Doc.Text(),
+		doc:              d,
 		name:             name,
 		needResultParens: needResultParens,
 		params:           params,
@@ -188,12 +196,18 @@
 			results = append(results, el.Name()+" "+typ)
 		}
 	}
-	var doc string
+	var d string
 	if comment != nil {
-		doc = comment.Text()
+		d = comment.Text()
+	}
+	switch s.View().Options().HoverKind {
+	case SynopsisDocumentation:
+		d = doc.Synopsis(d)
+	case NoDocumentation:
+		d = ""
 	}
 	return &signature{
-		doc:              doc,
+		doc:              d,
 		params:           params,
 		results:          results,
 		variadic:         sig.Variadic(),