Subject: Re: bug#70724: 29.2.50; eglot-reconnect errors when the project is deleted
From: Dmitry Gutov <[email-masked]>
To: Spencer Baugh <[email-masked]>, [email-masked]
Cc: [email-masked],João Távora <[email-masked]>
Date: Thu, 6 Jun 2024 23:36:11 +0300
List-Id: <debbugs-submit.debbugs.gnu.org>

On 04/05/2024 04:09, Dmitry Gutov wrote:
> 
> I think I like this solution (as long as the nil value returned by 
> project-current on this step is appropriately handled).
> 
> Something like:
> 
> diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el
> index 6896baf30ce..7b2461c3ce6 100644
> --- a/lisp/progmodes/eglot.el
> +++ b/lisp/progmodes/eglot.el
> @@ -1426,11 +1426,15 @@ eglot-reconnect
>     (interactive (list (eglot--current-server-or-lose) t))
>     (when (jsonrpc-running-p server)
>       (ignore-errors (eglot-shutdown server interactive nil 
> 'preserve-buffers)))
> -  (eglot--connect (eglot--major-modes server)
> -                  (eglot--project server)
> -                  (eieio-object-class-name server)
> -                  (eglot--saved-initargs server)
> -                  (eglot--language-ids server))
> +  (let* ((root (project-root (eglot--project server)))
> +         (project (project-current nil root)))
> +    (if (not project)
> +        (eglot--error "Project in `%s' is gone!" root)
> +      (eglot--connect (eglot--major-modes server)
> +                      project
> +                      (eieio-object-class-name server)
> +                      (eglot--saved-initargs server)
> +                      (eglot--language-ids server))))
>     (eglot--message "Reconnected!"))
> 
>   (defvar eglot--managed-mode) ; forward decl

Okay, I've pushed a slightly revised version of this patch now. It makes 
sense to me, even if some caching issues might remain in project backend(s).

Spencer, please see if it takes care of your scenario.