From: João Távora Date: Sat, 19 May 2018 12:16:36 +0000 (+0100) Subject: Better decide what text exactly to present as completions X-Git-Tag: emacs-29.0.90~1616^2~524^2~4^2~555 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=75ca40724b869991b191e02e5930db21c1527dd1;p=emacs.git Better decide what text exactly to present as completions For inserting, :insertText takes precedence over :label. For annotating, first sentence of :documentation, then :detail, then :kind name. Also remember to send didChange in the :exit-function * eglot.el (eglot-completion-function): Rework main function and :annotation-function, and :exit-function --- diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index 9d5ef805350..e8af7ed80e6 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el @@ -702,7 +702,7 @@ DEFERRED is passed to `eglot--async-request', which see." (throw done `(error ,(format "Ooops: %s: %s" code message)))) :deferred deferred)) - (while t (accept-process-output nil 30))) + (while t (accept-process-output nil 30))) (when (cadr id-and-timer) (cancel-timer (cadr id-and-timer)))))) (when (eq 'error (car res)) (eglot--error (cadr res))) (cadr res))) @@ -1300,15 +1300,19 @@ DUMMY is ignored" :textDocument/completion)) (items (if (vectorp resp) resp (plist-get resp :items)))) (mapcar - (eglot--lambda (&rest all &key label &allow-other-keys) - (add-text-properties 0 1 all label) label) + (eglot--lambda (&rest all &key label insertText &allow-other-keys) + (let ((insert (or insertText label))) + (add-text-properties 0 1 all insert) insert)) items)))) :annotation-function (lambda (obj) - (propertize (concat " " (or (get-text-property 0 :detail obj) - (cdr (assoc (get-text-property 0 :kind obj) - eglot--kind-names)))) - 'face 'font-lock-function-name-face)) + (cl-destructuring-bind (&key detail documentation kind &allow-other-keys) + (text-properties-at 0 obj) + (concat " " (propertize + (or (and documentation + (replace-regexp-in-string "\n.*" "" documentation)) + detail (cdr (assoc kind eglot--kind-names))) + 'face 'font-lock-function-name-face)))) :display-sort-function (lambda (items) (sort items (lambda (a b) @@ -1329,8 +1333,9 @@ DUMMY is ignored" (font-lock-ensure) (insert documentation) (current-buffer))))) - :exit-function - (lambda (_string _status) (eglot-eldoc-function)))))) + :exit-function (lambda (_string _status) + (eglot--signal-textDocument/didChange) + (eglot-eldoc-function)))))) (defvar eglot--highlights nil "Overlays for textDocument/documentHighlight.")