]> git.eshelyaron.com Git - emacs.git/commitdiff
Better decide what text exactly to present as completions
authorJoão Távora <joaotavora@gmail.com>
Sat, 19 May 2018 12:16:36 +0000 (13:16 +0100)
committerJoão Távora <joaotavora@gmail.com>
Sat, 19 May 2018 16:05:20 +0000 (17:05 +0100)
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

lisp/progmodes/eglot.el

index 9d5ef805350bbcf284a3f57e6648ce8a87194f7d..e8af7ed80e6744fe179531073b755833c6391485 100644 (file)
@@ -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.")