Skip to content

Fix inspector not using the appropriate REPL connection #3830

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions cider-client.el
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,10 @@ nREPL connection."
(defun cider-nrepl-op-supported-p (op &optional connection skip-ensure)
"Check whether the CONNECTION supports the nREPL middleware OP.
Skip check if repl is active if SKIP-ENSURE is non nil."
(nrepl-op-supported-p op (or connection (cider-current-repl nil (if skip-ensure
nil
'ensure)))))
(nrepl-op-supported-p op (or connection
(cider-current-repl 'infer (if skip-ensure
nil
'ensure)))))

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

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

(defun cider-nrepl-send-unhandled-request (request &optional connection)
"Send REQUEST to the nREPL CONNECTION and ignore any responses.
Immediately mark the REQUEST as done. Return the id of the sent message."
(let* ((conn (or connection (cider-current-repl 'any 'ensure)))
(let* ((conn (or connection (cider-current-repl 'infer 'ensure)))
(id (nrepl-send-request request #'ignore conn)))
(with-current-buffer conn
(nrepl--mark-id-completed id))
Expand All @@ -219,7 +222,7 @@ If NS is non-nil, include it in the request. LINE and COLUMN, if non-nil,
define the position of INPUT in its buffer. ADDITIONAL-PARAMS is a plist
to be appended to the request message. CONNECTION is the connection
buffer, defaults to (cider-current-repl)."
(let ((connection (or connection (cider-current-repl nil 'ensure)))
(let ((connection (or connection (cider-current-repl 'infer 'ensure)))
(eval-buffer (current-buffer)))
(run-hooks 'cider-before-eval-hook)
(nrepl-request:eval input
Expand All @@ -238,7 +241,10 @@ buffer, defaults to (cider-current-repl)."
(defun cider-nrepl-sync-request:eval (input &optional connection ns)
"Send the INPUT to the nREPL CONNECTION synchronously.
If NS is non-nil, include it in the eval request."
(nrepl-sync-request:eval input (or connection (cider-current-repl nil 'ensure)) ns))
(nrepl-sync-request:eval input
(or connection
(cider-current-repl 'infer 'ensure))
ns))

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

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

Expand All @@ -458,7 +464,7 @@ itself is present."
"Interrupt any pending evaluations."
(interactive)
;; FIXME: does this work correctly in cljc files?
(with-current-buffer (cider-current-repl nil 'ensure)
(with-current-buffer (cider-current-repl 'infer 'ensure)
(let ((pending-request-ids (cider-util--hash-keys nrepl-pending-requests)))
(dolist (request-id pending-request-ids)
(nrepl-request:interrupt
Expand Down
20 changes: 12 additions & 8 deletions cider-connection.el
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ REPL defaults to the current REPL."
(interactive)
(let ((repl (or repl
(sesman-browser-get 'object)
(cider-current-repl nil 'ensure))))
(cider-current-repl 'infer 'ensure))))
(cider--close-connection repl))
;; if there are no more sessions we can kill all ancillary buffers
(unless (cider-sessions)
Expand All @@ -546,7 +546,7 @@ entire session."
(interactive)
(let* ((repl (or repl
(sesman-browser-get 'object)
(cider-current-repl nil 'ensure)))
(cider-current-repl 'infer 'ensure)))
(params (thread-first ()
(cider--gather-connect-params repl)
(plist-put :session-name (sesman-session-name-for-object 'CIDER repl))
Expand All @@ -569,7 +569,7 @@ REPL defaults to the current REPL."
(interactive)
(let ((repl (or repl
(sesman-browser-get 'object)
(cider-current-repl nil 'ensure))))
(cider-current-repl 'infer 'ensure))))
(message "%s" (cider--connection-info repl))))

(defconst cider-nrepl-session-buffer "*cider-nrepl-session*")
Expand All @@ -580,7 +580,7 @@ REPL defaults to the current REPL."
"Describe an nREPL session."
(interactive)
(cider-ensure-connected)
(let* ((repl (cider-current-repl nil 'ensure))
(let* ((repl (cider-current-repl 'infer 'ensure))
(selected-session (completing-read "Describe nREPL session: " (nrepl-sessions repl))))
(when (and selected-session (not (equal selected-session "")))
(let* ((session-info (nrepl-sync-request:describe repl))
Expand All @@ -602,7 +602,7 @@ REPL defaults to the current REPL."
"List the loaded nREPL middleware."
(interactive)
(cider-ensure-connected)
(let* ((repl (cider-current-repl nil 'ensure))
(let* ((repl (cider-current-repl 'infer 'ensure))
(middleware (nrepl-middleware repl)))
(with-current-buffer (cider-popup-buffer "*cider-nrepl-middleware*" 'select nil 'ancillary)
(read-only-mode -1)
Expand Down Expand Up @@ -946,19 +946,23 @@ REPL (connection) which produced them.")

(defun cider-current-repl (&optional type ensure)
"Get the most recent REPL of TYPE from the current session.
TYPE is either clj, cljs, multi or any.
When nil, infer the type from the current buffer.
TYPE is either clj, cljs, multi, infer or any.
When infer or nil, infer the type from the current buffer.
If ENSURE is non-nil, throw an error if either there is
no linked session or there is no REPL of TYPE within the current session."
(let ((type (cider-maybe-intern type)))
(if (and (derived-mode-p 'cider-repl-mode)
(or (null type)
(eq 'any type)
(eq 'infer type)
(eq cider-repl-type type)))
;; shortcut when in REPL buffer
(current-buffer)
(or cider--ancillary-buffer-repl
(let* ((type (or type (cider-repl-type-for-buffer)))
(let* ((type (if (or (null type)
(eq 'infer type))
(cider-repl-type-for-buffer)
type))
(repls (cider-repls type ensure))
(repl (if (<= (length repls) 1)
(car repls)
Expand Down
2 changes: 1 addition & 1 deletion cider-log.el
Original file line number Diff line number Diff line change
Expand Up @@ -1422,7 +1422,7 @@ Honors the `cider-log-framework-name' customization variable.
This function is offered as an alternative to workflows
based on `transient-mode'."
(interactive)
(cider-current-repl nil 'ensure)
(cider-current-repl 'infer 'ensure)
(let ((framework (cider-log--framework))
(appender (cider-log--appender))
(new-default-directory (buffer-local-value 'default-directory (current-buffer))))
Expand Down
4 changes: 2 additions & 2 deletions cider-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ prefix arg SET-NAMESPACE sets the namespace in the REPL buffer to that of
the namespace in the Clojure source buffer"
(interactive "P")
(cider--switch-to-repl-buffer
(cider-current-repl nil 'ensure)
(cider-current-repl 'infer 'ensure)
set-namespace))

(declare-function cider-load-buffer "cider-eval")
Expand Down Expand Up @@ -154,7 +154,7 @@ the related commands `cider-repl-clear-buffer' and
`cider-repl-clear-output'."
(interactive "P")
(let ((origin-buffer (current-buffer)))
(switch-to-buffer (cider-current-repl nil 'ensure))
(switch-to-buffer (cider-current-repl 'infer 'ensure))
(if clear-repl
(cider-repl-clear-buffer)
(cider-repl-clear-output))
Expand Down
4 changes: 2 additions & 2 deletions cider-repl.el
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ This cache is stored in the connection buffer.")
(defun cider-repl-require-repl-utils ()
"Require standard REPL util functions into the current REPL."
(interactive)
(let* ((current-repl (cider-current-repl nil 'ensure))
(let* ((current-repl (cider-current-repl 'infer 'ensure))
(require-code (cdr (assoc (cider-repl-type current-repl) cider-repl-require-repl-utils-code))))
(nrepl-send-sync-request
(cider-plist-put
Expand Down Expand Up @@ -1202,7 +1202,7 @@ Closes all open parentheses or bracketed expressions."
"Switch between the Clojure and ClojureScript REPLs for the current project."
(interactive)
;; FIXME: implement cycling as session can hold more than two REPLs
(let* ((this-repl (cider-current-repl nil 'ensure))
(let* ((this-repl (cider-current-repl 'infer 'ensure))
(other-repl (car (seq-remove (lambda (r) (eq r this-repl)) (cider-repls nil t)))))
(if other-repl
(switch-to-buffer other-repl)
Expand Down
Loading