[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/elpa be52e1e 037/139: Rework connection restarting agai
From: |
João Távora |
Subject: |
[elpa] externals/elpa be52e1e 037/139: Rework connection restarting again |
Date: |
Mon, 14 May 2018 09:53:30 -0400 (EDT) |
branch: externals/elpa
commit be52e1ee6a39c6f775a308c229c7a75ac28485bd
Author: João Távora <address@hidden>
Commit: João Távora <address@hidden>
Rework connection restarting again
Quitting a process removes it from the project.
* eglot.el (eglot-editing-mode,eglot-mode): Forward declare.
(eglot--project): New process-local var.
(eglot--connect): Takes a project.
(eglot-new-process): Rework.
(eglot--sentinel): Remove proc from eglot--processes-by-project.
---
eglot.el | 85 ++++++++++++++++++++++++++++++++++++++--------------------------
1 file changed, 51 insertions(+), 34 deletions(-)
diff --git a/eglot.el b/eglot.el
index b9aa94c..12e7fef 100644
--- a/eglot.el
+++ b/eglot.el
@@ -44,6 +44,9 @@
(defvar eglot--processes-by-project (make-hash-table :test #'equal))
+(defvar eglot-editing-mode) ; forward decl
+(defvar eglot-mode) ; forward decl
+
(defvar eglot--special-buffer-process nil
"Current buffer's eglot process.")
@@ -103,6 +106,9 @@ after setting it."
(eglot--define-process-var eglot--moribund nil
"Non-nil if process is about to exit")
+(eglot--define-process-var eglot--project nil
+ "The project the process belongs to.")
+
(eglot--define-process-var eglot--spinner `(nil nil t)
"\"Spinner\" used by some servers.
A list (ID WHAT DONE-P)." t)
@@ -134,12 +140,13 @@ Returns a process object."
name)))))
proc))
-(defun eglot--connect (short-name bootstrap-fn &optional success-fn)
- "Make a connection with SHORT-NAME and BOOTSTRAP-FN.
+(defun eglot--connect (project short-name bootstrap-fn &optional success-fn)
+ "Make a connection with PROJECT, SHORT-NAME and BOOTSTRAP-FN.
Call SUCCESS-FN with no args if all goes well."
(let* ((proc (funcall bootstrap-fn short-name))
(buffer (process-buffer proc)))
- (setf (eglot--bootstrap-fn proc) bootstrap-fn)
+ (setf (eglot--bootstrap-fn proc) bootstrap-fn
+ (eglot--project proc) project)
(with-current-buffer buffer
(let ((inhibit-read-only t))
(setf (eglot--short-name proc) short-name)
@@ -164,48 +171,57 @@ INTERACTIVE is t if called interactively."
(interactive (list (eglot--current-process-or-lose) t))
(when (process-live-p process)
(eglot-quit-server process 'sync interactive))
- (eglot--connect (eglot--short-name process)
- (eglot--bootstrap-fn process)
- (lambda ()
- (eglot--message "Reconnected"))))
+ (eglot--connect
+ (eglot--project process)
+ (eglot--short-name process)
+ (eglot--bootstrap-fn process)
+ (lambda ()
+ (eglot--message "Reconnected"))))
(defun eglot-new-process (&optional interactive)
"Start a new EGLOT process and initialize it.
INTERACTIVE is t if called interactively."
(interactive (list t))
(let ((project (project-current)))
- (unless project (eglot--error "(new-process) Cannot work without a current
project!"))
+ (unless project (eglot--error
+ "(new-process) Cannot work without a current project!"))
(let ((current-process (eglot--current-process))
(command (let ((probe (cdr (assoc major-mode eglot-executables))))
(unless probe
(eglot--error "Don't know how to start EGLOT for %s
buffers"
major-mode))
probe)))
- (cond ((and current-process
- (process-live-p current-process))
- (eglot--message "(new-process) Reconnecting instead")
- (eglot-reconnect current-process interactive))
- (t
- (eglot--connect
- (file-name-base
- (directory-file-name
- (car (project-roots (project-current)))))
- (lambda (name)
- (eglot-make-local-process
- name
- command))
- (lambda ()
- (eglot--message "Connected")
- (dolist (buffer (buffer-list))
- (with-current-buffer buffer
- (if (and buffer-file-name
- (cl-some
- (lambda (root)
- (string-prefix-p
- (expand-file-name root)
- (expand-file-name buffer-file-name)))
- (project-roots project)))
- (eglot--signalDidOpen)))))))))))
+ (cond
+ ((and current-process
+ (process-live-p current-process))
+ (when (and
+ interactive
+ (y-or-n-p "[eglot] Live process found, reconnect instead? "))
+ (eglot-reconnect current-process interactive)))
+ (t
+ (eglot--connect
+ project
+ (file-name-base
+ (directory-file-name
+ (car (project-roots (project-current)))))
+ (lambda (name)
+ (eglot-make-local-process
+ name
+ command))
+ (lambda ()
+ (eglot--message "Connected")
+ (dolist (buffer (buffer-list))
+ (with-current-buffer buffer
+ (when(and buffer-file-name
+ (cl-some
+ (lambda (root)
+ (string-prefix-p
+ (expand-file-name root)
+ (expand-file-name buffer-file-name)))
+ (project-roots project)))
+ (unless eglot-editing-mode
+ (eglot-editing-mode 1))
+ (eglot--signalDidOpen)))))))))))
(defun eglot--process-sentinel (process change)
"Called with PROCESS undergoes CHANGE."
@@ -221,7 +237,8 @@ INTERACTIVE is t if called interactively."
(eglot--pending-continuations process))
(cond ((eglot--moribund process)
(eglot--message "(sentinel) Moribund process exited with status %s"
- (process-exit-status process)))
+ (process-exit-status process))
+ (remhash (eglot--project process) eglot--processes-by-project))
(t
(eglot--warn
"(sentinel) Reconnecting after process unexpectedly changed to %s."
- [elpa] externals/elpa f7f77e1 044/139: Make M-x eglot the main entry point, (continued)
- [elpa] externals/elpa f7f77e1 044/139: Make M-x eglot the main entry point, João Távora, 2018/05/14
- [elpa] externals/elpa 51ff863 046/139: Must re-announce didOpen after reconnect, João Távora, 2018/05/14
- [elpa] externals/elpa d2eca65 045/139: Fix another Flymake sync bug, João Távora, 2018/05/14
- [elpa] externals/elpa c95a0a4 041/139: Multiple servers per project are possible, João Távora, 2018/05/14
- [elpa] externals/elpa e60c7fc 013/139: Overhaul async mechanism safety, João Távora, 2018/05/14
- [elpa] externals/elpa a3545fb 050/139: Rename RPC methods for clarity, João Távora, 2018/05/14
- [elpa] externals/elpa 4d4b85d 061/139: eglot-editing-mode becomes eglot--managed-mode, João Távora, 2018/05/14
- [elpa] externals/elpa 4f246b5 017/139: * eglot.el (eglot-mode-map): Move up before minor mode., João Távora, 2018/05/14
- [elpa] externals/elpa a4f99e0 005/139: Introduce and use `eglot--current-process-or-lose', João Távora, 2018/05/14
- [elpa] externals/elpa 8e6488f 023/139: Don't switch to possibly dead buffer in sentinel, João Távora, 2018/05/14
- [elpa] externals/elpa be52e1e 037/139: Rework connection restarting again,
João Távora <=
- [elpa] externals/elpa cc183a6 043/139: Fix assorted bugs, João Távora, 2018/05/14
- [elpa] externals/elpa e8f859e 031/139: Rework commands for connecting and reconnecting, João Távora, 2018/05/14
- [elpa] externals/elpa b511b7d 036/139: Redesign and simplify parser, João Távora, 2018/05/14
- [elpa] externals/elpa b4dd4f8 022/139: Report server status in the mode-line, João Távora, 2018/05/14
- [elpa] externals/elpa 46bb1c0 049/139: Reorganize file, João Távora, 2018/05/14
- [elpa] externals/elpa b69302c 060/139: Make M-x eglot's interactive spec a separate function, João Távora, 2018/05/14
- [elpa] externals/elpa b657b32 068/139: Use rootUri instead of rootPath, João Távora, 2018/05/14
- [elpa] externals/elpa eebd32b 059/139: When user declines to reconnect, first quit existing server, João Távora, 2018/05/14
- [elpa] externals/elpa f1b6485 053/139: Trim some edges and add a bunch of boring RPC methods, João Távora, 2018/05/14
- [elpa] externals/elpa df5d76d 065/139: Reply to client/registerCapability (don't handle it yet), João Távora, 2018/05/14