Subject: Re: bug#70927: Acknowledgement (30.0.50; track-changes assertion when shutting down eglot)

From: Stefan Monnier <[email-masked]>
Date: Wed, 15 May 2024 14:49:59 -0400

> A quick fix would be to change `eglot--signal-textDocument/didChange`:
>
> - from: `(eglot--track-changes-fetch eglot--track-changes)`
> - to: `(when eglot--track-changes (eglot--track-changes-fetch eglot--track-changes))`
>
> But I'm guessing there's some underlying problem and this may be masking
> the real issue.

Indeed.  I pushed the patch below to `master` instead which should also
fix the problem.  Please confirm that it fixes it for you as well.
Maybe `eglot-shutdown` shouldn't end up calling
`eglot--signal-textDocument/didChange` at all, but that's a long
standing behavior AFAICT, so I'll leave it for some other time.

        Stefan

diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el
index 57a019e126d..0ba69f66f0d 100644
--- a/lisp/progmodes/eglot.el
+++ b/lisp/progmodes/eglot.el
@@ -2022,9 +2022,6 @@ eglot--managed-mode
       (eldoc-mode 1))
     (cl-pushnew (current-buffer) (eglot--managed-buffers (eglot-current-server))))
    (t
-    (when eglot--track-changes
-      (track-changes-unregister eglot--track-changes)
-      (setq eglot--track-changes nil))
     (remove-hook 'kill-buffer-hook #'eglot--managed-mode-off t)
     (remove-hook 'kill-buffer-hook #'eglot--signal-textDocument/didClose t)
     (remove-hook 'before-revert-hook #'eglot--signal-textDocument/didClose t)
@@ -2053,7 +2050,10 @@ eglot--managed-mode
               (delq (current-buffer) (eglot--managed-buffers server)))
         (when (and eglot-autoshutdown
                    (null (eglot--managed-buffers server)))
-          (eglot-shutdown server)))))))
+          (eglot-shutdown server))))
+    (when eglot--track-changes
+      (track-changes-unregister eglot--track-changes)
+      (setq eglot--track-changes nil)))))
 
 (defun eglot--managed-mode-off ()
   "Turn off `eglot--managed-mode' unconditionally."