]> git.eshelyaron.com Git - emacs.git/commitdiff
Eglot: run eglot-managed-mode-hook after LSP didOpen
authorJoão Távora <joaotavora@gmail.com>
Wed, 22 Feb 2023 18:44:39 +0000 (18:44 +0000)
committerJoão Távora <joaotavora@gmail.com>
Wed, 22 Feb 2023 18:52:00 +0000 (18:52 +0000)
This allows using the hook for interacting with the LSP server using
the current buffer as the subject of that interaction ("document" in
LSP parlance).

* lisp/progmodes/eglot.el (eglot--maybe-activate-editing-mode):
Run eglot-managed-mode-hook here.
(eglot--managed-mode): Not here.

lisp/progmodes/eglot.el

index 3daca24a5864efbe8ca86587f0a3d21450e8c2a5..8b0caf41ad71b905e2a1dda5de45884275228435 100644 (file)
@@ -1814,9 +1814,7 @@ Use `eglot-managed-p' to determine if current buffer is managed.")
               (delq (current-buffer) (eglot--managed-buffers server)))
         (when (and eglot-autoshutdown
                    (null (eglot--managed-buffers server)))
-          (eglot-shutdown server))))))
-  ;; Note: the public hook runs before the internal eglot--managed-mode-hook.
-  (run-hooks 'eglot-managed-mode-hook))
+          (eglot-shutdown server)))))))
 
 (defun eglot--managed-mode-off ()
   "Turn off `eglot--managed-mode' unconditionally."
@@ -1858,7 +1856,10 @@ If it is activated, also signal textDocument/didOpen."
     (when (and buffer-file-name (eglot-current-server))
       (setq eglot--diagnostics nil)
       (eglot--managed-mode)
-      (eglot--signal-textDocument/didOpen))))
+      (eglot--signal-textDocument/didOpen)
+      ;; Run user hook after 'textDocument/didOpen' so server knows
+      ;; about the buffer.
+      (run-hooks 'eglot-managed-mode-hook))))
 
 (add-hook 'find-file-hook 'eglot--maybe-activate-editing-mode)
 (add-hook 'after-change-major-mode-hook 'eglot--maybe-activate-editing-mode)