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>
This commit is contained in:
Rebecca Stambler 2020-07-16 22:18:40 -04:00
parent d518495ee8
commit 6ddee64345
2 changed files with 9 additions and 1 deletions

View File

@ -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)

View File

@ -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)