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