[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/eglot be52e1e 037/139: Rework connection restarting aga
From: |
João Távora |
Subject: |
[elpa] externals/eglot be52e1e 037/139: Rework connection restarting again |
Date: |
Mon, 14 May 2018 09:54:49 -0400 (EDT) |
branch: externals/eglot
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/eglot e8f859e 031/139: Rework commands for connecting and reconnecting, (continued)
- [elpa] externals/eglot e8f859e 031/139: Rework commands for connecting and reconnecting, João Távora, 2018/05/14
- [elpa] externals/eglot 92bf3a0 038/139: Signal textDocument/didClose, João Távora, 2018/05/14
- [elpa] externals/eglot b511b7d 036/139: Redesign and simplify parser, João Távora, 2018/05/14
- [elpa] externals/eglot 328c7ae 025/139: Auto update mode-line after setting some process properties, João Távora, 2018/05/14
- [elpa] externals/eglot 2b61a3b 048/139: Delete two useless forward declarations, João Távora, 2018/05/14
- [elpa] externals/eglot 88e3655 040/139: Appease checkdoc.el, João Távora, 2018/05/14
- [elpa] externals/eglot c948713 035/139: Auto-reconnect on unexpected connection loss, João Távora, 2018/05/14
- [elpa] externals/eglot 1dc2a9f 021/139: Implement spinners and RLS's window/progress, João Távora, 2018/05/14
- [elpa] externals/eglot 931093e 032/139: Don't clutter UI with warnings, João Távora, 2018/05/14
- [elpa] externals/eglot 95983c9 028/139: Change status to error everytime an error is found, João Távora, 2018/05/14
- [elpa] externals/eglot be52e1e 037/139: Rework connection restarting again,
João Távora <=
- [elpa] externals/eglot d2eca65 045/139: Fix another Flymake sync bug, João Távora, 2018/05/14
- [elpa] externals/eglot f7f77e1 044/139: Make M-x eglot the main entry point, João Távora, 2018/05/14
- [elpa] externals/eglot d90efdf 001/139: Initial commit, João Távora, 2018/05/14
- [elpa] externals/eglot 1514e0f 052/139: Fix a couple of Rust-related edge cases, João Távora, 2018/05/14
- [elpa] externals/eglot b4dd4f8 022/139: Report server status in the mode-line, João Távora, 2018/05/14
- [elpa] externals/eglot 6689a15 026/139: Add eglot-clear-status interactive command, João Távora, 2018/05/14
- [elpa] externals/eglot a3545fb 050/139: Rename RPC methods for clarity, João Távora, 2018/05/14
- [elpa] externals/eglot 9665a3e 051/139: Fix textDocument/didChange, João Távora, 2018/05/14
- [elpa] externals/eglot eebd32b 059/139: When user declines to reconnect, first quit existing server, João Távora, 2018/05/14
- [elpa] externals/eglot 17e0ca4 047/139: Fix Flymake diagnostic positions, João Távora, 2018/05/14