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