emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/eglot d167c80 15/22: Fix #190: actually make completion


From: João Távora
Subject: [elpa] externals/eglot d167c80 15/22: Fix #190: actually make completion sorting work
Date: Sat, 5 Jan 2019 09:31:04 -0500 (EST)

branch: externals/eglot
commit d167c8014d76d06c9448fff2feba3d12b9c665f9
Author: João Távora <address@hidden>
Commit: João Távora <address@hidden>

    Fix #190: actually make completion sorting work
    
    * eglot.el (eglot-completion-at-point): Complicate severely.
---
 eglot.el | 66 +++++++++++++++++++++++++++++++++++-----------------------------
 1 file changed, 36 insertions(+), 30 deletions(-)

diff --git a/eglot.el b/eglot.el
index 5861b05..d60fc07 100644
--- a/eglot.el
+++ b/eglot.el
@@ -1806,37 +1806,49 @@ is not active."
 
 (defun eglot-completion-at-point ()
   "EGLOT's `completion-at-point' function."
-  (let ((bounds (bounds-of-thing-at-point 'symbol))
+  (let* ((bounds (bounds-of-thing-at-point 'symbol))
         (server (eglot--current-server-or-lose))
         (completion-capability (eglot--server-capable :completionProvider))
+        (sort-completions (lambda (completions)
+                            (sort completions
+                                  (lambda (a b)
+                                    (string-lessp
+                                     (or (get-text-property 0 :sortText a) "")
+                                     (or (get-text-property 0 :sortText b) 
""))))))
+        (metadata `(metadata . ((display-sort-function . ,sort-completions))))
         strings)
     (when completion-capability
       (list
        (or (car bounds) (point))
        (or (cdr bounds) (point))
-       (completion-table-dynamic
-        (lambda (_ignored)
-          (let* ((resp (jsonrpc-request server
-                                        :textDocument/completion
-                                        (eglot--CompletionParams)
-                                        :deferred :textDocument/completion
-                                        :cancel-on-input t))
-                 (items (if (vectorp resp) resp (plist-get resp :items))))
-            (setq
-             strings
-             (mapcar
-              (jsonrpc-lambda (&rest all &key label insertText insertTextFormat
-                                     &allow-other-keys)
-                (let ((completion
-                       (cond ((and (eql insertTextFormat 2)
-                                   (eglot--snippet-expansion-fn))
-                              (string-trim-left label))
-                             (t
-                              (or insertText (string-trim-left label))))))
-                  (add-text-properties 0 1 all completion)
-                  (put-text-property 0 1 'eglot--lsp-completion all completion)
-                  completion))
-              items)))))
+       (lambda (string pred action)
+         (if (eq action 'metadata) metadata
+           (funcall
+            (completion-table-dynamic
+             (lambda (_ignored)
+               (let* ((resp (jsonrpc-request server
+                                             :textDocument/completion
+                                             (eglot--CompletionParams)
+                                             :deferred :textDocument/completion
+                                             :cancel-on-input t))
+                      (items (if (vectorp resp) resp (plist-get resp :items))))
+                 (setq
+                  strings
+                  (mapcar
+                   (jsonrpc-lambda
+                       (&rest all &key label insertText insertTextFormat
+                              &allow-other-keys)
+                     (let ((completion
+                            (cond ((and (eql insertTextFormat 2)
+                                        (eglot--snippet-expansion-fn))
+                                   (string-trim-left label))
+                                  (t
+                                   (or insertText (string-trim-left label))))))
+                       (add-text-properties 0 1 all completion)
+                       (put-text-property 0 1 'eglot--lsp-completion all 
completion)
+                       completion))
+                   items)))))
+            string pred action)))
        :annotation-function
        (lambda (obj)
          (eglot--dbind ((CompletionItem) detail kind insertTextFormat)
@@ -1854,12 +1866,6 @@ is not active."
                        (and (eql insertTextFormat 2)
                             (eglot--snippet-expansion-fn)
                             " (snippet)"))))))
-       :display-sort-function
-       (lambda (items)
-         (sort items (lambda (a b)
-                       (string-lessp
-                        (or (get-text-property 0 :sortText a) "")
-                        (or (get-text-property 0 :sortText b) "")))))
        :company-doc-buffer
        (lambda (obj)
          (let* ((documentation



reply via email to

[Prev in Thread] Current Thread [Next in Thread]