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