From 3a24bc0f4f65b3729b239776b2bdae00edd5884a Mon Sep 17 00:00:00 2001 From: Michal Krzywkowski Date: Sat, 8 Sep 2018 21:36:00 +0200 Subject: [PATCH] Sort references and definitions by line number * eglot.el (eglot--sort-xrefs): New function. (xref-backend-definitions): (xref-backend-references): (xref-backend-apropos): Use it. --- lisp/progmodes/eglot.el | 47 ++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index 41863cc213f..7e79b165c69 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el @@ -1323,6 +1323,12 @@ DUMMY is ignored." ;; F!@(#*&#$)CKING OFF-BY-ONE again (1+ line) character)))) +(defun eglot--sort-xrefs (xrefs) + (sort xrefs + (lambda (a b) + (< (xref-location-line (xref-item-location a)) + (xref-location-line (xref-item-location b)))))) + (cl-defmethod xref-backend-identifier-completion-table ((_backend (eql eglot))) (when (eglot--server-capable :documentSymbolProvider) (let ((server (eglot--current-server-or-lose)) @@ -1363,9 +1369,10 @@ DUMMY is ignored." :textDocument/definition (get-text-property 0 :textDocumentPositionParams identifier))))) - (mapcar (jsonrpc-lambda (&key uri range) - (eglot--xref-make identifier uri (plist-get range :start))) - location-or-locations))) + (eglot--sort-xrefs + (mapcar (jsonrpc-lambda (&key uri range) + (eglot--xref-make identifier uri (plist-get range :start))) + location-or-locations)))) (cl-defmethod xref-backend-references ((_backend (eql eglot)) identifier) (unless (eglot--server-capable :referencesProvider) @@ -1376,25 +1383,27 @@ DUMMY is ignored." (and rich (get-text-property 0 :textDocumentPositionParams rich)))))) (unless params (eglot--error "Don' know where %s is in the workspace!" identifier)) - (mapcar - (jsonrpc-lambda (&key uri range) - (eglot--xref-make identifier uri (plist-get range :start))) - (jsonrpc-request (eglot--current-server-or-lose) - :textDocument/references - (append - params - (list :context - (list :includeDeclaration t))))))) + (eglot--sort-xrefs + (mapcar + (jsonrpc-lambda (&key uri range) + (eglot--xref-make identifier uri (plist-get range :start))) + (jsonrpc-request (eglot--current-server-or-lose) + :textDocument/references + (append + params + (list :context + (list :includeDeclaration t)))))))) (cl-defmethod xref-backend-apropos ((_backend (eql eglot)) pattern) (when (eglot--server-capable :workspaceSymbolProvider) - (mapcar - (jsonrpc-lambda (&key name location &allow-other-keys) - (cl-destructuring-bind (&key uri range) location - (eglot--xref-make name uri (plist-get range :start)))) - (jsonrpc-request (eglot--current-server-or-lose) - :workspace/symbol - `(:query ,pattern))))) + (eglot--sort-xrefs + (mapcar + (jsonrpc-lambda (&key name location &allow-other-keys) + (cl-destructuring-bind (&key uri range) location + (eglot--xref-make name uri (plist-get range :start)))) + (jsonrpc-request (eglot--current-server-or-lose) + :workspace/symbol + `(:query ,pattern)))))) (defun eglot-format-buffer () "Format contents of current buffer." -- 2.39.2