From 85c5e15c9bd81e70b51393fcd6be07486eddcb15 Mon Sep 17 00:00:00 2001 From: James Ravn Date: Thu, 23 Apr 2020 18:34:54 +0100 Subject: [PATCH] Display the first line of MarkupContent in eldoc 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, https://github.com/microsoft/language-server-protocol/issues/772 should make this more reliable. --- lsp-mode.el | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lsp-mode.el b/lsp-mode.el index c960feefb48..e601c931717 100644 --- a/lsp-mode.el +++ b/lsp-mode.el @@ -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.