emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/eglot 95c2052 09/15: Handle managed buffers in own proc


From: João Távora
Subject: [elpa] externals/eglot 95c2052 09/15: Handle managed buffers in own process var
Date: Sun, 20 May 2018 19:59:03 -0400 (EDT)

branch: externals/eglot
commit 95c20525422bd63cbda293b73c063b0fd16d3bf0
Author: João Távora <address@hidden>
Commit: João Távora <address@hidden>

    Handle managed buffers in own process var
    
    This should save some trouble when testing noninteractively.  Because
    eglot--shutdown didn't turn off the minor mode, test code running
    immediately after it could still make didClose requests, for example.
    The sentinel was the previous responsible for turning off the minor
    mode and didn't get a chance to run in that case. Now eglot--shutdown
    is also responsible for turning off the minor mode.
    
    All this should be hidden behind eglot--managed-mode-onoff.
    
    * eglot.el (eglot--managed-buffers): New process-local variable.
    (eglot--process-sentinel): Turn off managed mode.
    (eglot--managed-mode-onoff): New function.
    (eglot--managed-mode): Don't offer to kill server here.
    (eglot--buffer-managed-p): Remove.
    (eglot--maybe-activate-editing-mode): Activate mode here.
    (eglot-shutdown): Turn off minor mode here.
    (eglot--server-window/progress): Simplify slightly.
---
 eglot.el | 51 +++++++++++++++++++++++++++++----------------------
 1 file changed, 29 insertions(+), 22 deletions(-)

diff --git a/eglot.el b/eglot.el
index 13d0086..5829aff 100644
--- a/eglot.el
+++ b/eglot.el
@@ -172,6 +172,9 @@ A list (WHAT SERIOUS-P).")
 (eglot--define-process-var eglot--file-watches (make-hash-table :test #'equal)
   "File system watches for the didChangeWatchedfiles thingy.")
 
+(eglot--define-process-var eglot--managed-buffers nil
+  "Buffers managed by the server.")
+
 (defun eglot--make-process (name managed-major-mode contact)
   "Make a process from CONTACT.
 NAME is used to name the the started process or connection.
@@ -415,10 +418,8 @@ INTERACTIVE is t if called interactively."
                      (funcall error `(:code -1 :message "Server died"))))
                  (eglot--pending-continuations proc))
       ;; Turn off `eglot--managed-mode' where appropriate.
-      (dolist (buffer (buffer-list))
-        (with-current-buffer buffer
-          (when (eglot--buffer-managed-p proc)
-            (eglot--managed-mode -1))))
+      (dolist (buffer (eglot--managed-buffers proc))
+        (with-current-buffer buffer (eglot--managed-mode-onoff proc -1)))
       ;; Forget about the process-project relationship
       (setf (gethash (eglot--project proc) eglot--processes-by-project)
             (delq proc
@@ -849,19 +850,20 @@ If optional MARKERS, make markers."
     (remove-hook 'completion-at-point-functions #'eglot-completion-at-point t)
     (remove-function (local 'eldoc-documentation-function)
                      #'eglot-eldoc-function)
-    (remove-function (local imenu-create-index-function) #'eglot-imenu)
-    (let ((proc (eglot--current-process)))
-      (when (and (process-live-p proc) (y-or-n-p "[eglot] Kill server too? "))
-        (eglot-shutdown proc t))))))
+    (remove-function (local imenu-create-index-function) #'eglot-imenu))))
+
+(defun eglot--managed-mode-onoff (proc arg)
+  "Proxy for function `eglot--managed-mode' with ARG and PROC."
+  (eglot--managed-mode arg)
+  (let ((buf (current-buffer)))
+    (if eglot--managed-mode
+        (cl-pushnew buf (eglot--managed-buffers proc))
+      (setf (eglot--managed-buffers proc)
+            (delq buf (eglot--managed-buffers proc))))))
 
 (add-hook 'eglot--managed-mode-hook 'flymake-mode)
 (add-hook 'eglot--managed-mode-hook 'eldoc-mode)
 
-(defun eglot--buffer-managed-p (&optional proc)
-  "Tell if current buffer is managed by PROC."
-  (and buffer-file-name (let ((cur (eglot--current-process)))
-                          (or (and (null proc) cur)
-                              (and proc (eq proc cur))))))
 
 (defvar-local eglot--current-flymake-report-fn nil
   "Current flymake report function for this buffer")
@@ -871,11 +873,14 @@ If optional MARKERS, make markers."
 If PROC is supplied, do it only if BUFFER is managed by it.  In
 that case, also signal textDocument/didOpen."
   ;; Called even when revert-buffer-in-progress-p
-  (when (eglot--buffer-managed-p proc)
-    (eglot--managed-mode 1)
-    (eglot--signal-textDocument/didOpen)
-    (flymake-start)
-    (funcall (or eglot--current-flymake-report-fn #'ignore) nil)))
+  (let* ((cur (and buffer-file-name (eglot--current-process)))
+         (proc (or (and (null proc) cur)
+                   (and proc (eq proc cur) cur))))
+    (when proc
+      (eglot--managed-mode-onoff proc 1)
+      (eglot--signal-textDocument/didOpen)
+      (flymake-start)
+      (funcall (or eglot--current-flymake-report-fn #'ignore) nil))))
 
 (add-hook 'find-file-hook 'eglot--maybe-activate-editing-mode)
 
@@ -960,6 +965,9 @@ function with the server still running."
         (eglot--request proc :shutdown nil)
         ;; this one is supposed to always fail, hence ignore-errors
         (ignore-errors (eglot--request proc :exit nil)))
+    ;; Turn off `eglot--managed-mode' where appropriate.
+    (dolist (buffer (eglot--managed-buffers proc))
+      (with-current-buffer buffer (eglot--managed-mode-onoff proc -1)))
     (when (process-live-p proc)
       (eglot--warn "Brutally deleting non-compliant existing process %s" proc)
       (delete-process proc))))
@@ -1589,11 +1597,10 @@ Proceed? "
   "Handle notification window/progress"
   (setf (eglot--spinner process) (list id title done message))
   (when (and (equal "Indexing" title) done)
-    (dolist (buffer (buffer-list))
+    (dolist (buffer (eglot--managed-buffers process))
       (with-current-buffer buffer
-        (when (eglot--buffer-managed-p process)
-          (funcall (or eglot--current-flymake-report-fn #'ignore)
-                   eglot--unreported-diagnostics))))))
+        (funcall (or eglot--current-flymake-report-fn #'ignore)
+                 eglot--unreported-diagnostics)))))
 
 (provide 'eglot)
 ;;; eglot.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]