Skip to content

Commit eef3069

Browse files
committed
nrepl-client.el (nrepl-send-sync-request): New optional argument
If provided, abort the loop immediately and return nil. This avoids hanging the interface on background requests.
1 parent c85d5ae commit eef3069

File tree

2 files changed

+33
-27
lines changed

2 files changed

+33
-27
lines changed

cider-client.el

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,13 @@ loaded. If CALLBACK is nil, use `cider-load-file-handler'."
179179

180180
(defun cider-sync-request:complete (str context)
181181
"Return a list of completions for STR using nREPL's \"complete\" op."
182-
(-> (list "op" "complete"
183-
"session" (nrepl-current-session)
184-
"ns" (cider-current-ns)
185-
"symbol" str
186-
"context" context)
187-
(nrepl-send-sync-request)
188-
(nrepl-dict-get "completions")))
182+
(-when-let (dict (-> (list "op" "complete"
183+
"session" (nrepl-current-session)
184+
"ns" (cider-current-ns)
185+
"symbol" str
186+
"context" context)
187+
(nrepl-send-sync-request 'abort-on-input)))
188+
(nrepl-dict-get dict "completions")))
189189

190190
(defun cider-sync-request:info (symbol &optional class member)
191191
"Send \"info\" op with parameters SYMBOL or CLASS and MEMBER."
@@ -202,13 +202,13 @@ loaded. If CALLBACK is nil, use `cider-load-file-handler'."
202202

203203
(defun cider-sync-request:eldoc (symbol &optional class member)
204204
"Send \"eldoc\" op with parameters SYMBOL or CLASS and MEMBER."
205-
(let ((eldoc (-> `("op" "eldoc"
206-
"session" ,(nrepl-current-session)
207-
"ns" ,(cider-current-ns)
208-
,@(when symbol (list "symbol" symbol))
209-
,@(when class (list "class" class))
210-
,@(when member (list "member" member)))
211-
(nrepl-send-sync-request))))
205+
(-when-let (eldoc (-> `("op" "eldoc"
206+
"session" ,(nrepl-current-session)
207+
"ns" ,(cider-current-ns)
208+
,@(when symbol (list "symbol" symbol))
209+
,@(when class (list "class" class))
210+
,@(when member (list "member" member)))
211+
(nrepl-send-sync-request 'abort-on-input)))
212212
(if (member "no-eldoc" (nrepl-dict-get eldoc "status"))
213213
nil
214214
eldoc)))

nrepl-client.el

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -922,15 +922,19 @@ REQUEST is a pair list of the form (\"op\" \"operation\" \"par1-name\"
922922
(puthash id callback nrepl-pending-requests)
923923
(process-send-string nil message))))
924924

925-
(defun nrepl-send-sync-request (request)
925+
(defun nrepl-send-sync-request (request &optional abort-on-input)
926926
"Send REQUEST to the nREPL server synchronously.
927927
Hold till final \"done\" message has arrived and join all response messages
928-
of the same \"op\" that came along."
928+
of the same \"op\" that came along.
929+
If ABORT-ON-INPUT is non-nil, the function will return nil at the first
930+
sign of user input, so as not to hang the interface."
929931
(let* ((time0 (current-time))
930932
(response (cons 'dict nil))
931933
status)
932934
(nrepl-send-request request (lambda (resp) (nrepl--merge response resp)))
933-
(while (not (member "done" status))
935+
(while (and (not (member "done" status))
936+
(not (and abort-on-input
937+
(input-pending-p))))
934938
(setq status (nrepl-dict-get response "status"))
935939
;; If we get a need-input message then the repl probably isn't going
936940
;; anywhere, and we'll just timeout. So we forward it to the user.
@@ -947,16 +951,18 @@ of the same \"op\" that came along."
947951
;; Clean up the response, otherwise we might repeatedly ask for input.
948952
(nrepl-dict-put response "status" nil)
949953
(accept-process-output nil 0.01))
950-
(-when-let* ((ex (nrepl-dict-get response "ex"))
951-
(err (nrepl-dict-get response "err")))
952-
(cider-repl-emit-interactive-err-output err)
953-
(message err))
954-
(-when-let (id (nrepl-dict-get response "id"))
955-
;; FIXME: This should go away eventually when we get rid of
956-
;; pending-request hash table
957-
(with-current-buffer (nrepl-current-connection-buffer)
958-
(remhash id nrepl-pending-requests)))
959-
response))
954+
;; If we couldn't finish, return nil.
955+
(when (member "done" status)
956+
(-when-let* ((ex (nrepl-dict-get response "ex"))
957+
(err (nrepl-dict-get response "err")))
958+
(cider-repl-emit-interactive-err-output err)
959+
(message err))
960+
(-when-let (id (nrepl-dict-get response "id"))
961+
;; FIXME: This should go away eventually when we get rid of
962+
;; pending-request hash table
963+
(with-current-buffer (nrepl-current-connection-buffer)
964+
(remhash id nrepl-pending-requests)))
965+
response)))
960966

961967
(defun nrepl-request:stdin (input callback)
962968
"Send a :stdin request with INPUT.

0 commit comments

Comments
 (0)