[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/eglot 56cf02d 126/139: Rework autoreconnection logic
From: |
João Távora |
Subject: |
[elpa] externals/eglot 56cf02d 126/139: Rework autoreconnection logic |
Date: |
Mon, 14 May 2018 09:55:09 -0400 (EDT) |
branch: externals/eglot
commit 56cf02da4e832e6f38ff9aa9a3fffb1002710b8b
Author: João Távora <address@hidden>
Commit: João Távora <address@hidden>
Rework autoreconnection logic
Can't be a global var, has to be a per process thing.
* eglot.el (eglot-autoreconnect): New defcustom
(eglot--inhibit-autoreconnect): Renamed from eglot--inhibit-autoreconnect
(eglot--connect): Run autoreconnect timer here.
(eglot--inhibit-auto-reconnect): Removed.
(eglot--process-sentinel): Don't run timer here. Rework.
(eglot, eglot-reconnect): Pass INTERACTIVE to eglot--connect.
---
eglot.el | 57 +++++++++++++++++++++++++++++++++++----------------------
1 file changed, 35 insertions(+), 22 deletions(-)
diff --git a/eglot.el b/eglot.el
index 3b3aada..aabaf54 100644
--- a/eglot.el
+++ b/eglot.el
@@ -59,9 +59,19 @@
"Face for package-name in EGLOT's mode line.")
(defcustom eglot-request-timeout 10
- "How many seconds to way for a reply from the server."
+ "How many seconds to wait for a reply from the server."
:type :integer)
+(defcustom eglot-autoreconnect 3
+ "Control EGLOT's ability to reconnect automatically.
+If t, always reconnect automatically (not recommended). If nil,
+never reconnect automatically after unexpected server shutdowns,
+crashes or network failures. A positive integer number says to
+only autoreconnect if the previous successful connection attempt
+lasted more than that many seconds."
+ :type '(choice (boolean :tag "Whether to inhibit autoreconnection")
+ (integer :tag "Number of seconds")))
+
;;; Process management
(defvar eglot--processes-by-project (make-hash-table :test #'equal)
@@ -129,6 +139,9 @@ A list (ID WHAT DONE-P).")
"Status as declared by the server.
A list (WHAT SERIOUS-P).")
+(eglot--define-process-var eglot--inhibit-autoreconnect eglot-autoreconnect
+ "If non-nil, don't autoreconnect on unexpected quit.")
+
(eglot--define-process-var eglot--contact nil
"Method used to contact a server.
Either a list of strings (a shell command and arguments), or a
@@ -206,8 +219,9 @@ CONTACT is as `eglot--contact'. Returns a process object."
:publishDiagnostics `(:relatedInformation :json-false))
:experimental (eglot--obj)))
-(defun eglot--connect (project managed-major-mode short-name contact)
- "Connect for PROJECT, MANAGED-MAJOR-MODE, SHORT-NAME and CONTACT."
+(defun eglot--connect (project managed-major-mode short-name contact
interactive)
+ "Connect for PROJECT, MANAGED-MAJOR-MODE, SHORT-NAME and CONTACT.
+INTERACTIVE is t if inside interactive call."
(let* ((proc (eglot--make-process short-name managed-major-mode contact))
(buffer (process-buffer proc)))
(setf (eglot--contact proc) contact
@@ -215,6 +229,15 @@ CONTACT is as `eglot--contact'. Returns a process object."
(eglot--major-mode proc) managed-major-mode)
(with-current-buffer buffer
(let ((inhibit-read-only t))
+ (setf (eglot--inhibit-autoreconnect proc)
+ (cond
+ ((booleanp eglot-autoreconnect) (not eglot-autoreconnect))
+ (interactive nil)
+ ((cl-plusp eglot-autoreconnect)
+ (run-with-timer eglot-autoreconnect nil
+ (lambda ()
+ (setf (eglot--inhibit-autoreconnect proc)
+ (null eglot-autoreconnect)))))))
(setf (eglot--short-name proc) short-name)
(push proc (gethash project eglot--processes-by-project))
(erase-buffer)
@@ -317,7 +340,8 @@ INTERACTIVE is t if called interactively."
(let ((proc (eglot--connect project
managed-major-mode
short-name
- command)))
+ command
+ interactive)))
(eglot--message "Connected! Process `%s' now \
managing `%s' buffers in project `%s'."
proc managed-major-mode short-name))))))
@@ -331,12 +355,10 @@ INTERACTIVE is t if called interactively."
(eglot--connect (eglot--project process)
(eglot--major-mode process)
(eglot--short-name process)
- (eglot--contact process))
+ (eglot--contact process)
+ interactive)
(eglot--message "Reconnected!"))
-(defvar eglot--inhibit-auto-reconnect nil
- "If non-nil, don't autoreconnect on unexpected quit.")
-
(defun eglot--process-sentinel (proc change)
"Called when PROC undergoes CHANGE."
(eglot--log-event proc `(:message "Process state changed" :change ,change))
@@ -364,22 +386,13 @@ INTERACTIVE is t if called interactively."
(setf (gethash (eglot--project proc) eglot--processes-by-project)
(delq proc
(gethash (eglot--project proc) eglot--processes-by-project)))
- (cond ((eglot--moribund proc)
- (eglot--message "(sentinel) Moribund process exited with status
%s"
- (process-exit-status proc)))
- ((null eglot--inhibit-auto-reconnect)
- (eglot--warn
- "(sentinel) Reconnecting after process unexpectedly changed to
`%s'."
- change)
- (setq eglot--inhibit-auto-reconnect
- (run-with-timer 3 nil
- (lambda ()
- (setq eglot--inhibit-auto-reconnect
nil))))
+ (eglot--message "Server exited with status %s" (process-exit-status
proc))
+ (cond ((eglot--moribund proc))
+ ((not (eglot--inhibit-autoreconnect proc))
+ (eglot--warn "Reconnecting unexpected server exit.")
(eglot-reconnect proc))
(t
- (eglot--warn
- "(sentinel) Not auto-reconnecting, last one didn't last long."
- change)))
+ (eglot--warn "Not auto-reconnecting, last one didn't last
long.")))
(delete-process proc))))
(defun eglot--process-filter (proc string)
- [elpa] externals/eglot 764347d 128/139: New command eglot-help-at-point and a README update, (continued)
- [elpa] externals/eglot 764347d 128/139: New command eglot-help-at-point and a README update, João Távora, 2018/05/14
- [elpa] externals/eglot 9bf3166 136/139: Don't define a menu if nothing to show there for now, João Távora, 2018/05/14
- [elpa] externals/eglot 54fc885 113/139: More RLS-specifics: update Flymake diags when indexing done, João Távora, 2018/05/14
- [elpa] externals/eglot 56c2e1d 104/139: Get rid of eglot-mode, João Távora, 2018/05/14
- [elpa] externals/eglot 9577dfc 125/139: Duh, json.el is in Emacs, and json-mode.el is useless here, João Távora, 2018/05/14
- [elpa] externals/eglot d33a9b5 103/139: Simplify eglot--signal-textDocument/didChange, João Távora, 2018/05/14
- [elpa] externals/eglot ef80455 121/139: Support :completionItem/resolve, João Távora, 2018/05/14
- [elpa] externals/eglot f89f859 114/139: Simplify mode-line updating logic, João Távora, 2018/05/14
- [elpa] externals/eglot 3a6c637 099/139: Support textDocument/rename, João Távora, 2018/05/14
- [elpa] externals/eglot 581608f 115/139: Resist server failure during synchronous requests, João Távora, 2018/05/14
- [elpa] externals/eglot 56cf02d 126/139: Rework autoreconnection logic,
João Távora <=
- [elpa] externals/eglot 4c0bfc3 139/139: Support didChangeWatchedFiles with dynamic registration, João Távora, 2018/05/14
- [elpa] externals/eglot 42177d0 107/139: New "deferred requests" that wait until server is ready, João Távora, 2018/05/14
- [elpa] externals/eglot 29f6b4c 129/139: Tweak README.md, João Távora, 2018/05/14
- [elpa] externals/eglot 1fb2bcb 132/139: Ask server for textDocument/signatureHelp if it supports it, João Távora, 2018/05/14
- [elpa] externals/eglot e63dad0 092/139: Simplify mode-line code with a helper., João Távora, 2018/05/14
- [elpa] externals/eglot ab575d2 120/139: Rename functions. eglot--request is now the synchronous one, João Távora, 2018/05/14
- [elpa] externals/eglot 41f5922 137/139: Now send willSaveWaitUntil, João Távora, 2018/05/14
- [elpa] externals/eglot 458bc69 110/139: More correctly setup rust-mode-related autoloads, João Távora, 2018/05/14
- [elpa] externals/eglot 9af84a2 124/139: Prepare to sumbit to GNU ELPA, João Távora, 2018/05/14
- [elpa] externals/eglot 0625b6c 123/139: (eglot--xref-make): Fix Use of cl-destructuring-bind., João Távora, 2018/05/14