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

From: Dario Gjorgjevski <[email-masked]>
Date: Sun, 18 Aug 2024 22:36:01 +0200

Hi, Stefan,

On Sun, Aug 18, 2024 at 6:10 PM Stefan Monnier <[email-masked]> wrote:
>
> - Eglot errors out.  This should definitely not happen and seems like
>   a regression.  Restarting Eglot should definitely not be needed.
>
> Could you clarify what you mean by Eglot erroring out and why
> restarting it is necessary?

Eglot gets in a weird state and begins reporting erroneous data to the
LSP server.

>
> Hmm... assuming the file really started with content "foo = 0" (and no
> terminating newline), "track-changes--after (1 8 0)" looks OK: the
> revert has changed the file size by 0 chars and the new content spans
> chars from 1 to 8.  So my guess is that revert-buffer failed to call the
> `before-changes-functions` or that it called it with a smaller region
> (e.g. only the region that's actually modified (7..8), where "0" is
> turned into "1").
>
> Will have to dig deeper.

One thing I see is that the buffer becomes empty for a split second,
and is then overwritten with the new contents.  I don't know how
exactly Node.js does the overwriting, but I guess it's worth looking
into.

>
> BTW, your recipe does not mention enabling auto-revert.  Have you
> confirmed on your side that the problem shows up also in
> a vanilla config?

You're right, the problem depends on auto-revert-mode being active.
Sorry about that.

Best regards,
Dario