Skip to content

Commit

Permalink
Display the first line of MarkupContent in eldoc
Browse files Browse the repository at this point in the history
Many LSP servers, like gopls, return `document/onHover` as
MarkupContent. This modifies the eldoc behavior to support MarkupContent
by displaying the first rendered line. As the majority of LSP servers
return the signature, this will display the signature as most people expect.

In the future,
microsoft/language-server-protocol#772
should make this more reliable.
  • Loading branch information
jsravn committed Apr 23, 2020
1 parent d89f403 commit 85c5e15
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lsp-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -4715,9 +4715,11 @@ CONTENTS - MarkedString | MarkedString[] | MarkupContent
RENDER-ALL - nil if only the signature should be rendered."
(cond
((and (hash-table-p contents) (gethash "kind" contents))
;; MarkupContent, deprecated by LSP but actually very flexible.
;; It tends to be long and is not suitable in echo area.
(if render-all (lsp--render-element contents) ""))
;; MarkupContent.
;; It tends to be long and is not suitable to display fully in the echo area.
;; Just display the first line which is typically the signature.
(let ((rendered (lsp--render-element contents)))
(if render-all rendered (car (split-string rendered "\n")))))
((and (stringp contents) (not (string-match-p "\n" contents)))
;; If the contents is a single string containing a single line,
;; render it always.
Expand Down

0 comments on commit 85c5e15

Please sign in to comment.