[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/elpa 56cf02d 126/139: Rework autoreconnection logic
From: |
João Távora |
Subject: |
[elpa] externals/elpa 56cf02d 126/139: Rework autoreconnection logic |
Date: |
Mon, 14 May 2018 09:53:49 -0400 (EDT) |
branch: externals/elpa
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/elpa 23b79e0 111/139: Shorten summary line to appease package-lint.el, (continued)
- [elpa] externals/elpa 23b79e0 111/139: Shorten summary line to appease package-lint.el, João Távora, 2018/05/14
- [elpa] externals/elpa 24466a9 096/139: When killing server, always wait 3 seconds, João Távora, 2018/05/14
- [elpa] externals/elpa 3a6c637 099/139: Support textDocument/rename, João Távora, 2018/05/14
- [elpa] externals/elpa 458bc69 110/139: More correctly setup rust-mode-related autoloads, João Távora, 2018/05/14
- [elpa] externals/elpa 3dcbc30 109/139: Add minimal headers, commentary and autoloads, João Távora, 2018/05/14
- [elpa] externals/elpa 581608f 115/139: Resist server failure during synchronous requests, João Távora, 2018/05/14
- [elpa] externals/elpa 41f5922 137/139: Now send willSaveWaitUntil, João Távora, 2018/05/14
- [elpa] externals/elpa 05c67ee 112/139: Adjust flymake integration, João Távora, 2018/05/14
- [elpa] externals/elpa f89f859 114/139: Simplify mode-line updating logic, João Távora, 2018/05/14
- [elpa] externals/elpa 0625b6c 123/139: (eglot--xref-make): Fix Use of cl-destructuring-bind., João Távora, 2018/05/14
- [elpa] externals/elpa 56cf02d 126/139: Rework autoreconnection logic,
João Távora <=
- [elpa] externals/elpa 49fb02f 135/139: Use RLS in Travis CI and add actual tests, João Távora, 2018/05/14
- [elpa] externals/elpa 29f58a6 127/139: Get rid of catch/loop/throw idiom (suggested by Thien-Thi Nguyen), João Távora, 2018/05/14
- [elpa] externals/elpa 418412b 131/139: Fix copyright header. Obviously not since 2003, João Távora, 2018/05/14
- [elpa] externals/elpa 54fc885 113/139: More RLS-specifics: update Flymake diags when indexing done, João Távora, 2018/05/14
- [elpa] externals/elpa 8a80fb7 105/139: Simplify `eglot-shutdown`, João Távora, 2018/05/14
- [elpa] externals/elpa d40f9ac 094/139: Half-decent imenu support via textDocument/documentSymbol, João Távora, 2018/05/14
- [elpa] externals/elpa 42177d0 107/139: New "deferred requests" that wait until server is ready, João Távora, 2018/05/14
- [elpa] externals/elpa ef80455 121/139: Support :completionItem/resolve, João Távora, 2018/05/14
- [elpa] externals/elpa 77856c2 130/139: Reinstate the catch/loop/throw idiom in eglot-request, João Távora, 2018/05/14
- [elpa] externals/elpa d1cdcf1 119/139: Friendlier M-x eglot, João Távora, 2018/05/14