Subject: bug#61350: Eglot over Tramp freezes with large project

From: João Távora <[email-masked]>
Date: Thu, 23 Feb 2023 12:17:30 +0000

Michael Albinus <[email-masked]> wrote:

> The problem is clear. We are in jsonrpc--process-filter (accepting process
> output). This runs eglot-handle-notification, and that runs
> file-truename. The latter needs to check remote, so Tramp sends a remote
> command, and waits for that output (calling accept-process-output again).
>  
> Since jsonrpc always accepts output from *all* running processes, there
> could be (and is!) the constellation, that process output has been read
> already, and Tramp didn't get it, waiting for the output forever. I
> could mitigate the problem partly by changing the arguments of
> accept-process-output in jsonrpc-request, and eglot could work
> successfully, sometimes. And sometimes not. And even then, I ran into
> the famous "Forbidden reentrant call" error, see bug#60534.

I see the problem more or less, indeed, thanks for reproducing it and
clarifying it.

Can you try your experiment again after evaluating these two lines?

  (cl-defmethod eglot-handle-notification :around (_ _ &key &allow-other-keys)
    (run-at-time 0 nil (lambda () (cl-call-next-method))))

This makes the notification handlers execute "outside" the LSP server's
process filter,  so maybe it fix it.  

I've given it very little testing and it might have other monumentally
severe consequences in non-TRAMP cases, so take it with a grain of salt.

If the fix works, maybe it could be done upstream in jsonrpc.el itself.

João