From bc47cced6668da4a784ec0bf35a6fa9bc374defb Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jo=C3=A3o=20T=C3=A1vora?= Date: Fri, 24 Jan 2025 22:51:54 +0000 Subject: [PATCH] Eglot: symbol highlighting now done in eldoc-documentation-functions Even though highlighting the thing at point isn't really producing documentation at point, theory and practice have shown that using eldoc-documentation-functions for this is a feasible way to avoid reimplementing all the idle timer logic for such functionality. In fact, we were already using ElDoc for this purpose, but this commit makes it so the new eglot-highlight-eldoc-function is a first class citizen in eldoc-documentation-functions, so users can manipulate it if so desired. * lisp/progmodes/eglot.el (eglot--managed-mode): Use eglot-highlight-eldoc-function (eglot-hover-eldoc-function): Don't mix highlighting with hover. (eglot-highlight-eldoc-function): Rename and rework from eglot--highlight-piggyback (cherry picked from commit 60166a419f601b413db86ddce186cc387e8ec269) --- lisp/progmodes/eglot.el | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index 57118036665..166b3936102 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el @@ -2047,6 +2047,8 @@ Use `eglot-managed-p' to determine if current buffer is managed.") nil t) (add-hook 'eldoc-documentation-functions #'eglot-signature-eldoc-function nil t) + (add-hook 'eldoc-documentation-functions #'eglot-highlight-eldoc-function + nil t) (eldoc-mode 1)) (cl-pushnew (current-buffer) (eglot--managed-buffers (eglot-current-server)))) (t @@ -2067,6 +2069,7 @@ Use `eglot-managed-p' to determine if current buffer is managed.") (remove-hook 'eldoc-documentation-functions #'eglot-hover-eldoc-function t) (remove-hook 'eldoc-documentation-functions #'eglot-signature-eldoc-function t) (remove-hook 'flymake-diagnostic-functions #'eglot-flymake-backend t) + (remove-hook 'eldoc-documentation-functions #'eglot-highlight-eldoc-function t) (cl-loop for (var . saved-binding) in eglot--saved-bindings do (set (make-local-variable var) saved-binding)) (remove-function (local 'imenu-create-index-function) #'eglot-imenu) @@ -3534,17 +3537,17 @@ for which LSP on-type-formatting should be requested." (funcall cb info :echo (and info (string-match "\n" info)))))) :deferred :textDocument/hover)) - (eglot--highlight-piggyback cb) t)) (defvar eglot--highlights nil "Overlays for textDocument/documentHighlight.") -(defun eglot--highlight-piggyback (_cb) - "Request and handle `:textDocument/documentHighlight'." - ;; FIXME: Obviously, this is just piggy backing on eldoc's calls for - ;; convenience, as shown by the fact that we just ignore cb. - (let ((buf (current-buffer))) - (when (eglot-server-capable :documentHighlightProvider) +(defun eglot-highlight-eldoc-function (_cb &rest _ignored) + "A member of `eldoc-documentation-functions', for highlighting symbols'." + ;; Obviously, we're not using ElDoc for documentation, but merely its + ;; at-point calling convention, as shown by the fact that we just + ;; ignore cb and return nil to say "no doc". + (when (eglot-server-capable :documentHighlightProvider) + (let ((buf (current-buffer))) (jsonrpc-async-request (eglot--current-server-or-lose) :textDocument/documentHighlight (eglot--TextDocumentPositionParams) -- 2.39.5