[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/eglot 9fb5f0c 05/26: Per #52, #127: Improve performance
From: |
João Távora |
Subject: |
[elpa] externals/eglot 9fb5f0c 05/26: Per #52, #127: Improve performance of xref summary line collection |
Date: |
Sun, 9 Dec 2018 19:11:25 -0500 (EST) |
branch: externals/eglot
commit 9fb5f0cb5de73c4ca221ec8865fe7677fb29b2da
Author: João Távora <address@hidden>
Commit: João Távora <address@hidden>
Per #52, #127: Improve performance of xref summary line collection
* eglot.el (eglot--temp-location-buffers): New variable.
(eglot--handling-xrefs): New macro.
(eglot--xref-make): Use eglot--temp-location-buffers.
(xref-backend-definitions, xref-backend-references)
(xref-backend-apropos): Use eglot--handling-xrefs.
---
eglot.el | 38 ++++++++++++++++++++++++--------------
1 file changed, 24 insertions(+), 14 deletions(-)
diff --git a/eglot.el b/eglot.el
index 8ba483b..1522935 100644
--- a/eglot.el
+++ b/eglot.el
@@ -1478,13 +1478,26 @@ DUMMY is ignored."
(advice-add 'xref-find-definitions :after #'eglot--xref-reset-known-symbols)
(advice-add 'xref-find-references :after #'eglot--xref-reset-known-symbols)
+(defvar eglot--temp-location-buffers (make-hash-table :test #'equal)
+ "Helper variable for `eglot--handling-xrefs'.")
+
+(defmacro eglot--handling-xrefs (&rest body)
+ "Properly sort and handle xrefs produced and returned by BODY."
+ `(unwind-protect
+ (sort (progn ,@body)
+ (lambda (a b)
+ (< (xref-location-line (xref-item-location a))
+ (xref-location-line (xref-item-location b)))))
+ (maphash (lambda (_uri buf) (kill-buffer buf))
eglot--temp-location-buffers)
+ (clrhash eglot--temp-location-buffers)))
+
(defun eglot--xref-make (name uri range)
"Like `xref-make' but with LSP's NAME, URI and RANGE.
Try to visit the target file for a richer summary line."
(pcase-let*
- ((`(,beg . ,end) (eglot--range-region range))
- (file (eglot--uri-to-path uri))
- (visiting (find-buffer-visiting file))
+ ((file (eglot--uri-to-path uri))
+ (visiting (or (find-buffer-visiting file)
+ (gethash uri eglot--temp-location-buffers)))
(collect (lambda ()
(eglot--widening
(pcase-let* ((`(,beg . ,end) (eglot--range-region range))
@@ -1497,19 +1510,16 @@ Try to visit the target file for a richer summary line."
(`(,summary ,line ,column)
(cond
(visiting (with-current-buffer visiting (funcall collect)))
- ((file-readable-p file) (with-temp-buffer (insert-file-contents file)
- (funcall collect)))
+ ((file-readable-p file) (with-current-buffer
+ (puthash uri (generate-new-buffer "
*temp*")
+ eglot--temp-location-buffers)
+ (insert-file-contents file)
+ (funcall collect)))
(t ;; fall back to the "dumb strategy"
(let ((start (cl-getf range :start)))
(list name (1+ (cl-getf start :line)) (cl-getf start
:character)))))))
(xref-make summary (xref-make-file-location file line column))))
-(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))
@@ -1553,7 +1563,7 @@ Try to visit the target file for a richer summary line."
(locations
(and definitions
(if (vectorp definitions) definitions (vector definitions)))))
- (eglot--sort-xrefs
+ (eglot--handling-xrefs
(mapcar (jsonrpc-lambda (&key uri range)
(eglot--xref-make identifier uri range))
locations))))
@@ -1567,7 +1577,7 @@ Try to visit the target file for a richer summary line."
(and rich (get-text-property 0 :textDocumentPositionParams
rich))))))
(unless params
(eglot--error "Don' know where %s is in the workspace!" identifier))
- (eglot--sort-xrefs
+ (eglot--handling-xrefs
(mapcar
(jsonrpc-lambda (&key uri range)
(eglot--xref-make identifier uri range))
@@ -1580,7 +1590,7 @@ Try to visit the target file for a richer summary line."
(cl-defmethod xref-backend-apropos ((_backend (eql eglot)) pattern)
(when (eglot--server-capable :workspaceSymbolProvider)
- (eglot--sort-xrefs
+ (eglot--handling-xrefs
(mapcar
(jsonrpc-lambda (&key name location &allow-other-keys)
(cl-destructuring-bind (&key uri range) location
- [elpa] externals/eglot updated (f291816 -> 23accee), João Távora, 2018/12/09
- [elpa] externals/eglot 11eb256 02/26: Fix #164: CodeAction command can be a Command object (#165), João Távora, 2018/12/09
- [elpa] externals/eglot 10b238b 03/26: Revert "Fix #164: CodeAction command can be a Command object (#165)", João Távora, 2018/12/09
- [elpa] externals/eglot cddab30 06/26: * eglot.el (eglot--current-column): New helper., João Távora, 2018/12/09
- [elpa] externals/eglot 53bfdb7 19/26: Per #173: adjust previous fix, João Távora, 2018/12/09
- [elpa] externals/eglot 9fb5f0c 05/26: Per #52, #127: Improve performance of xref summary line collection,
João Távora <=
- [elpa] externals/eglot 5bbf884 11/26: Use eglot--dbind for destructuring, João Távora, 2018/12/09
- [elpa] externals/eglot 81d035f 04/26: Fix #52: Use entire line as xref summary when available, João Távora, 2018/12/09
- [elpa] externals/eglot 96169d8 18/26: Per #173: fix bug introduced by previous fix, João Távora, 2018/12/09
- [elpa] externals/eglot 4874c22 14/26: Use javascript-typescript-langserver for typescript-mode (#174), João Távora, 2018/12/09
- [elpa] externals/eglot 66a1704 22/26: Scratch/use elpa flymake (#178), João Távora, 2018/12/09
- [elpa] externals/eglot f63bedb 20/26: Fix #144: Use eglot--dbind and eglot--lambda throughout, João Távora, 2018/12/09
- [elpa] externals/eglot 3922cf3 01/26: Per #144, #156: control strictness towards incoming LSP messages, João Távora, 2018/12/09
- [elpa] externals/eglot 8140be5 07/26: Touch up last commit, João Távora, 2018/12/09
- [elpa] externals/eglot 95ef9e1 08/26: Robustify tests against (M)ELPA eglot installations, João Távora, 2018/12/09
- [elpa] externals/eglot 38da3d3 15/26: Fix #159: Properly clear old diagnostics when making new ones, João Távora, 2018/12/09