Skip to content

Commit

Permalink
cache adjusted documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
wyuenho committed Nov 27, 2024
1 parent 9ac1584 commit e30d4dd
Showing 1 changed file with 57 additions and 46 deletions.
103 changes: 57 additions & 46 deletions lsp-completion.el
Original file line number Diff line number Diff line change
Expand Up @@ -454,52 +454,63 @@ The MARKERS and PREFIX value will be attached to each candidate."

(defun lsp-completion--get-documentation (item)
"Get doc comment for completion ITEM."
(-let* ((resolved (get-text-property 0 'lsp-completion-resolved item))
(item (get-text-property
0
(if resolved
'lsp-completion-item
'lsp-completion-unresolved-item)
item))
((&CompletionItem :detail?
:documentation?)
item))

(unless (or resolved (and detail? documentation?))
(setq item (lsp-completion--resolve item)
resolved t))

(setq detail? (lsp:completion-item-detail? item)
documentation? (lsp:completion-item-documentation? item))

(when (and detail? documentation?)
(cond ((lsp-markup-content? documentation?)
(-let (((&MarkupContent :kind :value) documentation?))
(cond ((and (equal kind "plaintext")
(not (string-match-p (regexp-quote detail?) value)))
(lsp:set-markup-content-value
documentation?
(concat detail?
(if (bound-and-true-p page-break-lines-mode)
"\n \n"
"\n\n")
value)))
((and (equal kind "markdown")
(not (string-match-p (regexp-quote detail?) value)))
(lsp:set-markup-content-value
documentation?
(concat "```\n" detail? "\n```\n---\n" value))))))

((and (stringp documentation?)
(not (string-match-p (regexp-quote detail?) documentation?)))
(setq documentation?
(concat detail?
(if (bound-and-true-p page-break-lines-mode)
"\n \n"
"\n\n")
documentation?)))))

(lsp--render-element documentation?)))
(or (get-text-property 0 'lsp-completion-item-doc item)
(-let* ((unresolved-item (get-text-property 0 'lsp-completion-unresolved-item item))
(has-unresolved-detail (lsp:completion-item-detail? unresolved-item))
(resolved (get-text-property 0 'lsp-completion-resolved item))
(completion-item (if resolved
(get-text-property 0 'lsp-completion-item item)
unresolved-item))
((&CompletionItem :detail?
:documentation?)
completion-item))

(unless (or resolved (and detail? documentation?))
(setq completion-item (get-text-property 0 'lsp-completion-item (lsp-completion--resolve item))
resolved t))

(setq detail? (lsp:completion-item-detail? completion-item)
documentation? (lsp:completion-item-documentation? completion-item))

(let ((doc
(if (and (null has-unresolved-detail) detail? documentation?)
;; detail was resolved, that means the candidate list has no
;; detail, so we may need to prepend it to the documentation
(cond ((lsp-markup-content? documentation?)
(-let (((&MarkupContent :kind :value) documentation?))
(cond ((and (equal kind "plaintext")
(not (string-match-p (regexp-quote detail?) value)))

(lsp--render-string
(concat detail?
(if (bound-and-true-p page-break-lines-mode)
"\n \n"
"\n\n")
value)
kind))

((and (equal kind "markdown")
(not (string-match-p (regexp-quote detail?) value)))

(lsp--render-string
(concat "```\n" detail? "\n```\n---\n" value)
kind)))))

((and (stringp documentation?)
(not (string-match-p (regexp-quote detail?) documentation?)))

(lsp--render-string
(concat detail?
(if (bound-and-true-p page-break-lines-mode)
"\n \n"
"\n\n")
documentation?)
"plaintext")))

(lsp--render-element documentation?))))

(put-text-property 0 (length item) 'lsp-completion-item-doc doc item)
doc))))

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

0 comments on commit e30d4dd

Please sign in to comment.