Skip to content

Commit 54541a4

Browse files
committed
Do not resolve during annotate, enrich documentation with details
Also fixes: - #3201 - #3905
1 parent f8fce0d commit 54541a4

File tree

1 file changed

+48
-8
lines changed

1 file changed

+48
-8
lines changed

lsp-completion.el

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ This will help minimize popup flickering issue in `company-mode'."
172172
:_emacsStartPoint start-point)
173173
item))
174174
(propertize label
175+
'lsp-completion-unresolved-item item
175176
'lsp-completion-item item
176177
'lsp-sort-text sort-text?
177178
'lsp-completion-start-point start-point
@@ -248,9 +249,7 @@ The CLEANUP-FN will be called to cleanup."
248249
(defun lsp-completion--annotate (item)
249250
"Annotate ITEM detail."
250251
(-let (((completion-item &as &CompletionItem :detail? :kind? :label-details?)
251-
(get-text-property 0 'lsp-completion-item item)))
252-
(lsp-completion--resolve-async item #'ignore)
253-
252+
(get-text-property 0 'lsp-completion-unresolved-item item)))
254253
(concat (when (and lsp-completion-show-detail detail?)
255254
(concat " " (s-replace "\r" "" detail?)))
256255
(when (and lsp-completion-show-label-description label-details?)
@@ -459,11 +458,52 @@ The MARKERS and PREFIX value will be attached to each candidate."
459458

460459
(defun lsp-completion--get-documentation (item)
461460
"Get doc comment for completion ITEM."
462-
(-some->> item
463-
(lsp-completion--resolve)
464-
(get-text-property 0 'lsp-completion-item)
465-
(lsp:completion-item-documentation?)
466-
(lsp--render-element)))
461+
(-let* ((resolved (get-text-property 0 'lsp-completion-resolved item))
462+
(item (get-text-property
463+
0
464+
(if resolved
465+
'lsp-completion-item
466+
'lsp-completion-unresolved-item)
467+
item))
468+
((&CompletionItem :detail?
469+
:documentation?)
470+
item))
471+
472+
(unless (or resolved (and detail? documentation?))
473+
(setq item (lsp-completion--resolve item)
474+
resolved t))
475+
476+
(setq detail? (lsp:completion-item-detail? item)
477+
documentation? (lsp:completion-item-documentation? item))
478+
479+
(when (and detail? documentation?)
480+
(cond ((lsp-markup-content? documentation?)
481+
(-let (((&MarkupContent :kind :value) documentation?))
482+
(cond ((and (equal kind "plaintext")
483+
(not (string-match-p (regexp-quote detail?) value)))
484+
(lsp:set-markup-content-value
485+
documentation?
486+
(concat detail?
487+
(if (bound-and-true-p page-break-lines-mode)
488+
"\n \n"
489+
"\n\n")
490+
value)))
491+
((and (equal kind "markdown")
492+
(not (string-match-p (regexp-quote detail?) value)))
493+
(lsp:set-markup-content-value
494+
documentation?
495+
(concat "```\n" detail? "\n```\n---\n" value))))))
496+
497+
((and (stringp documentation?)
498+
(not (string-match-p (regexp-quote detail?) documentation?)))
499+
(setq documentation?
500+
(concat detail?
501+
(if (bound-and-true-p page-break-lines-mode)
502+
"\n \n"
503+
"\n\n")
504+
documentation?)))))
505+
506+
(lsp--render-element documentation?)))
467507

468508
(defun lsp-completion--get-context (trigger-characters same-session?)
469509
"Get completion context with provided TRIGGER-CHARACTERS and SAME-SESSION?."

0 commit comments

Comments
 (0)