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

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

[elpa] externals/eglot 2da7d92 50/69: Simplify JSONRPC status setting


From: João Távora
Subject: [elpa] externals/eglot 2da7d92 50/69: Simplify JSONRPC status setting
Date: Fri, 22 Jun 2018 11:55:02 -0400 (EDT)

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

    Simplify JSONRPC status setting
    
    * eglot.el (eglot--connect): Don't set jsonrpc-status.
    (eglot-clear-status): New interactive command.
    (eglot--mode-line-format): Simplify.
    
    * jsonrpc.el (jsonrpc--async-request-1): Simplify.
    (jsonrpc-connection): Replace status with last-error.
    (jsonrpc-clear-status): Delete.
    (jsonrpc--connection-receive): Set last-error.
---
 eglot.el   | 15 ++++++++++-----
 jsonrpc.el | 24 +++++++++++-------------
 2 files changed, 21 insertions(+), 18 deletions(-)

diff --git a/eglot.el b/eglot.el
index 13413ab..f8bd32c 100644
--- a/eglot.el
+++ b/eglot.el
@@ -423,7 +423,6 @@ appeases checkdoc, that's all."
                    :initializationOptions (eglot-initialization-options server)
                    :capabilities (eglot-client-capabilities server)))
           (setf (eglot--capabilities server) capabilities)
-          (setf (jsonrpc-status server) nil)
           (dolist (buffer (buffer-list))
             (with-current-buffer buffer
               (eglot--maybe-activate-editing-mode server)))
@@ -613,6 +612,11 @@ that case, also signal textDocument/didOpen."
 
 (add-hook 'find-file-hook 'eglot--maybe-activate-editing-mode)
 
+(defun eglot-clear-status (server)
+  "Clear the last JSONRPC error for SERVER."
+  (interactive (list (jsonrpc-current-connection-or-lose)))
+  (setf (jsonrpc-last-error server) nil))
+
 
 ;;; Mode-line, menu and other sugar
 ;;;
@@ -652,7 +656,7 @@ Uses THING, FACE, DEFS and PREPEND."
                (pending (and server (hash-table-count
                                      (jsonrpc--request-continuations server))))
                (`(,_id ,doing ,done-p ,detail) (and server (eglot--spinner 
server)))
-               (`(,status ,serious-p) (and server (jsonrpc-status server))))
+               (last-error (and server (jsonrpc-last-error server))))
     (append
      `(,(eglot--mode-line-props "eglot" 'eglot-mode-line nil))
      (when nick
@@ -662,11 +666,12 @@ Uses THING, FACE, DEFS and PREPEND."
                  (mouse-1 eglot-events-buffer "go to events buffer")
                  (mouse-2 eglot-shutdown      "quit server")
                  (mouse-3 eglot-reconnect     "reconnect to server")))
-         ,@(when serious-p
+         ,@(when last-error
              `("/" ,(eglot--mode-line-props
                      "error" 'compilation-mode-line-fail
-                     '((mouse-3 jsonrpc-clear-status  "clear this status"))
-                     (format "An error occured: %s\n" status))))
+                     '((mouse-3 eglot-clear-status  "clear this status"))
+                     (format "An error occured: %s\n" (plist-get last-error
+                                                                 :message)))))
          ,@(when (and doing (not done-p))
              `("/" ,(eglot--mode-line-props
                      (format "%s%s" doing
diff --git a/jsonrpc.el b/jsonrpc.el
index 36f45ef..094b353 100644
--- a/jsonrpc.el
+++ b/jsonrpc.el
@@ -171,9 +171,9 @@ object, using the keywords `:code', `:message' and `:data'."
     :initform #'ignore
     :initarg :notification-dispatcher
     :documentation "Dispatcher for remotely invoked notifications.")
-   (status
-    :initform `(:unknown nil) :accessor jsonrpc-status
-    :documentation "Status (WHAT SERIOUS-P) as declared by the server.")
+   (last-error
+    :accessor jsonrpc-last-error
+    :documentation "Last JSONRPC error message received from endpoint.")
    (-request-continuations
     :initform (make-hash-table)
     :accessor jsonrpc--request-continuations
@@ -429,7 +429,7 @@ originated."
       message
     (let (continuations)
       (jsonrpc-log-event connection message 'server)
-      (when error (setf (jsonrpc-status connection) `(,error t)))
+      (setf (jsonrpc-last-error connection) error)
       (cond
        (;; A remote request
         (and method id)
@@ -516,11 +516,6 @@ originated."
   (interactive (list (jsonrpc-current-connection-or-lose)))
   (clrhash (jsonrpc--request-continuations connection)))
 
-(defun jsonrpc-clear-status (connection)
-  "Clear most recent error message from CONNECTION."
-  (interactive (list (jsonrpc-current-connection-or-lose)))
-  (setf (jsonrpc-status connection) nil))
-
 (defun jsonrpc--call-deferred (connection)
   "Call CONNECTION's deferred actions, who may again defer themselves."
   (when-let ((actions (hash-table-values (jsonrpc--deferred-actions 
connection))))
@@ -631,13 +626,16 @@ TIMEOUT is nil)."
              (list (or success-fn
                        (jsonrpc-lambda (&rest _ignored)
                          (jsonrpc--debug
-                          connection (jsonrpc-obj :message "success ignored" 
:id id))))
+                          connection (jsonrpc-obj :message "success ignored"
+                                                  :id id))))
                    (or error-fn
                        (jsonrpc-lambda (&key code message &allow-other-keys)
-                         (setf (jsonrpc-status connection) `(,message t))
                          (jsonrpc--debug
-                          connection (jsonrpc-obj :message "error ignored, 
status set"
-                                                  :id id :error code))))
+                          connection (jsonrpc-obj
+                                      :message
+                                      (format "error ignored, status set (%s)"
+                                              message)
+                                      :id id :error code))))
                    (setq timer (funcall make-timer)))
              (jsonrpc--request-continuations connection))
     (list id timer)))



reply via email to

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