From 004702460d4516306d5a1bae640bce9a367715f1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jo=C3=A3o=20T=C3=A1vora?= Date: Sat, 26 May 2018 18:52:17 +0100 Subject: [PATCH] Really ensure eglot--shutdown deletes a process completely * eglot.el (eglot-lsp-server): rename slot "moribund" to "shutdown-requested" (eglot--connect): Don't check if shutdown was requested here. (eglot--process-sentinel): Set shutdown-requested to :sentinel-done here. (eglot-shutdown): use eglot--shutdown-requested. Improve check for process liveness. --- lisp/progmodes/eglot.el | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index b83e772c49e..cc3fae1f54a 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el @@ -184,9 +184,9 @@ deferred to the future." (capabilities :documentation "JSON object containing server capabilities." :accessor eglot--capabilities) - (moribund + (shutdown-requested :documentation "Flag set when server is shutting down." - :accessor eglot--moribund) + :accessor eglot--shutdown-requested) (project :documentation "Project associated with server." :initarg :project :accessor eglot--project) @@ -307,7 +307,7 @@ class SERVER-CLASS." (run-hook-with-args 'eglot-connect-hook server) (setq connect-success server)) (unless (or connect-success - (not (process-live-p proc)) (eglot--moribund server)) + (not (process-live-p proc))) (eglot-shutdown server))))) (defvar eglot--command-history nil @@ -454,7 +454,8 @@ INTERACTIVE is t if called interactively." (eglot--process server))) (delete-process proc) ;; Consider autoreconnecting - (cond ((eglot--moribund server)) + (cond ((eglot--shutdown-requested server) + (setf (eglot--shutdown-requested server) :sentinel-done)) ((not (eglot--inhibit-autoreconnect server)) (eglot--warn "Reconnecting after unexpected server exit") (eglot-reconnect server)) @@ -959,15 +960,17 @@ function with the server still running." (eglot--message "Asking %s politely to terminate" (eglot--name server)) (unwind-protect (let ((eglot-request-timeout 3)) - (setf (eglot--moribund server) t) + (setf (eglot--shutdown-requested server) t) (eglot--request server :shutdown nil) ;; this one is supposed to always fail, hence ignore-errors (ignore-errors (eglot--request server :exit nil))) ;; Turn off `eglot--managed-mode' where appropriate. (dolist (buffer (eglot--managed-buffers server)) (with-current-buffer buffer (eglot--managed-mode-onoff server -1))) - (when (process-live-p (eglot--process server)) - (eglot--warn "Brutally deleting non-compliant server %s" (eglot--name server)) + (while (progn (accept-process-output nil 0.1) + (not (eq (eglot--shutdown-requested server) :sentinel-done))) + (eglot--warn "Sentinel for %s still hasn't run, brutally deleting it!" + (eglot--process server)) (delete-process (eglot--process server))))) (cl-defmethod eglot-handle-notification -- 2.39.2