[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/eglot 59cc3fb 61/69: jsonrpc-connection-receive is now
From: |
João Távora |
Subject: |
[elpa] externals/eglot 59cc3fb 61/69: jsonrpc-connection-receive is now a public convenience function |
Date: |
Fri, 22 Jun 2018 11:55:04 -0400 (EDT) |
branch: externals/eglot
commit 59cc3fbb99bb1bc917dbfd4f8eac1a3f3fd61b8c
Author: João Távora <address@hidden>
Commit: João Távora <address@hidden>
jsonrpc-connection-receive is now a public convenience function
* jsonrpc.el (Commentary:) Mention jsonrpc-connection-receive.
(jsonrpc-connection-receive): Rename from
jsonrpc--connection-receive.
(jsonrpc--process-filter): Use jsonrpc-connection-receive.
---
jsonrpc.el | 93 ++++++++++++++++++++++++++++++++------------------------------
1 file changed, 48 insertions(+), 45 deletions(-)
diff --git a/jsonrpc.el b/jsonrpc.el
index 9a90f33..cec16b7 100644
--- a/jsonrpc.el
+++ b/jsonrpc.el
@@ -66,7 +66,8 @@
;; initiated contacts, it must arrange for the dispatcher functions
;; held in `jsonrpc--request-dispatcher' and
;; `jsonrpc--notification-dispatcher' to be called when appropriate,
-;; i.e. when noticing a new JSONRPC message on the wire. Optionally
+;; i.e. when noticing a new JSONRPC message on the wire. The function
+;; `jsonrpc-connection-receive' is a good way to do that. Optionally
;; it should implement `jsonrpc-shutdown' and `jsonrpc-running-p' if
;; these concepts apply to the transport.
;;
@@ -218,6 +219,50 @@ for sending requests immediately."
"Stop waiting for responses from the current JSONRPC CONNECTION."
(clrhash (jsonrpc--request-continuations connection)))
+(defun jsonrpc-connection-receive (connection message)
+ "Process MESSAGE just received from CONNECTION.
+This function will destructure MESSAGE and call the appropriate
+dispatcher in CONNECTION."
+ (cl-destructuring-bind (&key method id error params result _jsonrpc)
+ message
+ (let (continuations)
+ (jsonrpc--log-event connection message 'server)
+ (setf (jsonrpc-last-error connection) error)
+ (cond
+ (;; A remote request
+ (and method id)
+ (let* ((debug-on-error (and debug-on-error (not (ert-running-test))))
+ (reply
+ (condition-case-unless-debug _ignore
+ (condition-case oops
+ `(:result ,(funcall (jsonrpc--request-dispatcher
connection)
+ connection (intern method) params))
+ (jsonrpc-error
+ `(:error
+ (:code
+ ,(or (alist-get 'jsonrpc-error-code (cdr oops))
-32603)
+ :message ,(or (alist-get 'jsonrpc-error-message
+ (cdr oops))
+ "Internal error")))))
+ (error
+ `(:error (:code -32603 :message "Internal error"))))))
+ (apply #'jsonrpc--reply connection id reply)))
+ (;; A remote notification
+ method
+ (funcall (jsonrpc--notification-dispatcher connection)
+ connection (intern method) params))
+ (;; A remote response
+ (setq continuations
+ (and id (gethash id (jsonrpc--request-continuations
connection))))
+ (let ((timer (nth 2 continuations)))
+ (when timer (cancel-timer timer)))
+ (remhash id (jsonrpc--request-continuations connection))
+ (if error (funcall (nth 1 continuations) error)
+ (funcall (nth 0 continuations) result)))
+ (;; An abnormal situation
+ id (jsonrpc--warn "No continuation for id %s" id)))
+ (jsonrpc--call-deferred connection))))
+
;;; Contacting the remote endpoint
;;;
@@ -544,8 +589,8 @@ connection object, called when the process dies .")
;; buffer, shielding proc buffer from
;; tamper
(with-temp-buffer
- (jsonrpc--connection-receive connection
-
json-message)))))
+ (jsonrpc-connection-receive connection
+
json-message)))))
(goto-char message-end)
(delete-region (point-min) (point))
(setq expected-bytes nil))))
@@ -557,48 +602,6 @@ connection object, called when the process dies .")
;;
(setf (jsonrpc--expected-bytes connection) expected-bytes))))))
-(defun jsonrpc--connection-receive (connection message)
- "Connection MESSAGE from CONNECTION."
- (cl-destructuring-bind (&key method id error params result _jsonrpc)
- message
- (let (continuations)
- (jsonrpc--log-event connection message 'server)
- (setf (jsonrpc-last-error connection) error)
- (cond
- (;; A remote request
- (and method id)
- (let* ((debug-on-error (and debug-on-error (not (ert-running-test))))
- (reply
- (condition-case-unless-debug _ignore
- (condition-case oops
- `(:result ,(funcall (jsonrpc--request-dispatcher
connection)
- connection (intern method) params))
- (jsonrpc-error
- `(:error
- (:code
- ,(or (alist-get 'jsonrpc-error-code (cdr oops))
-32603)
- :message ,(or (alist-get 'jsonrpc-error-message
- (cdr oops))
- "Internal error")))))
- (error
- `(:error (:code -32603 :message "Internal error"))))))
- (apply #'jsonrpc--reply connection id reply)))
- (;; A remote notification
- method
- (funcall (jsonrpc--notification-dispatcher connection)
- connection (intern method) params))
- (;; A remote response
- (setq continuations
- (and id (gethash id (jsonrpc--request-continuations
connection))))
- (let ((timer (nth 2 continuations)))
- (when timer (cancel-timer timer)))
- (remhash id (jsonrpc--request-continuations connection))
- (if error (funcall (nth 1 continuations) error)
- (funcall (nth 0 continuations) result)))
- (;; An abnormal situation
- id (jsonrpc--warn "No continuation for id %s" id)))
- (jsonrpc--call-deferred connection))))
-
(cl-defun jsonrpc--async-request-1 (connection
method
params
- [elpa] externals/eglot f730fff 48/69: Merge branch 'master' into jsonrpc-refactor, (continued)
- [elpa] externals/eglot f730fff 48/69: Merge branch 'master' into jsonrpc-refactor, João Távora, 2018/06/22
- [elpa] externals/eglot aaca7de 60/69: Fix ridiculous bug, João Távora, 2018/06/22
- [elpa] externals/eglot d87f4bf 55/69: jsonrpc--log-event should also be private, João Távora, 2018/06/22
- [elpa] externals/eglot a65d3f4 53/69: Make message and warning helpers private, João Távora, 2018/06/22
- [elpa] externals/eglot 9e9dc57 30/69: Merge branch 'master' into jsonrpc-refactor (using regular merge), João Távora, 2018/06/22
- [elpa] externals/eglot 6c9d41e 38/69: Add reasonably sophisticated deferred action tests, João Távora, 2018/06/22
- [elpa] externals/eglot 2da7d92 50/69: Simplify JSONRPC status setting, João Távora, 2018/06/22
- [elpa] externals/eglot 69a622a 64/69: Fix some typos, João Távora, 2018/06/22
- [elpa] externals/eglot 7371f68 57/69: * jsonrpc.el: Rewrite commentary., João Távora, 2018/06/22
- [elpa] externals/eglot 6531c8b 58/69: Merge branch 'master' into jsonrpc-refactor, João Távora, 2018/06/22
- [elpa] externals/eglot 59cc3fb 61/69: jsonrpc-connection-receive is now a public convenience function,
João Távora <=
- [elpa] externals/eglot d371f05 49/69: Request dispatcher's return value determines response, João Távora, 2018/06/22
- [elpa] externals/eglot 0f20fdf 68/69: Tiny README.md change, João Távora, 2018/06/22
- [elpa] externals/eglot cef3c29 22/69: Heroically merge master into jsonrpc-refactor (using imerge), João Távora, 2018/06/22
- [elpa] externals/eglot a4441c6 37/69: Merge master into jsonrpc-refactor (using imerge), João Távora, 2018/06/22
- [elpa] externals/eglot 0e44b27 27/69: jsonrpc.el uses classes and generic functions, João Távora, 2018/06/22
- [elpa] externals/eglot 856a224 62/69: Simplify jsonrpc-connection-send, João Távora, 2018/06/22
- [elpa] externals/eglot 1f09fd3 59/69: Review commentary section before another review cycle, João Távora, 2018/06/22
- [elpa] externals/eglot 8fda30c 67/69: Merge master into jsonrpc-refactor (using imerge), João Távora, 2018/06/22
- [elpa] externals/eglot 7f4e273 31/69: Merge master into jsonrpc-refactor (using imerge), João Távora, 2018/06/22
- [elpa] externals/eglot 4525eca 43/69: Support json.c. API purely based on classes, João Távora, 2018/06/22