branch: elpa/cider
commit 573b11209140e8cd87507abdaf2bedf2648fcb4a
Author: Ákos Kiss <a...@coram.pub>
Commit: Bozhidar Batsov <bozhi...@batsov.dev>

    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.
---
 cider-client.el     | 28 +++++++++++++++++-----------
 cider-connection.el | 20 ++++++++++++--------
 cider-log.el        |  2 +-
 cider-mode.el       |  4 ++--
 cider-repl.el       |  4 ++--
 5 files changed, 34 insertions(+), 24 deletions(-)

diff --git a/cider-client.el b/cider-client.el
index 31bd82602b..97bd02a4d3 100644
--- a/cider-client.el
+++ b/cider-client.el
@@ -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.
@@ -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)
@@ -199,7 +202,7 @@ 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))
@@ -207,7 +210,7 @@ if CALLBACK is non-nil, it will additionally be called on 
all received messages.
 (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))
@@ -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
@@ -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.
@@ -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)
@@ -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))
 
@@ -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
diff --git a/cider-connection.el b/cider-connection.el
index d223166ca7..f4181330e9 100644
--- a/cider-connection.el
+++ b/cider-connection.el
@@ -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)
@@ -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))
@@ -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*")
@@ -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))
@@ -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)
@@ -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)
diff --git a/cider-log.el b/cider-log.el
index af57952cb2..7ba71a0d2a 100644
--- a/cider-log.el
+++ b/cider-log.el
@@ -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))))
diff --git a/cider-mode.el b/cider-mode.el
index 7a7d642adb..bde58315bc 100644
--- a/cider-mode.el
+++ b/cider-mode.el
@@ -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")
@@ -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))
diff --git a/cider-repl.el b/cider-repl.el
index 12681f34c0..ce32f4a43b 100644
--- a/cider-repl.el
+++ b/cider-repl.el
@@ -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
@@ -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)

Reply via email to