Subject: bug#73496: 30.0.91; Eglot (and clangd) out of sync after switching git branches in magit

From: João Távora <[email-masked]>
Date: Thu, 26 Sep 2024 11:25:04 +0100

On Thu, Sep 26, 2024 at 11:08 AM Eli Zaretskii <[email-masked]> wrote:
>
> > Date: Thu, 26 Sep 2024 08:20:52 +0000
> > From:  Mikael Springer via "Bug reports for GNU Emacs,
> >  the Swiss army knife of text editors" <[email-masked]>
> >
> >
> > 1. Visit buffer with C++ code -> Eglot starts.
> > 2. Listing references for a variable in Eglot works.
> > 3. Switch Git branch in magit.
> > 4. Go back to C++ buffer. Listing references for a variable using Eglot
> > does not work, error message in echo buffer; "jsonrpc-request:
> > jsonrpc-error: "request id=44 failed:", (jsonrpc-error-code . -32602),
> > (jsonrpc-error-message . "trying to get AST for non-added document"),
> > (jsonrpc-error-data)"
> > 5. Closing the buffer and opening it again fixes the problem, or doing
> > eglot-reconnect also fixes the problem, listing references is working
> > again.
> > 6. This is true for all open C++ buffers handled by Eglot before the
> > branch switch.
>
> CC'ing João.

It would be great if Mikael could make this into a Emacs -Q recipe
to ease investigation and rule out interference from configuration etc.

For example this isn't  true

  Visit buffer with C++ code -> Eglot starts.

unless you use eglot-ensure in your config.  And possibly Magit isn't
needed to trigger this, a simple Git branch change on the side will do (or
maybe it won't in which case Magit has to be investigated, too).

A concrete example toy repo with, say, a single file would also
be useful.

João.