]> git.eshelyaron.com Git - emacs.git/commitdiff
Eglot: symbol highlighting now done in eldoc-documentation-functions
authorJoão Távora <joaotavora@gmail.com>
Fri, 24 Jan 2025 22:51:54 +0000 (22:51 +0000)
committerEshel Yaron <me@eshelyaron.com>
Thu, 30 Jan 2025 18:09:59 +0000 (19:09 +0100)
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

index 57118036665af4ad05bb209abd63710650e8c503..166b39361029b10e746d9e28391fbd0bf06e6905 100644 (file)
@@ -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)