Skip to content

Commit

Permalink
internal/lsp: add a configuration to enable/disable links in hover
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
stamblerre committed Jul 17, 2020
1 parent d518495 commit 6ddee64
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion internal/lsp/source/hover.go
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions internal/lsp/source/options.go
Expand Up @@ -115,6 +115,7 @@ func DefaultOptions() Options {
Env: os.Environ(),
HoverKind: FullDocumentation,
LinkTarget: "pkg.go.dev",
LinksInHover: true,
Matcher: Fuzzy,
SymbolMatcher: SymbolFuzzy,
DeepCompletion: true,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 6ddee64

Please sign in to comment.