Skip to content

Commit

Permalink
Per #131: Rework how workspace symbol cache is searched and organized
Browse files Browse the repository at this point in the history
* eglot (eglot--workspace-symbols-cache):  Move closer to point of usage.
Don't clear on every command.
(eglot--recover-workspace-meta): Be aware of minibuffer.el improper lists.
(eglot--pre-command-hook): Simplify.
(xref-backend-identifier-completion-table): Clear cache here.
  • Loading branch information
joaotavora committed Jul 14, 2022
1 parent 3cd6c68 commit 997e5ff
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions eglot.el
Original file line number Diff line number Diff line change
Expand Up @@ -2101,12 +2101,8 @@ THINGS are either registrations or unregisterations (sic)."
:key #'seq-first))))
(eglot-format (point) nil last-input-event))))

(defvar eglot--workspace-symbols-cache (make-hash-table :test #'equal)
"Cache of `workspace/Symbol' results used by `xref-find-definitions'.")

(defun eglot--pre-command-hook ()
"Reset some temporary variables."
(clrhash eglot--workspace-symbols-cache)
(setq eglot--last-inserted-char nil))

(defun eglot--CompletionParams ()
Expand Down Expand Up @@ -2396,9 +2392,13 @@ Try to visit the target file for a richer summary line."
(eglot--current-server-or-lose))
(xref-make-match summary (xref-make-file-location file line column) length)))

(defvar eglot--workspace-symbols-cache (make-hash-table :test #'equal)
"Cache of `workspace/Symbol' results used by `xref-find-definitions'.")

(cl-defmethod xref-backend-identifier-completion-table ((_backend (eql eglot)))
(if (eglot--server-capable :workspaceSymbolProvider)
(let ((buf (current-buffer)))
(clrhash eglot--workspace-symbols-cache)
(cl-labels ((refresh (pat)
(mapcar
(lambda (wss)
Expand Down Expand Up @@ -2457,8 +2457,10 @@ Try to visit the target file for a richer summary line."
"Search `eglot--workspace-symbols-cache' for rich entry of STRING."
(catch 'found
(maphash (lambda (_k v)
(let ((probe (member string v)))
(when probe (throw 'found (car probe)))))
(while v
;; Like mess? Ask minibuffer.el about improper lists.
(when (equal (car v) string) (throw 'found (car v)))
(setq v (and (consp v) (cdr v)))))
eglot--workspace-symbols-cache)))

(add-to-list 'completion-category-overrides
Expand Down

0 comments on commit 997e5ff

Please sign in to comment.