Skip to content

Commit 573b112

Browse files
ak-corambbatsov
authored andcommitted
Infer REPL type in nrepl-send-*, add infer symbol as alias for nil
This fixes the inspector not using the appropriate REPL connection for the current buffer.
1 parent fa93545 commit 573b112

File tree

5 files changed

+34
-24
lines changed

5 files changed

+34
-24
lines changed

cider-client.el

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,10 @@ nREPL connection."
170170
(defun cider-nrepl-op-supported-p (op &optional connection skip-ensure)
171171
"Check whether the CONNECTION supports the nREPL middleware OP.
172172
Skip check if repl is active if SKIP-ENSURE is non nil."
173-
(nrepl-op-supported-p op (or connection (cider-current-repl nil (if skip-ensure
174-
nil
175-
'ensure)))))
173+
(nrepl-op-supported-p op (or connection
174+
(cider-current-repl 'infer (if skip-ensure
175+
nil
176+
'ensure)))))
176177

177178
(defun cider-ensure-op-supported (op)
178179
"Check for support of middleware op OP.
@@ -187,7 +188,9 @@ REQUEST is a pair list of the form (\"op\" \"operation\" \"par1-name\"
187188
If CONNECTION is provided dispatch to that connection instead of
188189
the current connection. Return the id of the sent message.
189190
If TOOLING is truthy then the tooling session is used."
190-
(nrepl-send-request request callback (or connection (cider-current-repl 'any 'ensure)) tooling))
191+
(nrepl-send-request request callback (or connection
192+
(cider-current-repl 'infer 'ensure))
193+
tooling))
191194

192195
(defun cider-nrepl-send-sync-request (request &optional connection
193196
abort-on-input callback)
@@ -199,15 +202,15 @@ at the first sign of user input, so as not to hang the
199202
interface.
200203
if CALLBACK is non-nil, it will additionally be called on all received messages."
201204
(nrepl-send-sync-request request
202-
(or connection (cider-current-repl 'any 'ensure))
205+
(or connection (cider-current-repl 'infer 'ensure))
203206
abort-on-input
204207
nil
205208
callback))
206209

207210
(defun cider-nrepl-send-unhandled-request (request &optional connection)
208211
"Send REQUEST to the nREPL CONNECTION and ignore any responses.
209212
Immediately mark the REQUEST as done. Return the id of the sent message."
210-
(let* ((conn (or connection (cider-current-repl 'any 'ensure)))
213+
(let* ((conn (or connection (cider-current-repl 'infer 'ensure)))
211214
(id (nrepl-send-request request #'ignore conn)))
212215
(with-current-buffer conn
213216
(nrepl--mark-id-completed id))
@@ -219,7 +222,7 @@ If NS is non-nil, include it in the request. LINE and COLUMN, if non-nil,
219222
define the position of INPUT in its buffer. ADDITIONAL-PARAMS is a plist
220223
to be appended to the request message. CONNECTION is the connection
221224
buffer, defaults to (cider-current-repl)."
222-
(let ((connection (or connection (cider-current-repl nil 'ensure)))
225+
(let ((connection (or connection (cider-current-repl 'infer 'ensure)))
223226
(eval-buffer (current-buffer)))
224227
(run-hooks 'cider-before-eval-hook)
225228
(nrepl-request:eval input
@@ -238,7 +241,10 @@ buffer, defaults to (cider-current-repl)."
238241
(defun cider-nrepl-sync-request:eval (input &optional connection ns)
239242
"Send the INPUT to the nREPL CONNECTION synchronously.
240243
If NS is non-nil, include it in the eval request."
241-
(nrepl-sync-request:eval input (or connection (cider-current-repl nil 'ensure)) ns))
244+
(nrepl-sync-request:eval input
245+
(or connection
246+
(cider-current-repl 'infer 'ensure))
247+
ns))
242248

243249
(defcustom cider-format-code-options nil
244250
"A map of options that will be passed to `cljfmt' to format code.
@@ -426,7 +432,7 @@ clobber *1/2/3)."
426432
;; namespace forms are always evaluated in the "user" namespace
427433
(nrepl-request:eval input
428434
callback
429-
(or connection (cider-current-repl nil 'ensure))
435+
(or connection (cider-current-repl 'infer 'ensure))
430436
ns nil nil nil 'tooling))
431437

432438
(defun cider-sync-tooling-eval (input &optional ns connection)
@@ -437,7 +443,7 @@ bindings of the primary eval nREPL session (e.g. this is not going to
437443
clobber *1/2/3)."
438444
;; namespace forms are always evaluated in the "user" namespace
439445
(nrepl-sync-request:eval input
440-
(or connection (cider-current-repl nil 'ensure))
446+
(or connection (cider-current-repl 'infer 'ensure))
441447
ns
442448
'tooling))
443449

@@ -458,7 +464,7 @@ itself is present."
458464
"Interrupt any pending evaluations."
459465
(interactive)
460466
;; FIXME: does this work correctly in cljc files?
461-
(with-current-buffer (cider-current-repl nil 'ensure)
467+
(with-current-buffer (cider-current-repl 'infer 'ensure)
462468
(let ((pending-request-ids (cider-util--hash-keys nrepl-pending-requests)))
463469
(dolist (request-id pending-request-ids)
464470
(nrepl-request:interrupt

cider-connection.el

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ REPL defaults to the current REPL."
530530
(interactive)
531531
(let ((repl (or repl
532532
(sesman-browser-get 'object)
533-
(cider-current-repl nil 'ensure))))
533+
(cider-current-repl 'infer 'ensure))))
534534
(cider--close-connection repl))
535535
;; if there are no more sessions we can kill all ancillary buffers
536536
(unless (cider-sessions)
@@ -546,7 +546,7 @@ entire session."
546546
(interactive)
547547
(let* ((repl (or repl
548548
(sesman-browser-get 'object)
549-
(cider-current-repl nil 'ensure)))
549+
(cider-current-repl 'infer 'ensure)))
550550
(params (thread-first ()
551551
(cider--gather-connect-params repl)
552552
(plist-put :session-name (sesman-session-name-for-object 'CIDER repl))
@@ -569,7 +569,7 @@ REPL defaults to the current REPL."
569569
(interactive)
570570
(let ((repl (or repl
571571
(sesman-browser-get 'object)
572-
(cider-current-repl nil 'ensure))))
572+
(cider-current-repl 'infer 'ensure))))
573573
(message "%s" (cider--connection-info repl))))
574574

575575
(defconst cider-nrepl-session-buffer "*cider-nrepl-session*")
@@ -580,7 +580,7 @@ REPL defaults to the current REPL."
580580
"Describe an nREPL session."
581581
(interactive)
582582
(cider-ensure-connected)
583-
(let* ((repl (cider-current-repl nil 'ensure))
583+
(let* ((repl (cider-current-repl 'infer 'ensure))
584584
(selected-session (completing-read "Describe nREPL session: " (nrepl-sessions repl))))
585585
(when (and selected-session (not (equal selected-session "")))
586586
(let* ((session-info (nrepl-sync-request:describe repl))
@@ -602,7 +602,7 @@ REPL defaults to the current REPL."
602602
"List the loaded nREPL middleware."
603603
(interactive)
604604
(cider-ensure-connected)
605-
(let* ((repl (cider-current-repl nil 'ensure))
605+
(let* ((repl (cider-current-repl 'infer 'ensure))
606606
(middleware (nrepl-middleware repl)))
607607
(with-current-buffer (cider-popup-buffer "*cider-nrepl-middleware*" 'select nil 'ancillary)
608608
(read-only-mode -1)
@@ -946,19 +946,23 @@ REPL (connection) which produced them.")
946946

947947
(defun cider-current-repl (&optional type ensure)
948948
"Get the most recent REPL of TYPE from the current session.
949-
TYPE is either clj, cljs, multi or any.
950-
When nil, infer the type from the current buffer.
949+
TYPE is either clj, cljs, multi, infer or any.
950+
When infer or nil, infer the type from the current buffer.
951951
If ENSURE is non-nil, throw an error if either there is
952952
no linked session or there is no REPL of TYPE within the current session."
953953
(let ((type (cider-maybe-intern type)))
954954
(if (and (derived-mode-p 'cider-repl-mode)
955955
(or (null type)
956956
(eq 'any type)
957+
(eq 'infer type)
957958
(eq cider-repl-type type)))
958959
;; shortcut when in REPL buffer
959960
(current-buffer)
960961
(or cider--ancillary-buffer-repl
961-
(let* ((type (or type (cider-repl-type-for-buffer)))
962+
(let* ((type (if (or (null type)
963+
(eq 'infer type))
964+
(cider-repl-type-for-buffer)
965+
type))
962966
(repls (cider-repls type ensure))
963967
(repl (if (<= (length repls) 1)
964968
(car repls)

cider-log.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1422,7 +1422,7 @@ Honors the `cider-log-framework-name' customization variable.
14221422
This function is offered as an alternative to workflows
14231423
based on `transient-mode'."
14241424
(interactive)
1425-
(cider-current-repl nil 'ensure)
1425+
(cider-current-repl 'infer 'ensure)
14261426
(let ((framework (cider-log--framework))
14271427
(appender (cider-log--appender))
14281428
(new-default-directory (buffer-local-value 'default-directory (current-buffer))))

cider-mode.el

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ prefix arg SET-NAMESPACE sets the namespace in the REPL buffer to that of
108108
the namespace in the Clojure source buffer"
109109
(interactive "P")
110110
(cider--switch-to-repl-buffer
111-
(cider-current-repl nil 'ensure)
111+
(cider-current-repl 'infer 'ensure)
112112
set-namespace))
113113

114114
(declare-function cider-load-buffer "cider-eval")
@@ -154,7 +154,7 @@ the related commands `cider-repl-clear-buffer' and
154154
`cider-repl-clear-output'."
155155
(interactive "P")
156156
(let ((origin-buffer (current-buffer)))
157-
(switch-to-buffer (cider-current-repl nil 'ensure))
157+
(switch-to-buffer (cider-current-repl 'infer 'ensure))
158158
(if clear-repl
159159
(cider-repl-clear-buffer)
160160
(cider-repl-clear-output))

cider-repl.el

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ This cache is stored in the connection buffer.")
257257
(defun cider-repl-require-repl-utils ()
258258
"Require standard REPL util functions into the current REPL."
259259
(interactive)
260-
(let* ((current-repl (cider-current-repl nil 'ensure))
260+
(let* ((current-repl (cider-current-repl 'infer 'ensure))
261261
(require-code (cdr (assoc (cider-repl-type current-repl) cider-repl-require-repl-utils-code))))
262262
(nrepl-send-sync-request
263263
(cider-plist-put
@@ -1202,7 +1202,7 @@ Closes all open parentheses or bracketed expressions."
12021202
"Switch between the Clojure and ClojureScript REPLs for the current project."
12031203
(interactive)
12041204
;; FIXME: implement cycling as session can hold more than two REPLs
1205-
(let* ((this-repl (cider-current-repl nil 'ensure))
1205+
(let* ((this-repl (cider-current-repl 'infer 'ensure))
12061206
(other-repl (car (seq-remove (lambda (r) (eq r this-repl)) (cider-repls nil t)))))
12071207
(if other-repl
12081208
(switch-to-buffer other-repl)

0 commit comments

Comments
 (0)