From 6ddee64345a6aa3330ff5260ce9366cd8b2462e8 Mon Sep 17 00:00:00 2001 From: Rebecca Stambler Date: Thu, 16 Jul 2020 22:18:40 -0400 Subject: [PATCH] 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 TryBot-Result: Gobot Gobot Reviewed-by: Robert Findley --- internal/lsp/source/hover.go | 3 ++- internal/lsp/source/options.go | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/internal/lsp/source/hover.go b/internal/lsp/source/hover.go index 2423010935c..a3ddc89ef37 100644 --- a/internal/lsp/source/hover.go +++ b/internal/lsp/source/hover.go @@ -390,7 +390,7 @@ func FormatHover(h *HoverInformation, options Options) (string, error) { } 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 @@ func formatLink(h *HoverInformation, options Options) string { 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 5d378cf3874..c59d4d3c655 100644 --- a/internal/lsp/source/options.go +++ b/internal/lsp/source/options.go @@ -115,6 +115,7 @@ func DefaultOptions() Options { Env: os.Environ(), HoverKind: FullDocumentation, LinkTarget: "pkg.go.dev", + LinksInHover: true, Matcher: Fuzzy, SymbolMatcher: SymbolFuzzy, DeepCompletion: true, @@ -210,6 +211,9 @@ type UserOptions struct { // 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 @@ func (o *Options) set(name string, value interface{}) OptionResult { case "linkTarget": result.setString(&o.LinkTarget) + case "linksInHover": + result.setBool(&o.LinksInHover) + case "importShortcut": var s string result.setString(&s)