Subject: Re: bug#72696: Track-changes errors out when file is overwritten using Node.js's fs.writeFile (at least on macOS)

From: Stefan Monnier <[email-masked]>
Date: Sun, 08 Sep 2024 19:06:55 -0400

> As far as I can see, the testDocument/didChange request should not be
> there.

Either the `didClose/didOpen` should not be there, or the `didChange` should
not be there.  The problem is that we have both.

Can you try the patch below, which I suspect should fix your problem?
It should get rid of the `didChange` in your recipe.

We could also change Eglot so it doesn't do `didClose/didOpen` upon
`revert-buffer` (in which case it should/will do the `didChange`), but
that should be a separate concern.

        Stefan
diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el
index 82e99a2c920..a2c9f73fc73 100644
--- a/lisp/progmodes/eglot.el
+++ b/lisp/progmodes/eglot.el
@@ -2813,6 +2813,8 @@ eglot--signal-textDocument/didChange
 
 (defun eglot--signal-textDocument/didOpen ()
   "Send textDocument/didOpen to server."
+  ;; Flush any potential pending change.
+  (eglot--track-changes-fetch eglot--track-changes)
   (setq eglot--recent-changes nil
         eglot--versioned-identifier 0
         eglot--TextDocumentIdentifier-cache nil)