internal/lsp: add a configuration to enable/disable links in hover

I had previously suggested that users set LinkTarget to "" to avoid
links in the hover text. However, this work-around isn't perfect because
it also disables the documentLink behavior in other cases.

Change-Id: I3df948e2a2e4d2312998de65ccea8dfb404768ab
Reviewed-on: https://go-review.googlesource.com/c/tools/+/243239
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
diff --git a/internal/lsp/source/hover.go b/internal/lsp/source/hover.go
index 2423010..a3ddc89 100644
--- a/internal/lsp/source/hover.go
+++ b/internal/lsp/source/hover.go
@@ -390,7 +390,7 @@
 }
 
 func formatLink(h *HoverInformation, options Options) string {
-	if options.LinkTarget == "" || h.Link == "" {
+	if !options.LinksInHover || options.LinkTarget == "" || h.Link == "" {
 		return ""
 	}
 	plainLink := fmt.Sprintf("https://%s/%s", options.LinkTarget, h.Link)
@@ -403,6 +403,7 @@
 		return plainLink
 	}
 }
+
 func formatDoc(doc string, options Options) string {
 	if options.PreferredContentFormat == protocol.Markdown {
 		return CommentToMarkdown(doc)
diff --git a/internal/lsp/source/options.go b/internal/lsp/source/options.go
index 5d378cf..c59d4d3 100644
--- a/internal/lsp/source/options.go
+++ b/internal/lsp/source/options.go
@@ -115,6 +115,7 @@
 			Env:                     os.Environ(),
 			HoverKind:               FullDocumentation,
 			LinkTarget:              "pkg.go.dev",
+			LinksInHover:            true,
 			Matcher:                 Fuzzy,
 			SymbolMatcher:           SymbolFuzzy,
 			DeepCompletion:          true,
@@ -210,6 +211,9 @@
 	// provided.
 	LinkTarget string
 
+	// LinksInHover toggles the presence of links to documentation in hover.
+	LinksInHover bool
+
 	// ImportShortcut specifies whether import statements should link to
 	// documentation or go to definitions. The default is both.
 	ImportShortcut ImportShortcut
@@ -526,6 +530,9 @@
 	case "linkTarget":
 		result.setString(&o.LinkTarget)
 
+	case "linksInHover":
+		result.setBool(&o.LinksInHover)
+
 	case "importShortcut":
 		var s string
 		result.setString(&s)