Fix M-x eglot prompt when connection already exists (bug#60557)

Before this change, if a current connection existed at the time of M-x
eglot, user would be first asked to enter into M-x eglot's interactive
spec details about new command line arguments, and only afterwards be
prompted about what to do with the current connection (which could be
to reconnect to it using the same arguments, or tear it down and make
a new one).

This is very confusing, as users may not be fully aware of the
distinction between "reconnect" vs "disconnect-and-connect".  They
might not know if any new command line arguments provided are taking
effect or not.

This change simplifies this and removes the option to "reconnect
instead" from M-x eglot (users can do that at any time via M-x
eglot-reconnect).  It also ensures that users are informed about a
current connection before asking to enter new command line arguments
and not the other way round.

* lisp/progmodes/eglot.el (eglot): Rework.
This commit is contained in:
João Távora 2023-01-16 11:48:09 +00:00
parent 3d1e74c82a
commit 67df34c143

View file

@ -1113,16 +1113,16 @@ LANGUAGE-ID is the language ID string to send to the server for
MANAGED-MAJOR-MODE, which matters to a minority of servers. MANAGED-MAJOR-MODE, which matters to a minority of servers.
INTERACTIVE is t if called interactively." INTERACTIVE is t if called interactively."
(interactive (append (eglot--guess-contact t) '(t))) (interactive
(setq managed-major-mode (eglot--ensure-list managed-major-mode)) (let ((current-server (eglot-current-server)))
(let* ((current-server (eglot-current-server)) (unless (or (null current-server)
(live-p (and current-server (jsonrpc-running-p current-server)))) (y-or-n-p "\
(if (and live-p [eglot] Shut down current connection before attempting new one?"))
interactive (user-error "[eglot] Connection attempt aborted by user."))
(y-or-n-p "[eglot] Live process found, reconnect instead? ")) (prog1 (append (eglot--guess-contact t) '(t))
(eglot-reconnect current-server interactive) (when current-server (ignore-errors (eglot-shutdown current-server))))))
(when live-p (ignore-errors (eglot-shutdown current-server))) (eglot--connect (eglot--ensure-list managed-major-mode)
(eglot--connect managed-major-mode project class contact language-id)))) project class contact language-id))
(defun eglot-reconnect (server &optional interactive) (defun eglot-reconnect (server &optional interactive)
"Reconnect to SERVER. "Reconnect to SERVER.