Skip to content
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

- Bump the injected `nrepl` to [1.4.0](https://github.com/nrepl/nrepl/blob/master/CHANGELOG.md#140-2025-09-02).
- Bump the injected `piggieback` to [0.6.1](https://github.com/nrepl/piggieback/blob/master/CHANGES.md#061-2025-12-31).
- [#3834](https://github.com/clojure-emacs/cider/issues/3834): Change cider-ns-refresh to always use Clojure REPL

### Bugs fixed

Expand Down
22 changes: 11 additions & 11 deletions cider-client.el
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,10 @@ Skip check if repl is active if SKIP-ENSURE is non nil."
nil
'ensure)))))

(defun cider-ensure-op-supported (op)
"Check for support of middleware op OP.
(defun cider-ensure-op-supported (op &optional connection)
"Check for support of middleware op OP for CONNECTION.
Signal an error if it is not supported."
(unless (cider-nrepl-op-supported-p op)
(unless (cider-nrepl-op-supported-p op connection)
(user-error "`%s' requires the nREPL op \"%s\" (provided by cider-nrepl)" this-command op)))

(defun cider-nrepl-send-request (request callback &optional connection tooling)
Expand Down Expand Up @@ -623,12 +623,12 @@ Optional arguments include SEARCH-NS, DOCS-P, PRIVATES-P, CASE-SENSITIVE-P."
(user-error "Invalid regexp: %s" (nrepl-dict-get response "error-msg"))
(nrepl-dict-get response "apropos-matches"))))

(defun cider-sync-request:classpath ()
"Return a list of classpath entries."
(cider-ensure-op-supported "classpath")
(defun cider-sync-request:classpath (&optional connection)
"Return a list of classpath entries for CONNECTION."
(cider-ensure-op-supported "classpath" connection)
(thread-first
'("op" "classpath")
(cider-nrepl-send-sync-request)
(cider-nrepl-send-sync-request connection)
(nrepl-dict-get "classpath")))

(defun cider--get-abs-path (path project)
Expand All @@ -652,11 +652,11 @@ resolve those to absolute paths."
(project (clojure-project-dir)))
(mapcar (lambda (path) (cider--get-abs-path path project)) classpath))))

(defun cider-classpath-entries ()
"Return a list of classpath entries."
(defun cider-classpath-entries (&optional connection)
"Return a list of classpath entries for CONNECTION."
(seq-map #'expand-file-name ; normalize filenames for e.g. Windows
(if (cider-nrepl-op-supported-p "classpath")
(cider-sync-request:classpath)
(if (cider-nrepl-op-supported-p "classpath" connection)
(cider-sync-request:classpath connection)
(cider-fallback-eval:classpath))))

(defun cider-sync-request:completion (prefix)
Expand Down
25 changes: 18 additions & 7 deletions cider-connection.el
Original file line number Diff line number Diff line change
Expand Up @@ -1053,8 +1053,9 @@ throw an error if no linked session exists."
(defun cider-map-repls (which function)
"Call FUNCTION once for each appropriate REPL as indicated by WHICH.
The function is called with one argument, the REPL buffer. The appropriate
connections are found by inspecting the current buffer. WHICH is one of
the following keywords:
connections are found by inspecting the current buffer. WHICH is either one of
the following keywords or a list starting with one of them followed by names of
operations that the REPL is expected to support:
:auto - Act on the connections whose type matches the current buffer. In
`cljc' files, mapping happens over both types of REPLs.
:clj (:cljs) - Map over clj (cljs)) REPLs only.
Expand All @@ -1064,23 +1065,33 @@ the following keywords:
Error is signaled if no REPL buffers of specified type exist in current
session."
(declare (indent 1))
(let ((cur-type (cider-repl-type-for-buffer)))
(cl-case which
(let ((cur-type (cider-repl-type-for-buffer))
(which-key (or (car-safe which) which))
(ops-to-support (cdr-safe which)))
(cl-case which-key
(:clj-strict (when (eq cur-type 'cljs)
(user-error "Clojure-only operation requested in a ClojureScript buffer")))
(:cljs-strict (when (eq cur-type 'clj)
(user-error "ClojureScript-only operation requested in a Clojure buffer"))))
(let* ((type (cl-case which
(let* ((type (cl-case which-key
((:clj :clj-strict) 'clj)
((:cljs :cljs-strict) 'cljs)
(:auto (if (eq cur-type 'multi)
'(clj cljs)
cur-type))))
(ensure (cl-case which
(ensure (cl-case which-key
(:auto nil)
(t 'ensure)))
(repls (cider-repls type ensure)))
(mapcar function repls))))
(mapcar (lambda (repl)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This throws an error for non-matching connections, which seems undesirable.

My suggestion was that the ops-to-support act as a 'filter', selecting the acceptable repls that we'll iterate over.

Taking a look at the function body, it seems to me that the cleanest approach would be to:

  • also introduce a ops-to-support parameter to the cider-repls function
  • relay that parameter from here

This way, we still have the flexibility to be 'strict' (error-throwing) or not, by reusing the existing ensure logic.

(mapc (lambda (op)
(unless (nrepl-op-supported-p op repl)
(user-error "`%s' requires the nREPL op \"%s\" (provided by cider-nrepl)"
this-command op)))
ops-to-support)
(funcall function repl))
repls))))


;; REPLs double as connections in CIDER, so it's useful to be able to refer to
;; them as connections in certain contexts.
Expand Down
12 changes: 5 additions & 7 deletions cider-ns.el
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,13 @@ presenting the error message as an overlay."
error)
(cider-ns--present-error error))))

(defun cider-ns-refresh--save-modified-buffers ()
"Ensure any relevant modified buffers are saved before refreshing.
(defun cider-ns-refresh--save-modified-buffers (&optional connection)
"Ensure any relevant modified buffers for CONNECTION are saved before refreshing.
Its behavior is controlled by `cider-ns-save-files-on-refresh' and
`cider-ns-save-files-on-refresh-modes'."
(when cider-ns-save-files-on-refresh
(let ((dirs (seq-filter #'file-directory-p
(cider-classpath-entries))))
(cider-classpath-entries connection))))
(save-some-buffers
(not (eq cider-ns-save-files-on-refresh 'prompt))
(lambda ()
Expand Down Expand Up @@ -297,14 +297,12 @@ refresh functions (defined in `cider-ns-refresh-before-fn' and
`cider-ns-refresh-after-fn') from being invoked."
(interactive "p")
(cider-ensure-connected)
(cider-ensure-op-supported "refresh")
(cider-ensure-op-supported "cider.clj-reload/reload")
(cider-ns-refresh--save-modified-buffers)
(let ((clear? (member mode '(clear 16)))
(all? (member mode '(refresh-all 4)))
(inhibit-refresh-fns (member mode '(inhibit-fns -1))))
(cider-map-repls :clj
(cider-map-repls '(:clj "refresh" "cider.clj-reload/reload")
(lambda (conn)
(cider-ns-refresh--save-modified-buffers conn)
;; Inside the lambda, so the buffer is not created if we error out.
(let ((log-buffer (or (get-buffer cider-ns-refresh-log-buffer)
(cider-make-popup-buffer cider-ns-refresh-log-buffer))))
Expand Down
2 changes: 1 addition & 1 deletion doc/modules/ROOT/pages/usage/cider_mode.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ kbd:[C-u C-c C-c]

| `cider-ns-refresh`
| kbd:[C-c M-n (M-)r]
| Reload all modified files on the classpath. If invoked with a prefix argument, reload all files on the classpath. If invoked with a double prefix argument, clear the state of the namespace tracker before reloading.
| Reload all modified files on the classpath. If invoked with a prefix argument, reload all files on the classpath. If invoked with a double prefix argument, clear the state of the namespace tracker before reloading. Uses a clojure REPL whenever one exists.

| `cider-doc`
| kbd:[C-c C-d d] +
Expand Down