From 28ed0d1840f94ba52b8b60bfbf222493fee2a3ea Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jo=C3=A3o=20T=C3=A1vora?= Date: Wed, 22 Feb 2023 18:44:39 +0000 Subject: [PATCH] Eglot: run eglot-managed-mode-hook after LSP didOpen 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 | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index 3daca24a586..8b0caf41ad7 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el @@ -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) -- 2.39.2