[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/eglot 21886be 08/62: Close #44: Robustify in the face o
From: |
Stefan Monnier |
Subject: |
[elpa] externals/eglot 21886be 08/62: Close #44: Robustify in the face of manual mode changes |
Date: |
Sat, 29 Sep 2018 17:13:28 -0400 (EDT) |
branch: externals/eglot
commit 21886bedc344d69550e8bb1d56bc6608d1f65a07
Author: João Távora <address@hidden>
Commit: João Távora <address@hidden>
Close #44: Robustify in the face of manual mode changes
When manually changing the major-mode of a managed buffer, this sends
a didClose and tears down Eglot-related stuff like if were killing the
buffer. After changing the mode, we have to recheck that we are now
not managed by another server (or by the same server, in case we
changed the mode to be the same mode).
* eglot.el (eglot-shutdown): Use eglot--with-live-buffer
(eglot--on-shutdown): Use eglot--with-live-buffer
(eglot--managed-mode): Use change-major-mode-hook.
(eglot--managed-mode-onoff): Change protocol. Turn off when called
with no arguments.
(eglot--maybe-activate-editing-mode): Don't do anything if mode is
already active. Suitable for calling from
after-change-major-mode-hook.
(after-change-major-mode-hook): Add
eglot--maybe-activate-editing-mode.
---
eglot.el | 53 ++++++++++++++++++++++++++++++++---------------------
1 file changed, 32 insertions(+), 21 deletions(-)
diff --git a/eglot.el b/eglot.el
index 8f9a43d..49a1f3d 100644
--- a/eglot.el
+++ b/eglot.el
@@ -244,7 +244,7 @@ Don't leave this function with the server still running."
(ignore-errors (jsonrpc-request server :exit nil :timeout 1)))
;; Turn off `eglot--managed-mode' where appropriate.
(dolist (buffer (eglot--managed-buffers server))
- (with-current-buffer buffer (eglot--managed-mode-onoff server -1)))
+ (eglot--with-live-buffer buffer (eglot--managed-mode-onoff server nil)))
;; Now ask jsonrpc.el to shutdown server (which in normal
;; conditions should return immediately).
(jsonrpc-shutdown server)))
@@ -253,7 +253,7 @@ Don't leave this function with the server still running."
"Called by jsonrpc.el when SERVER is already dead."
;; Turn off `eglot--managed-mode' where appropriate.
(dolist (buffer (eglot--managed-buffers server))
- (with-current-buffer buffer (eglot--managed-mode-onoff server -1)))
+ (eglot--with-live-buffer buffer (eglot--managed-mode-onoff server nil)))
;; Kill any expensive watches
(maphash (lambda (_id watches)
(mapcar #'file-notify-rm-watch watches))
@@ -691,11 +691,13 @@ If optional MARKERS, make markers."
(add-hook 'before-change-functions 'eglot--before-change nil t)
(add-hook 'flymake-diagnostic-functions 'eglot-flymake-backend nil t)
(add-hook 'kill-buffer-hook 'eglot--signal-textDocument/didClose nil t)
+ (add-hook 'kill-buffer-hook 'eglot--managed-mode-onoff nil t)
(add-hook 'before-revert-hook 'eglot--signal-textDocument/didClose nil t)
(add-hook 'before-save-hook 'eglot--signal-textDocument/willSave nil t)
(add-hook 'after-save-hook 'eglot--signal-textDocument/didSave nil t)
(add-hook 'xref-backend-functions 'eglot-xref-backend nil t)
(add-hook 'completion-at-point-functions #'eglot-completion-at-point nil t)
+ (add-hook 'change-major-mode-hook 'eglot--managed-mode-onoff nil t)
(add-function :before-until (local 'eldoc-documentation-function)
#'eglot-eldoc-function)
(add-function :around (local 'imenu-create-index-function) #'eglot-imenu))
@@ -709,6 +711,7 @@ If optional MARKERS, make markers."
(remove-hook 'after-save-hook 'eglot--signal-textDocument/didSave t)
(remove-hook 'xref-backend-functions 'eglot-xref-backend t)
(remove-hook 'completion-at-point-functions #'eglot-completion-at-point t)
+ (remove-hook 'change-major-mode-hook #'eglot--managed-mode-onoff t)
(remove-function (local 'eldoc-documentation-function)
#'eglot-eldoc-function)
(remove-function (local 'imenu-create-index-function) #'eglot-imenu)
@@ -718,17 +721,22 @@ If optional MARKERS, make markers."
"A cached reference to the current EGLOT server.
Reset in `eglot--managed-mode-onoff'.")
-(defun eglot--managed-mode-onoff (server arg)
- "Proxy for function `eglot--managed-mode' with ARG and SERVER."
- (eglot--managed-mode arg)
+(defun eglot--managed-mode-onoff (&optional server turn-on)
+ "Proxy for function `eglot--managed-mode' with TURN-ON and SERVER."
(let ((buf (current-buffer)))
- (cond (eglot--managed-mode
+ (cond ((and server turn-on)
+ (eglot--managed-mode 1)
(setq eglot--cached-current-server server)
(cl-pushnew buf (eglot--managed-buffers server)))
(t
- (setq eglot--cached-current-server nil)
- (setf (eglot--managed-buffers server)
- (delq buf (eglot--managed-buffers server)))))))
+ (eglot--managed-mode -1)
+ (let ((server
+ (or server
+ eglot--cached-current-server)))
+ (setq eglot--cached-current-server nil)
+ (when server
+ (setf (eglot--managed-buffers server)
+ (delq buf (eglot--managed-buffers server)))))))))
(add-hook 'eglot--managed-mode-hook 'flymake-mode)
(add-hook 'eglot--managed-mode-hook 'eldoc-mode)
@@ -754,21 +762,24 @@ Reset in `eglot--managed-mode-onoff'.")
"Maybe activate mode function `eglot--managed-mode'.
If SERVER is supplied, do it only if BUFFER is managed by it. In
that case, also signal textDocument/didOpen."
- (unless server
- (when eglot--cached-current-server
- (display-warning
- :eglot "`eglot--cached-current-server' is non-nil, but it should be!\n\
+ (unless eglot--managed-mode
+ (unless server
+ (when eglot--cached-current-server
+ (display-warning
+ :eglot "`eglot--cached-current-server' is non-nil, but it shouldn't
be!\n\
Please report this as a possible bug.")
- (setq eglot--cached-current-server nil)))
- ;; Called even when revert-buffer-in-progress-p
- (let* ((cur (and buffer-file-name (eglot--current-server)))
- (server (or (and (null server) cur) (and server (eq server cur)
cur))))
- (when server
- (setq eglot--unreported-diagnostics `(:just-opened . nil))
- (eglot--managed-mode-onoff server 1)
- (eglot--signal-textDocument/didOpen))))
+ (setq eglot--cached-current-server nil)))
+ ;; Called even when revert-buffer-in-progress-p
+ (let* ((cur (and buffer-file-name (eglot--current-server)))
+ (server (or (and (null server) cur) (and server (eq server cur)
cur))))
+ (when server
+ (setq eglot--unreported-diagnostics `(:just-opened . nil))
+ (eglot--managed-mode-onoff server t)
+ (eglot--signal-textDocument/didOpen)))))
+
(add-hook 'find-file-hook 'eglot--maybe-activate-editing-mode)
+(add-hook 'after-change-major-mode-hook 'eglot--maybe-activate-editing-mode)
(defun eglot-clear-status (server)
"Clear the last JSONRPC error for SERVER."
- [elpa] externals/eglot 83d7025 36/62: Close #68: Implement asynchronous server connection, (continued)
- [elpa] externals/eglot 83d7025 36/62: Close #68: Implement asynchronous server connection, Stefan Monnier, 2018/09/29
- [elpa] externals/eglot 2355e17 23/62: Per #63: Accept functions as entries in eglot-server-programs, Stefan Monnier, 2018/09/29
- [elpa] externals/eglot c0f9db7 46/62: Per #74: Don't error if server replies with empty hover message, Stefan Monnier, 2018/09/29
- [elpa] externals/eglot be15bb1 43/62: Per #74: Fix eglot-capabilities when querying for multiple features, Stefan Monnier, 2018/09/29
- [elpa] externals/eglot 15040a6 48/62: Improve snippet support, Stefan Monnier, 2018/09/29
- [elpa] externals/eglot d88f6aa 54/62: Close #86: Handle case when :textDocumentSync isn't a number, Stefan Monnier, 2018/09/29
- [elpa] externals/eglot 42fffa5 16/62: Close #54: Correctly make LSP positions in narrowed buffers, Stefan Monnier, 2018/09/29
- [elpa] externals/eglot e935718 20/62: Fix placement of diagnostics with same start and end positions, Stefan Monnier, 2018/09/29
- [elpa] externals/eglot 88ebed6 17/62: Implement TextDocument/rangeFormatting, Stefan Monnier, 2018/09/29
- [elpa] externals/eglot 792dc6b 28/62: * eglot.el (advice-add jsonrpc-request): Add &allow-other-keys, Stefan Monnier, 2018/09/29
- [elpa] externals/eglot 21886be 08/62: Close #44: Robustify in the face of manual mode changes,
Stefan Monnier <=
- [elpa] externals/eglot 6b14711 18/62: * eglot.el (eglot-client-capabilities): Fix a typo., Stefan Monnier, 2018/09/29
- [elpa] externals/eglot 4c019bd 24/62: * eglot.el (eglot-initialization-options): Fix spurious typo., Stefan Monnier, 2018/09/29
- [elpa] externals/eglot a62c2da 25/62: Close #60: Notify server of recent changes before save notification, Stefan Monnier, 2018/09/29
- [elpa] externals/eglot c8191b2 32/62: Improve eglot-execute-command API to ease overriding by servers, Stefan Monnier, 2018/09/29
- [elpa] externals/eglot 991d129 34/62: * README.md (Build Status): Show status for master, Stefan Monnier, 2018/09/29
- [elpa] externals/eglot ae37c2a 35/62: Add a test for eglot-ensure. Make, Stefan Monnier, 2018/09/29
- [elpa] externals/eglot cac728a 33/62: Kill server's output and events buffers from eglot-shutdown (#66), Stefan Monnier, 2018/09/29
- [elpa] externals/eglot 9ae03af 39/62: Close #41: Control the size of the events buffer, Stefan Monnier, 2018/09/29
- [elpa] externals/eglot c25c0e3 40/62: Close #64: handle edits to same position in the correct order, Stefan Monnier, 2018/09/29
- [elpa] externals/eglot 6874895 42/62: Close #73: Prompt for server in interactive eglot-shutdown, Stefan Monnier, 2018/09/29