aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoão Távora2023-12-14 16:32:54 +0000
committerJoão Távora2023-12-14 18:08:38 +0000
commitaf1fe69f05d803a6958f9d8a045d1013e2ce785c (patch)
treea83b576e2420474a670449d1eac11c85f164cd36
parentd9814efe0759ce916a1c470c5908d2ca3c80b29b (diff)
downloademacs-af1fe69f05d803a6958f9d8a045d1013e2ce785c.tar.gz
emacs-af1fe69f05d803a6958f9d8a045d1013e2ce785c.zip
Eglot: beware activation in fundamental-mode
In the specific situation of visiting a buffer via M-. with eglot-extend-to-xref set to t, it was found that buffer was first visited in fundamental mode, running after-change-major-mode-hook, and then again in the proper major mode for the file. The call to eglot-current-server of the first visit returned non-nil which cause two didOpen notifications to be issued for the same file. Furthermore, in the first call, eglot--languageId to returned nil, prompting an error from servers such as rust-analyzer. See also: https://github.com/joaotavora/eglot/discussions/1330 * lisp/progmodes/eglot.el (eglot-current-server): Watch out for fundamental-mode.
-rw-r--r--lisp/progmodes/eglot.el16
1 files changed, 9 insertions, 7 deletions
diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el
index 608389f1c05..84c5e6639df 100644
--- a/lisp/progmodes/eglot.el
+++ b/lisp/progmodes/eglot.el
@@ -2034,13 +2034,15 @@ Use `eglot-managed-p' to determine if current buffer is managed.")
2034 "Return logical Eglot server for current buffer, nil if none." 2034 "Return logical Eglot server for current buffer, nil if none."
2035 (setq eglot--cached-server 2035 (setq eglot--cached-server
2036 (or eglot--cached-server 2036 (or eglot--cached-server
2037 (cl-find-if #'eglot--languageId 2037 (and (not (eq major-mode 'fundamental-mode)) ; gh#1330
2038 (gethash (eglot--current-project) 2038 (or
2039 eglot--servers-by-project)) 2039 (cl-find-if #'eglot--languageId
2040 (and eglot-extend-to-xref 2040 (gethash (eglot--current-project)
2041 buffer-file-name 2041 eglot--servers-by-project))
2042 (gethash (expand-file-name buffer-file-name) 2042 (and eglot-extend-to-xref
2043 eglot--servers-by-xrefed-file))))) 2043 buffer-file-name
2044 (gethash (expand-file-name buffer-file-name)
2045 eglot--servers-by-xrefed-file)))))))
2044 2046
2045(defun eglot--current-server-or-lose () 2047(defun eglot--current-server-or-lose ()
2046 "Return current logical Eglot server connection or error." 2048 "Return current logical Eglot server connection or error."