@@ -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
@@ -245,9 +246,7 @@ The CLEANUP-FN will be called to cleanup."
245246(defun lsp-completion--annotate (item )
246247 " Annotate ITEM detail."
247248 (-let (((completion-item &as &CompletionItem :detail? :kind? :label-details? )
248- (get-text-property 0 'lsp-completion-item item)))
249- (lsp-completion--resolve-async item #'ignore )
250-
249+ (get-text-property 0 'lsp-completion-unresolved-item item)))
251250 (concat (when (and lsp-completion-show-detail detail?)
252251 (concat " " (s-replace " \r " " " detail?) ))
253252 (when (and lsp-completion-show-label-description label-details?)
@@ -456,11 +455,52 @@ The MARKERS and PREFIX value will be attached to each candidate."
456455
457456(defun lsp-completion--get-documentation (item )
458457 " Get doc comment for completion ITEM."
459- (-some->> item
460- (lsp-completion--resolve)
461- (get-text-property 0 'lsp-completion-item )
462- (lsp:completion-item-documentation?)
463- (lsp--render-element)))
458+ (-let* ((resolved (get-text-property 0 'lsp-completion-resolved item))
459+ (item (get-text-property
460+ 0
461+ (if resolved
462+ 'lsp-completion-item
463+ 'lsp-completion-unresolved-item )
464+ item))
465+ ((&CompletionItem :detail?
466+ :documentation? )
467+ item))
468+
469+ (unless (or resolved (and detail? documentation?) )
470+ (setq item (lsp-completion--resolve item)
471+ resolved t ))
472+
473+ (setq detail? (lsp:completion-item-detail? item)
474+ documentation? (lsp:completion-item-documentation? item))
475+
476+ (when (and detail? documentation?)
477+ (cond ((lsp-markup-content? documentation?)
478+ (-let (((&MarkupContent :kind :value ) documentation?) )
479+ (cond ((and (equal kind " plaintext" )
480+ (not (string-match-p (regexp-quote detail?) value)))
481+ (lsp:set-markup-content-value
482+ documentation?
483+ (concat detail?
484+ (if (bound-and-true-p page-break-lines-mode)
485+ " \n \n "
486+ " \n\n " )
487+ value)))
488+ ((and (equal kind " markdown" )
489+ (not (string-match-p (regexp-quote detail?) value)))
490+ (lsp:set-markup-content-value
491+ documentation?
492+ (concat " ```\n " detail? " \n ```\n ---\n " value))))))
493+
494+ ((and (stringp documentation?)
495+ (not (string-match-p (regexp-quote detail?) documentation?) ))
496+ (setq documentation?
497+ (concat detail?
498+ (if (bound-and-true-p page-break-lines-mode)
499+ " \n \n "
500+ " \n\n " )
501+ documentation?) ))))
502+
503+ (lsp--render-element documentation?) ))
464504
465505(defun lsp-completion--get-context (trigger-characters same-session? )
466506 " Get completion context with provided TRIGGER-CHARACTERS and SAME-SESSION?."
0 commit comments