From 0d62d4405efdf3c61df550e92d30bf970ec579bf Mon Sep 17 00:00:00 2001 From: Rebecca Stambler Date: Mon, 12 Aug 2019 15:51:32 -0400 Subject: [PATCH] internal/lsp: change ordering of hover depending on hoverKind This change configures the ordering of documentation on hover. If the user has requested full documentation, the signature appears at the top, to avoid the user having to scroll. Otherwise, the signature appears at the bottom, to minimize the distance between the triggering identifier and the signature. Updates golang/go#33352 Change-Id: I017baaabd0ee0c31cb13cb6abdda296782929823 Reviewed-on: https://go-review.googlesource.com/c/tools/+/189943 Run-TryBot: Rebecca Stambler Reviewed-by: Ian Cottrell --- internal/lsp/source/hover.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/internal/lsp/source/hover.go b/internal/lsp/source/hover.go index 45667031d1..d0e6841f38 100644 --- a/internal/lsp/source/hover.go +++ b/internal/lsp/source/hover.go @@ -45,9 +45,13 @@ func (i *IdentifierInfo) Hover(ctx context.Context, markdownSupported bool, hove return "", err } var b strings.Builder - if comment := formatDocumentation(h.comment, hoverKind); comment != "" { - b.WriteString(comment) - b.WriteRune('\n') + + // Add documentation to the top if the HoverKind is anything other than full documentation. + if hoverKind != FullDocumentation { + if comment := formatDocumentation(h.comment, hoverKind); comment != "" { + b.WriteString(comment) + b.WriteRune('\n') + } } if markdownSupported { b.WriteString("```go\n") @@ -63,6 +67,13 @@ func (i *IdentifierInfo) Hover(ctx context.Context, markdownSupported bool, hove if markdownSupported { b.WriteString("\n```") } + // Add documentation to the bottom if the HoverKind is full documentation. + if hoverKind == FullDocumentation { + if comment := formatDocumentation(h.comment, hoverKind); comment != "" { + b.WriteRune('\n') + b.WriteString(comment) + } + } return b.String(), nil }