aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoão Távora2023-02-23 13:58:38 +0000
committerJoão Távora2023-02-23 13:58:54 +0000
commite3be0dbf85c729447776d361ba56ada6b92f0149 (patch)
tree1574dabd3c3f5ecff180e6d54800cee92f8b75fc
parent5286111ea1fe442d861cd4a940d86db3fd832139 (diff)
downloademacs-e3be0dbf85c729447776d361ba56ada6b92f0149.tar.gz
emacs-e3be0dbf85c729447776d361ba56ada6b92f0149.zip
Eglot: display completion label when safe
Originally reported in https://github.com/joaotavora/eglot/discussions/1141 by "Mintsoup". Eglot doesn't always show the LSP :label property of a CompletionItem in the completion candidates. That is because label is sometimes not what should be inserted in the buffer in the end, the :insertText property supercedes it. But the label is usually more suitable for display nevertheless and if the LSP CompletionItem contains either a snippet or a textEdit, it's safe to display the label, since :exit-function will guarantee that a suitable buffer insertion is performed. This change reflects that awareness that when a textEdit is available, it's acceptable to show the label. * lisp/progmodes/eglot.el (eglot-completion-at-point): Adjust.
-rw-r--r--lisp/progmodes/eglot.el20
1 files changed, 12 insertions, 8 deletions
diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el
index df755dfa43a..7d61f6ad78e 100644
--- a/lisp/progmodes/eglot.el
+++ b/lisp/progmodes/eglot.el
@@ -2824,16 +2824,20 @@ for which LSP on-type-formatting should be requested."
2824 (mapcar 2824 (mapcar
2825 (jsonrpc-lambda 2825 (jsonrpc-lambda
2826 (&rest item &key label insertText insertTextFormat 2826 (&rest item &key label insertText insertTextFormat
2827 &allow-other-keys) 2827 textEdit &allow-other-keys)
2828 (let ((proxy 2828 (let ((proxy
2829 (cond ((and (eql insertTextFormat 2) 2829 ;; Snippet or textEdit, it's safe to
2830 (eglot--snippet-expansion-fn)) 2830 ;; display/insert the label since
2831 ;; it'll be adjusted. If no usable
2832 ;; insertText at all, label is best,
2833 ;; too.
2834 (cond ((or (and (eql insertTextFormat 2)
2835 (eglot--snippet-expansion-fn))
2836 textEdit
2837 (null insertText)
2838 (string-empty-p insertText))
2831 (string-trim-left label)) 2839 (string-trim-left label))
2832 ((and insertText 2840 (t insertText))))
2833 (not (string-empty-p insertText)))
2834 insertText)
2835 (t
2836 (string-trim-left label)))))
2837 (unless (zerop (length proxy)) 2841 (unless (zerop (length proxy))
2838 (put-text-property 0 1 'eglot--lsp-item item proxy)) 2842 (put-text-property 0 1 'eglot--lsp-item item proxy))
2839 proxy)) 2843 proxy))