@@ -455,52 +455,63 @@ The MARKERS and PREFIX value will be attached to each candidate."
455455
456456(defun lsp-completion--get-documentation (item )
457457 " Get doc comment for completion ITEM."
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?) ))
458+ (or (get-text-property 0 'lsp-completion-item-doc item)
459+ (-let* ((unresolved-item (get-text-property 0 'lsp-completion-unresolved-item item))
460+ (has-unresolved-detail (lsp:completion-item-detail? unresolved-item))
461+ (resolved (get-text-property 0 'lsp-completion-resolved item))
462+ (completion-item (if resolved
463+ (get-text-property 0 'lsp-completion-item item)
464+ unresolved-item))
465+ ((&CompletionItem :detail?
466+ :documentation? )
467+ completion-item))
468+
469+ (unless (or resolved (and detail? documentation?) )
470+ (setq completion-item (get-text-property 0 'lsp-completion-item (lsp-completion--resolve item))
471+ resolved t ))
472+
473+ (setq detail? (lsp:completion-item-detail? completion-item)
474+ documentation? (lsp:completion-item-documentation? completion-item))
475+
476+ (let ((doc
477+ (if (and (null has-unresolved-detail) detail? documentation?)
478+ ; ; detail was resolved, that means the candidate list has no
479+ ; ; detail, so we may need to prepend it to the 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+
485+ (lsp--render-string
486+ (concat detail?
487+ (if (bound-and-true-p page-break-lines-mode)
488+ " \n \n "
489+ " \n\n " )
490+ value)
491+ kind))
492+
493+ ((and (equal kind " markdown" )
494+ (not (string-match-p (regexp-quote detail?) value)))
495+
496+ (lsp--render-string
497+ (concat " ```\n " detail? " \n ```\n ---\n " value)
498+ kind)))))
499+
500+ ((and (stringp documentation?)
501+ (not (string-match-p (regexp-quote detail?) documentation?) ))
502+
503+ (lsp--render-string
504+ (concat detail?
505+ (if (bound-and-true-p page-break-lines-mode)
506+ " \n \n "
507+ " \n\n " )
508+ documentation?)
509+ " plaintext" )))
510+
511+ (lsp--render-element documentation?) )))
512+
513+ (put-text-property 0 (length item) 'lsp-completion-item-doc doc item)
514+ doc))))
504515
505516(defun lsp-completion--get-context (trigger-characters same-session? )
506517 " Get completion context with provided TRIGGER-CHARACTERS and SAME-SESSION?."
0 commit comments