branch: externals/eglot commit c30f0f3262c5e6d70934c7c2a9e7d7c23e696360 Author: João Távora <joaotav...@gmail.com> Commit: João Távora <joaotav...@gmail.com>
Get rid of jsonrpc.el customization group and timeout * eglot.el (eglot-shutdown, eglot--signal-textDocument/willSave): Pass :timeout to jsonrpc-request. (defadvice jsonrpc-request): Add :timeout kwarg * jsonrpc.el (defgroup jsonrpc, jsonrpc-request-timeout): Remove. (jrpc-default-request-timeout): New constant. (jsonrpc-async-request): Use it. (jsonrpc-request): Accept timeout kwarg and pass it on. --- eglot.el | 17 ++++++++--------- jsonrpc.el | 20 +++++++------------- 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/eglot.el b/eglot.el index 41e57b4..020e352 100644 --- a/eglot.el +++ b/eglot.el @@ -148,9 +148,9 @@ called interactively." (interactive (list (jsonrpc-current-process-or-lose) t)) (eglot--message "Asking %s politely to terminate" proc) (unwind-protect - (let ((jsonrpc-request-timeout 3)) + (progn (setf (eglot--moribund proc) t) - (jsonrpc-request proc :shutdown nil) + (jsonrpc-request proc :shutdown nil :timeout 3) ;; this one should always fail, hence ignore-errors (ignore-errors (jsonrpc-request proc :exit nil))) ;; Turn off `eglot--managed-mode' where appropriate. @@ -749,7 +749,7 @@ Records START, END and PRE-CHANGE-LENGTH locally." ;; bad idea, since that might lead to the request never having a ;; chance to run, because `jsonrpc-ready-predicates'. (advice-add #'jsonrpc-request :before - (cl-function (lambda (_proc _method _params &key deferred) + (cl-function (lambda (_proc _method _params &key deferred _timeout) (when (and eglot--managed-mode deferred) (eglot--signal-textDocument/didChange)))) '((name . eglot--signal-textDocument/didChange))) @@ -805,12 +805,11 @@ Records START, END and PRE-CHANGE-LENGTH locally." (let ((proc (jsonrpc-current-process-or-lose)) (params `(:reason 1 :textDocument ,(eglot--TextDocumentIdentifier)))) (jsonrpc-notify proc :textDocument/willSave params) - (ignore-errors - (let ((jsonrpc-request-timeout 0.5)) - (when (plist-get :willSaveWaitUntil - (eglot--server-capable :textDocumentSync)) - (eglot--apply-text-edits - (jsonrpc-request proc :textDocument/willSaveWaituntil params))))))) + (when (eglot--server-capable :textDocumentSync :willSaveWaitUntil) + (ignore-errors + (eglot--apply-text-edits + (jsonrpc-request proc :textDocument/willSaveWaituntil params + :timeout 0.5)))))) (defun eglot--signal-textDocument/didSave () "Send textDocument/didSave to server." diff --git a/jsonrpc.el b/jsonrpc.el index d5f7745..cda035e 100644 --- a/jsonrpc.el +++ b/jsonrpc.el @@ -123,16 +123,6 @@ (require 'pcase) (require 'array) ; xor -(defgroup jsonrpc nil - "Interaction between JSONRPC endpoints" - :prefix "jsonrpc-" - :group 'applications) - -(defcustom jsonrpc-request-timeout 3 - "How many seconds to wait for a JSONRPC from the server. -If nil, don't use a timeout (not recommended)." - :type :integer) - (defvar jsonrpc-find-process-functions nil "Special hook to find an active JSON-RPC process.") @@ -505,12 +495,15 @@ request and a process object.") (let ((e (gensym "jsonrpc-lambda-elem"))) `(lambda (,e) (apply (cl-function (lambda ,cl-lambda-list ,@body)) ,e)))) +(defconst jrpc-default-request-timeout 10 + "Time in seconds before timing out a JSONRPC request.") + (cl-defun jsonrpc-async-request (proc method params &rest args &key success-fn error-fn timeout-fn - (timeout jsonrpc-request-timeout) + (timeout jrpc-default-request-timeout) (deferred nil)) "Make a request to PROC, expecting a reply, return immediately. The JSONRPC request is formed by METHOD, a symbol, and PARAMS a @@ -591,7 +584,7 @@ TIMEOUT is nil)" (jsonrpc--request-continuations proc)) (list id timer))) -(cl-defun jsonrpc-request (proc method params &key deferred) +(cl-defun jsonrpc-request (proc method params &key deferred timeout) "Make a request to PROC, wait for a reply. Like `jsonrpc-async-request' for PROC, METHOD and PARAMS, but synchronous, i.e. doesn't exit until anything @@ -618,7 +611,8 @@ DEFERRED is passed to `jsonrpc-async-request', which see." :timeout-fn (lambda () (throw tag '(error (jsonrpc-error-message . "Timed out")))) - :deferred deferred)) + :deferred deferred + :timeout timeout)) (while t (accept-process-output nil 30))) (pcase-let ((`(,id ,timer) id-and-timer)) (when id (remhash id (jsonrpc--request-continuations proc)))