mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-05 22:20:24 -08:00
Jsonrpc: support requests and notifications without params (bug#79653)
See also bug#66144. Github-reference: https://github.com/joaotavora/eglot/discussions/1540 * lisp/jsonrpc.el (jsonrpc-async-request): Fix docstring. (jsonrpc--async-request-1): Handle :jsonrpc-omit (jsonrpc-notify): Handle jsonrpc-omit. (jsonrpc-request): Tweak doc. (Version): Bump to 1.0.26.
This commit is contained in:
parent
ac78b945d5
commit
74618070ab
1 changed files with 24 additions and 19 deletions
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
;; Author: João Távora <joaotavora@gmail.com>
|
;; Author: João Távora <joaotavora@gmail.com>
|
||||||
;; Keywords: processes, languages, extensions
|
;; Keywords: processes, languages, extensions
|
||||||
;; Version: 1.0.25
|
;; Version: 1.0.26
|
||||||
;; Package-Requires: ((emacs "25.2"))
|
;; Package-Requires: ((emacs "25.2"))
|
||||||
|
|
||||||
;; This is a GNU ELPA :core package. Avoid functionality that is not
|
;; This is a GNU ELPA :core package. Avoid functionality that is not
|
||||||
|
|
@ -360,8 +360,8 @@ object, using the keywords `:code', `:message' and `:data'."
|
||||||
_timeout-fn
|
_timeout-fn
|
||||||
_timeout _deferred)
|
_timeout _deferred)
|
||||||
"Make a request to CONNECTION, expecting a reply, return immediately.
|
"Make a request to CONNECTION, expecting a reply, return immediately.
|
||||||
The JSONRPC request is formed by METHOD, a symbol, and PARAMS a
|
The JSONRPC request is formed by METHOD, a symbol; and PARAMS, a JSON
|
||||||
JSON object.
|
object value as described in `json-serialize' (which see).
|
||||||
|
|
||||||
The caller can expect SUCCESS-FN or ERROR-FN to be called with a
|
The caller can expect SUCCESS-FN or ERROR-FN to be called with a
|
||||||
JSONRPC `:result' or `:error' object, respectively. If this
|
JSONRPC `:result' or `:error' object, respectively. If this
|
||||||
|
|
@ -378,6 +378,9 @@ never be sent at all, in case it is overridden in the meantime by
|
||||||
a new request with identical DEFERRED and for the same buffer.
|
a new request with identical DEFERRED and for the same buffer.
|
||||||
However, in that situation, the original timeout is kept.
|
However, in that situation, the original timeout is kept.
|
||||||
|
|
||||||
|
PARAMS can also be the keyword `:jsonrpc-omit', in which case the
|
||||||
|
JSONRPC request object is formed witout a `params' entry.
|
||||||
|
|
||||||
Returns a list whose first element is an integer identifying the request
|
Returns a list whose first element is an integer identifying the request
|
||||||
as specified in the JSONRPC 2.0 spec."
|
as specified in the JSONRPC 2.0 spec."
|
||||||
(apply #'jsonrpc--async-request-1 connection method params args))
|
(apply #'jsonrpc--async-request-1 connection method params args))
|
||||||
|
|
@ -387,9 +390,8 @@ as specified in the JSONRPC 2.0 spec."
|
||||||
deferred timeout
|
deferred timeout
|
||||||
cancel-on-input
|
cancel-on-input
|
||||||
cancel-on-input-retval)
|
cancel-on-input-retval)
|
||||||
"Make a request to CONNECTION, wait for a reply.
|
"Make a request to CONNECTION, synchronously wait for a reply.
|
||||||
Like `jsonrpc-async-request' for CONNECTION, METHOD and PARAMS,
|
CONNECTION, METHOD and PARAMS as in `jsonrpc-async-request' (which see).
|
||||||
but synchronous.
|
|
||||||
|
|
||||||
Except in the case of a non-nil CANCEL-ON-INPUT (explained
|
Except in the case of a non-nil CANCEL-ON-INPUT (explained
|
||||||
below), this function doesn't exit until anything interesting
|
below), this function doesn't exit until anything interesting
|
||||||
|
|
@ -401,11 +403,13 @@ error of type `jsonrpc-error'.
|
||||||
DEFERRED and TIMEOUT as in `jsonrpc-async-request', which see.
|
DEFERRED and TIMEOUT as in `jsonrpc-async-request', which see.
|
||||||
|
|
||||||
If CANCEL-ON-INPUT is non-nil and the user inputs something while the
|
If CANCEL-ON-INPUT is non-nil and the user inputs something while the
|
||||||
function is waiting, then any future replies to the request by the
|
function is waiting, the function locally exits immediately returning
|
||||||
remote endpoint (normal or error) are ignored and the function exits
|
CANCEL-ON-INPUT-RETVAL. Any future replies to the request coming from
|
||||||
returning CANCEL-ON-INPUT-RETVAL. If CANCEL-ON-INPUT is a function, it
|
the remote endpoint (normal or error) are ignored. If CANCEL-ON-INPUT
|
||||||
is invoked with one argument, an integer identifying the canceled
|
is a function, it is invoked with one argument, an integer identifying
|
||||||
request as specified in the JSONRPC 2.0 spec."
|
the canceled request as specified in the JSONRPC 2.0 spec. Callers may
|
||||||
|
use this function to issue a cancel notification to the endpoint, thus
|
||||||
|
preventing it from continuing to work on the now-cancelled request."
|
||||||
(let* ((tag (funcall (if (fboundp 'gensym) 'gensym 'cl-gensym)
|
(let* ((tag (funcall (if (fboundp 'gensym) 'gensym 'cl-gensym)
|
||||||
"jsonrpc-request-catch-tag"))
|
"jsonrpc-request-catch-tag"))
|
||||||
id-and-timer
|
id-and-timer
|
||||||
|
|
@ -465,10 +469,11 @@ request as specified in the JSONRPC 2.0 spec."
|
||||||
(cadr retval)))
|
(cadr retval)))
|
||||||
|
|
||||||
(cl-defun jsonrpc-notify (connection method params)
|
(cl-defun jsonrpc-notify (connection method params)
|
||||||
"Notify CONNECTION of something, don't expect a reply."
|
"Notify CONNECTION of something, don't expect a reply.
|
||||||
(jsonrpc-connection-send connection
|
CONNECTION, METHOD and PARAMS as in `jsonrpc-async-request' (which see)."
|
||||||
:method method
|
(apply #'jsonrpc-connection-send connection
|
||||||
:params params))
|
:method method
|
||||||
|
(unless (eq params :jsonrpc-omit) `(:params ,params))))
|
||||||
|
|
||||||
(define-obsolete-variable-alias 'jrpc-default-request-timeout
|
(define-obsolete-variable-alias 'jrpc-default-request-timeout
|
||||||
'jsonrpc-default-request-timeout "28.1")
|
'jsonrpc-default-request-timeout "28.1")
|
||||||
|
|
@ -933,10 +938,10 @@ TIMEOUT is nil)."
|
||||||
(cl-return-from jsonrpc--async-request-1 (list id timer))))
|
(cl-return-from jsonrpc--async-request-1 (list id timer))))
|
||||||
;; Really send it thru the wire
|
;; Really send it thru the wire
|
||||||
;;
|
;;
|
||||||
(jsonrpc-connection-send connection
|
(apply #'jsonrpc-connection-send connection
|
||||||
:id id
|
:id id
|
||||||
:method method
|
:method method
|
||||||
:params params)
|
(unless (eq params :jsonrpc-omit) `(:params ,params)))
|
||||||
;; Setup some control structures
|
;; Setup some control structures
|
||||||
;;
|
;;
|
||||||
(when sync-request
|
(when sync-request
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue