From: João Távora Date: Sat, 22 Dec 2018 15:23:41 +0000 (+0000) Subject: Actually make completion sorting work X-Git-Tag: emacs-29.0.90~1616^2~524^2~4^2~353 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=9ffa6a91cd1b7c84134997e22295664eba1925d6;p=emacs.git Actually make completion sorting work * eglot.el (eglot-completion-at-point): Complicate severely. GitHub-reference: fix https://github.com/joaotavora/eglot/issues/190 --- diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index 5861b05fcdf..d60fc0776a8 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/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