Skip to content

Commit 6ddee64

Browse files
committed
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Robert Findley <[email protected]>
1 parent d518495 commit 6ddee64

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

internal/lsp/source/hover.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ func FormatHover(h *HoverInformation, options Options) (string, error) {
390390
}
391391

392392
func formatLink(h *HoverInformation, options Options) string {
393-
if options.LinkTarget == "" || h.Link == "" {
393+
if !options.LinksInHover || options.LinkTarget == "" || h.Link == "" {
394394
return ""
395395
}
396396
plainLink := fmt.Sprintf("https://%s/%s", options.LinkTarget, h.Link)
@@ -403,6 +403,7 @@ func formatLink(h *HoverInformation, options Options) string {
403403
return plainLink
404404
}
405405
}
406+
406407
func formatDoc(doc string, options Options) string {
407408
if options.PreferredContentFormat == protocol.Markdown {
408409
return CommentToMarkdown(doc)

internal/lsp/source/options.go

+7
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ func DefaultOptions() Options {
115115
Env: os.Environ(),
116116
HoverKind: FullDocumentation,
117117
LinkTarget: "pkg.go.dev",
118+
LinksInHover: true,
118119
Matcher: Fuzzy,
119120
SymbolMatcher: SymbolFuzzy,
120121
DeepCompletion: true,
@@ -210,6 +211,9 @@ type UserOptions struct {
210211
// provided.
211212
LinkTarget string
212213

214+
// LinksInHover toggles the presence of links to documentation in hover.
215+
LinksInHover bool
216+
213217
// ImportShortcut specifies whether import statements should link to
214218
// documentation or go to definitions. The default is both.
215219
ImportShortcut ImportShortcut
@@ -526,6 +530,9 @@ func (o *Options) set(name string, value interface{}) OptionResult {
526530
case "linkTarget":
527531
result.setString(&o.LinkTarget)
528532

533+
case "linksInHover":
534+
result.setBool(&o.LinksInHover)
535+
529536
case "importShortcut":
530537
var s string
531538
result.setString(&s)

0 commit comments

Comments
 (0)