From e79506f5ed3d77dc2c308521dc389c2a15853b1a Mon Sep 17 00:00:00 2001 From: Jimmy Yuen Ho Wong Date: Tue, 26 Nov 2024 22:13:58 +0000 Subject: [PATCH 01/12] Do not resolve during annotate, enrich documentation with details Also fixes: - #3201 - #3905 --- lsp-completion.el | 56 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 48 insertions(+), 8 deletions(-) diff --git a/lsp-completion.el b/lsp-completion.el index a835eac6d6..90b0f4fd07 100644 --- a/lsp-completion.el +++ b/lsp-completion.el @@ -172,6 +172,7 @@ This will help minimize popup flickering issue in `company-mode'." :_emacsStartPoint start-point) item)) (propertize label + 'lsp-completion-unresolved-item item 'lsp-completion-item item 'lsp-sort-text sort-text? 'lsp-completion-start-point start-point @@ -248,9 +249,7 @@ The CLEANUP-FN will be called to cleanup." (defun lsp-completion--annotate (item) "Annotate ITEM detail." (-let (((completion-item &as &CompletionItem :detail? :kind? :label-details?) - (get-text-property 0 'lsp-completion-item item))) - (lsp-completion--resolve-async item #'ignore) - + (get-text-property 0 'lsp-completion-unresolved-item item))) (concat (when (and lsp-completion-show-detail detail?) (concat " " (s-replace "\r" "" detail?))) (when (and lsp-completion-show-label-description label-details?) @@ -459,11 +458,52 @@ The MARKERS and PREFIX value will be attached to each candidate." (defun lsp-completion--get-documentation (item) "Get doc comment for completion ITEM." - (-some->> item - (lsp-completion--resolve) - (get-text-property 0 'lsp-completion-item) - (lsp:completion-item-documentation?) - (lsp--render-element))) + (-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?))) (defun lsp-completion--get-context (trigger-characters same-session?) "Get completion context with provided TRIGGER-CHARACTERS and SAME-SESSION?." From 6e613089dfd5727cd274ec71ad57c5320ef8807b Mon Sep 17 00:00:00 2001 From: Jimmy Yuen Ho Wong Date: Wed, 27 Nov 2024 18:20:16 +0000 Subject: [PATCH 02/12] cache adjusted documentation --- lsp-completion.el | 103 +++++++++++++++++++++++++--------------------- 1 file changed, 57 insertions(+), 46 deletions(-) diff --git a/lsp-completion.el b/lsp-completion.el index 90b0f4fd07..7e27409173 100644 --- a/lsp-completion.el +++ b/lsp-completion.el @@ -458,52 +458,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?." From 830ccf4b3116c9eae82404edc8fccb8ac8a030c2 Mon Sep 17 00:00:00 2001 From: Jimmy Yuen Ho Wong Date: Thu, 28 Nov 2024 16:34:50 +0000 Subject: [PATCH 03/12] Make lsp-completion--resolve[-async] public --- lsp-completion.el | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lsp-completion.el b/lsp-completion.el index 7e27409173..bfebc9a959 100644 --- a/lsp-completion.el +++ b/lsp-completion.el @@ -190,7 +190,7 @@ See #2675" (unless (lsp-get data :for_ref) (lsp-put data :for_ref :json-false))))) -(defun lsp-completion--resolve (item) +(defun lsp-completion-resolve (item) "Resolve completion ITEM. ITEM can be string or a CompletionItem" (cl-assert item nil "Completion item must not be nil") @@ -215,7 +215,9 @@ ITEM can be string or a CompletionItem" item)) (_ completion-item))))) -(defun lsp-completion--resolve-async (item callback &optional cleanup-fn) +(defalias 'lsp-completion--resolve 'lsp-completion-resolve) + +(defun lsp-completion-resolve-async (item callback &optional cleanup-fn) "Resolve completion ITEM asynchronously with CALLBACK. The CLEANUP-FN will be called to cleanup." (cl-assert item nil "Completion item must not be nil") @@ -246,6 +248,8 @@ The CLEANUP-FN will be called to cleanup." (funcall callback completion-item) (when cleanup-fn (funcall cleanup-fn)))))) +(defalias 'lsp-completion--resolve-async 'lsp-completion-resolve-async) + (defun lsp-completion--annotate (item) "Annotate ITEM detail." (-let (((completion-item &as &CompletionItem :detail? :kind? :label-details?) @@ -470,7 +474,7 @@ The MARKERS and PREFIX value will be attached to each candidate." completion-item)) (unless (or resolved (and detail? documentation?)) - (setq completion-item (get-text-property 0 'lsp-completion-item (lsp-completion--resolve item)) + (setq completion-item (get-text-property 0 'lsp-completion-item (lsp-completion-resolve item)) resolved t)) (setq detail? (lsp:completion-item-detail? completion-item) @@ -675,7 +679,7 @@ Others: CANDIDATES" ;; see #3498 typescript-language-server does not provide the ;; proper insertText without resolving. (if (lsp-completion--find-workspace 'ts-ls) - (lsp-completion--resolve candidate) + (lsp-completion-resolve candidate) candidate)) ((&plist 'lsp-completion-item item 'lsp-completion-start-point start-point @@ -717,14 +721,14 @@ Others: CANDIDATES" (not (seq-empty-p additional-text-edits?))) (lsp--apply-text-edits additional-text-edits? 'completion) (-let [(callback cleanup-fn) (lsp--create-apply-text-edits-handlers)] - (lsp-completion--resolve-async + (lsp-completion-resolve-async item (-compose callback #'lsp:completion-item-additional-text-edits?) cleanup-fn)))) (if (or resolved command?) (when command? (lsp--execute-command command?)) - (lsp-completion--resolve-async + (lsp-completion-resolve-async item (-lambda ((&CompletionItem? :command?)) (when command? (lsp--execute-command command?))))) From 2cd60334229edf6e52049628cc722efcbc98e293 Mon Sep 17 00:00:00 2001 From: Jimmy Yuen Ho Wong Date: Sun, 1 Dec 2024 00:16:45 +0000 Subject: [PATCH 04/12] Resolved detail may be different from unresolved detail --- lsp-completion.el | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/lsp-completion.el b/lsp-completion.el index bfebc9a959..1ecfdd697c 100644 --- a/lsp-completion.el +++ b/lsp-completion.el @@ -463,25 +463,11 @@ The MARKERS and PREFIX value will be attached to each candidate." (defun lsp-completion--get-documentation (item) "Get doc comment for completion ITEM." (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? + (-let* (((&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?) + (get-text-property 0 'lsp-completion-item (lsp-completion-resolve item))) + (doc + (if (and 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?) @@ -517,8 +503,8 @@ The MARKERS and PREFIX value will be attached to each candidate." (lsp--render-element documentation?)))) - (put-text-property 0 (length item) 'lsp-completion-item-doc doc item) - doc)))) + (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?." From 1f34f8fd3736dce17cf65b6e73d2634a91734519 Mon Sep 17 00:00:00 2001 From: Jimmy Yuen Ho Wong Date: Sun, 1 Dec 2024 00:17:29 +0000 Subject: [PATCH 05/12] Do not fontify detail in documentation --- lsp-completion.el | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lsp-completion.el b/lsp-completion.el index 1ecfdd697c..5bbdb79b50 100644 --- a/lsp-completion.el +++ b/lsp-completion.el @@ -486,9 +486,13 @@ The MARKERS and PREFIX value will be attached to each candidate." ((and (equal kind "markdown") (not (string-match-p (regexp-quote detail?) value))) - (lsp--render-string - (concat "```\n" detail? "\n```\n---\n" value) - kind))))) + (concat + (propertize detail? 'face 'fixed-pitch) + (lsp--render-string + (concat + "\n---\n" + value) + kind)))))) ((and (stringp documentation?) (not (string-match-p (regexp-quote detail?) documentation?))) From 5f446c0c3fd180063dea51050b3bb3cbc212e27f Mon Sep 17 00:00:00 2001 From: Jimmy Yuen Ho Wong Date: Fri, 13 Dec 2024 14:24:59 +0000 Subject: [PATCH 06/12] Return resolved signature via company-docsig --- lsp-completion.el | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/lsp-completion.el b/lsp-completion.el index 5bbdb79b50..e0955a0083 100644 --- a/lsp-completion.el +++ b/lsp-completion.el @@ -190,7 +190,7 @@ See #2675" (unless (lsp-get data :for_ref) (lsp-put data :for_ref :json-false))))) -(defun lsp-completion-resolve (item) +(defun lsp-completion--resolve (item) "Resolve completion ITEM. ITEM can be string or a CompletionItem" (cl-assert item nil "Completion item must not be nil") @@ -215,9 +215,7 @@ ITEM can be string or a CompletionItem" item)) (_ completion-item))))) -(defalias 'lsp-completion--resolve 'lsp-completion-resolve) - -(defun lsp-completion-resolve-async (item callback &optional cleanup-fn) +(defun lsp-completion--resolve-async (item callback &optional cleanup-fn) "Resolve completion ITEM asynchronously with CALLBACK. The CLEANUP-FN will be called to cleanup." (cl-assert item nil "Completion item must not be nil") @@ -248,12 +246,10 @@ The CLEANUP-FN will be called to cleanup." (funcall callback completion-item) (when cleanup-fn (funcall cleanup-fn)))))) -(defalias 'lsp-completion--resolve-async 'lsp-completion-resolve-async) - -(defun lsp-completion--annotate (item) - "Annotate ITEM detail." +(defun lsp-completion--get-label-detail (item) + "Construct label detail from completion item ITEM." (-let (((completion-item &as &CompletionItem :detail? :kind? :label-details?) - (get-text-property 0 'lsp-completion-unresolved-item item))) + item)) (concat (when (and lsp-completion-show-detail detail?) (concat " " (s-replace "\r" "" detail?))) (when (and lsp-completion-show-label-description label-details?) @@ -263,6 +259,12 @@ The CLEANUP-FN will be called to cleanup." (when-let* ((kind-name (and kind? (aref lsp-completion--item-kind kind?)))) (format " (%s)" kind-name)))))) +(defun lsp-completion--annotate (cand) + "Annotation function for completion candidate CAND. + +Returns unresolved completion item detail." + (lsp-completion--get-label-detail (get-text-property 0 'lsp-completion-unresolved-item cand))) + (defun lsp-completion--looking-back-trigger-characterp (trigger-characters) "Return character if text before point match any of the TRIGGER-CHARACTERS." (unless (= (point) (line-beginning-position)) @@ -460,12 +462,19 @@ The MARKERS and PREFIX value will be attached to each candidate." (setq label-pos 0))) matches))) +(defun lsp-completion--company-docsig (cand) + "Signature for completion candidate CAND. + +Returns resolved completion item details." + (and (lsp-completion--resolve cand) + (lsp-completion--get-label-detail (get-text-property 0 'lsp-completion-item cand)))) + (defun lsp-completion--get-documentation (item) "Get doc comment for completion ITEM." (or (get-text-property 0 'lsp-completion-item-doc item) (-let* (((&CompletionItem :detail? :documentation?) - (get-text-property 0 'lsp-completion-item (lsp-completion-resolve item))) + (get-text-property 0 'lsp-completion-item (lsp-completion--resolve item))) (doc (if (and detail? documentation?) ;; detail was resolved, that means the candidate list has no @@ -647,6 +656,7 @@ The MARKERS and PREFIX value will be attached to each candidate." (goto-char (1- (point)))) (and triggered-by-char? t))) :company-match #'lsp-completion--company-match + :company-docsig #'lsp-completion--company-docsig :company-doc-buffer (-compose #'lsp-doc-buffer #'lsp-completion--get-documentation) :exit-function @@ -669,7 +679,7 @@ Others: CANDIDATES" ;; see #3498 typescript-language-server does not provide the ;; proper insertText without resolving. (if (lsp-completion--find-workspace 'ts-ls) - (lsp-completion-resolve candidate) + (lsp-completion--resolve candidate) candidate)) ((&plist 'lsp-completion-item item 'lsp-completion-start-point start-point @@ -711,14 +721,14 @@ Others: CANDIDATES" (not (seq-empty-p additional-text-edits?))) (lsp--apply-text-edits additional-text-edits? 'completion) (-let [(callback cleanup-fn) (lsp--create-apply-text-edits-handlers)] - (lsp-completion-resolve-async + (lsp-completion--resolve-async item (-compose callback #'lsp:completion-item-additional-text-edits?) cleanup-fn)))) (if (or resolved command?) (when command? (lsp--execute-command command?)) - (lsp-completion-resolve-async + (lsp-completion--resolve-async item (-lambda ((&CompletionItem? :command?)) (when command? (lsp--execute-command command?))))) From b9e6f4c89d035fdffa662c5fcf2d16a098a2de8f Mon Sep 17 00:00:00 2001 From: Jimmy Yuen Ho Wong Date: Sat, 21 Dec 2024 14:03:42 +0000 Subject: [PATCH 07/12] Properly implement labelDetails for 3.17 --- lsp-completion.el | 53 +++++++++++++++++++++++++++++------------------ lsp-protocol.el | 2 +- 2 files changed, 34 insertions(+), 21 deletions(-) diff --git a/lsp-completion.el b/lsp-completion.el index e0955a0083..c313be104b 100644 --- a/lsp-completion.el +++ b/lsp-completion.el @@ -67,17 +67,11 @@ ignored." :group 'lsp-completion :package-version '(lsp-mode . "7.0.1")) -(defcustom lsp-completion-show-detail t +(defcustom lsp-completion-show-detail nil "Whether or not to show detail of completion candidates." :type 'boolean :group 'lsp-completion) -(defcustom lsp-completion-show-label-description t - "Whether or not to show description of completion candidates." - :type 'boolean - :group 'lsp-completion - :package-version '(lsp-mode . "9.0.0")) - (defcustom lsp-completion-no-cache nil "Whether or not caching the returned completions from server." :type 'boolean @@ -246,24 +240,41 @@ The CLEANUP-FN will be called to cleanup." (funcall callback completion-item) (when cleanup-fn (funcall cleanup-fn)))))) -(defun lsp-completion--get-label-detail (item) +(defun lsp-completion--get-label-detail (item &optional omit-description) "Construct label detail from completion item ITEM." - (-let (((completion-item &as &CompletionItem :detail? :kind? :label-details?) - item)) - (concat (when (and lsp-completion-show-detail detail?) - (concat " " (s-replace "\r" "" detail?))) - (when (and lsp-completion-show-label-description label-details?) - (when-let* ((description (and label-details? (lsp:label-details-description label-details?)))) - (format " %s" description))) - (when lsp-completion-show-kind - (when-let* ((kind-name (and kind? (aref lsp-completion--item-kind kind?)))) - (format " (%s)" kind-name)))))) + (-let (((&CompletionItem :detail? :label-details?) item)) + (cond ((and label-details? + (or (lsp:label-details-detail? label-details?) + (lsp:label-details-description? label-details?))) + (-let (((&LabelDetails :detail? :description?) label-details?)) + (concat + (unless (and lsp-completion-show-detail + detail? + (string-prefix-p " " detail?)) + " ") + (when lsp-completion-show-detail + (s-replace "\r" "" detail?)) + (unless (or omit-description + (and description? (string-prefix-p " " description?))) + " ") + (unless omit-description + description?)))) + (lsp-completion-show-detail + (concat (unless (and detail? (string-prefix-p " " detail?)) + " ") + (s-replace "\r" "" detail?)))))) (defun lsp-completion--annotate (cand) "Annotation function for completion candidate CAND. Returns unresolved completion item detail." - (lsp-completion--get-label-detail (get-text-property 0 'lsp-completion-unresolved-item cand))) + (when-let ((lsp-completion-item (get-text-property 0 'lsp-completion-unresolved-item cand))) + (concat + (lsp-completion--get-label-detail lsp-completion-item) + (when lsp-completion-show-kind + (when-let* ((kind? (lsp:completion-item-kind? lsp-completion-item)) + (kind-name (and kind? (aref lsp-completion--item-kind kind?)))) + (format " (%s)" kind-name)))))) (defun lsp-completion--looking-back-trigger-characterp (trigger-characters) "Return character if text before point match any of the TRIGGER-CHARACTERS." @@ -467,7 +478,9 @@ The MARKERS and PREFIX value will be attached to each candidate." Returns resolved completion item details." (and (lsp-completion--resolve cand) - (lsp-completion--get-label-detail (get-text-property 0 'lsp-completion-item cand)))) + (lsp-completion--get-label-detail + (get-text-property 0 'lsp-completion-item cand) + t))) (defun lsp-completion--get-documentation (item) "Get doc comment for completion ITEM." diff --git a/lsp-protocol.el b/lsp-protocol.el index b8e2b62b8d..91c06c542d 100644 --- a/lsp-protocol.el +++ b/lsp-protocol.el @@ -667,7 +667,6 @@ See `-let' for a description of the destructuring mechanism." (FormattingOptions (:tabSize :insertSpaces) (:trimTrailingWhitespace :insertFinalNewline :trimFinalNewlines)) (HoverCapabilities nil (:contentFormat :dynamicRegistration)) (ImplementationCapabilities nil (:dynamicRegistration :linkSupport)) - (LabelDetails (:detail :description) nil) (LinkedEditingRanges (:ranges) (:wordPattern)) (Location (:range :uri) nil) (MarkedString (:language :value) nil) @@ -824,6 +823,7 @@ See `-let' for a description of the destructuring mechanism." (WillSaveTextDocumentParams (:reason :textDocument) nil) (WorkspaceSymbolParams (:query) nil) ;; 3.17 + (LabelDetails nil (:detail :description)) (InlayHint (:label :position) (:kind :paddingLeft :paddingRight)) (InlayHintLabelPart (:value) (:tooltip :location :command)) (InlayHintsParams (:textDocument) (:range)) From e288032b09026ecddf6520183711debccb1d05b2 Mon Sep 17 00:00:00 2001 From: Jimmy Yuen Ho Wong Date: Sat, 21 Dec 2024 14:20:06 +0000 Subject: [PATCH 08/12] Show detail when labelDetail is not available --- lsp-completion.el | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/lsp-completion.el b/lsp-completion.el index c313be104b..71b174b801 100644 --- a/lsp-completion.el +++ b/lsp-completion.el @@ -67,11 +67,6 @@ ignored." :group 'lsp-completion :package-version '(lsp-mode . "7.0.1")) -(defcustom lsp-completion-show-detail nil - "Whether or not to show detail of completion candidates." - :type 'boolean - :group 'lsp-completion) - (defcustom lsp-completion-no-cache nil "Whether or not caching the returned completions from server." :type 'boolean @@ -248,18 +243,15 @@ The CLEANUP-FN will be called to cleanup." (lsp:label-details-description? label-details?))) (-let (((&LabelDetails :detail? :description?) label-details?)) (concat - (unless (and lsp-completion-show-detail - detail? - (string-prefix-p " " detail?)) + (unless (and detail? (string-prefix-p " " detail?)) " ") - (when lsp-completion-show-detail - (s-replace "\r" "" detail?)) + (s-replace "\r" "" detail?) (unless (or omit-description (and description? (string-prefix-p " " description?))) " ") (unless omit-description description?)))) - (lsp-completion-show-detail + (detail? (concat (unless (and detail? (string-prefix-p " " detail?)) " ") (s-replace "\r" "" detail?)))))) From 43aa70163a0eacd48a3ea0d57eae9f26f5550aaf Mon Sep 17 00:00:00 2001 From: Jimmy Yuen Ho Wong Date: Sat, 21 Dec 2024 14:26:20 +0000 Subject: [PATCH 09/12] Replace \r only when there's a detail --- lsp-completion.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lsp-completion.el b/lsp-completion.el index 71b174b801..ba904f37f6 100644 --- a/lsp-completion.el +++ b/lsp-completion.el @@ -245,7 +245,8 @@ The CLEANUP-FN will be called to cleanup." (concat (unless (and detail? (string-prefix-p " " detail?)) " ") - (s-replace "\r" "" detail?) + (when detail? + (s-replace "\r" "" detail?)) (unless (or omit-description (and description? (string-prefix-p " " description?))) " ") From 9aadd93c3a78fc97db6abf167d0e416c17902587 Mon Sep 17 00:00:00 2001 From: Jimmy Yuen Ho Wong Date: Sat, 21 Dec 2024 18:16:47 +0000 Subject: [PATCH 10/12] Request server to compute insertTextFormat and insertTextMode early --- lsp-mode.el | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lsp-mode.el b/lsp-mode.el index 605d9cce85..142bef0879 100644 --- a/lsp-mode.el +++ b/lsp-mode.el @@ -3800,9 +3800,7 @@ disappearing, unset all the variables related to it." . ((properties . ["documentation" "detail" "additionalTextEdits" - "command" - "insertTextFormat" - "insertTextMode"]))) + "command"]))) (insertTextModeSupport . ((valueSet . [1 2]))) (labelDetailsSupport . t))) (contextSupport . t) From 594b24f01e37040f8a107f09f9d5ffb8b1eb3a78 Mon Sep 17 00:00:00 2001 From: Jimmy Yuen Ho Wong Date: Wed, 8 Jan 2025 20:13:03 +0000 Subject: [PATCH 11/12] Use code fence for detail --- lsp-completion.el | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lsp-completion.el b/lsp-completion.el index ba904f37f6..97da072fba 100644 --- a/lsp-completion.el +++ b/lsp-completion.el @@ -501,13 +501,14 @@ Returns resolved completion item details." ((and (equal kind "markdown") (not (string-match-p (regexp-quote detail?) value))) - (concat - (propertize detail? 'face 'fixed-pitch) - (lsp--render-string - (concat - "\n---\n" - value) - kind)))))) + (lsp--render-string + (concat + "```\n" + detail? + "\n```" + "\n---\n" + value) + kind))))) ((and (stringp documentation?) (not (string-match-p (regexp-quote detail?) documentation?))) From c4521ce4b2fb90f9bd65da4a297e31bd3389fe34 Mon Sep 17 00:00:00 2001 From: Jimmy Yuen Ho Wong Date: Wed, 8 Jan 2025 20:32:44 +0000 Subject: [PATCH 12/12] Put lsp-completion-show-detail back --- lsp-completion.el | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lsp-completion.el b/lsp-completion.el index 97da072fba..a1bf59fd1c 100644 --- a/lsp-completion.el +++ b/lsp-completion.el @@ -67,6 +67,11 @@ ignored." :group 'lsp-completion :package-version '(lsp-mode . "7.0.1")) +(defcustom lsp-completion-show-detail t + "Whether or not to show detail of completion candidates." + :type 'boolean + :group 'lsp-completion) + (defcustom lsp-completion-no-cache nil "Whether or not caching the returned completions from server." :type 'boolean @@ -263,7 +268,8 @@ The CLEANUP-FN will be called to cleanup." Returns unresolved completion item detail." (when-let ((lsp-completion-item (get-text-property 0 'lsp-completion-unresolved-item cand))) (concat - (lsp-completion--get-label-detail lsp-completion-item) + (when lsp-completion-show-detail + (lsp-completion--get-label-detail lsp-completion-item)) (when lsp-completion-show-kind (when-let* ((kind? (lsp:completion-item-kind? lsp-completion-item)) (kind-name (and kind? (aref lsp-completion--item-kind kind?))))