Skip to content

Commit 234cace

Browse files
committed
cider-ns-refresh: jump to the relevant file/line on errors
Fixes #3626
1 parent 89e66b3 commit 234cace

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
### Changes
1212

13+
- [#3626](https://github.com/clojure-emacs/cider/issues/3626): `cider-ns-refresh`: jump to the relevant file/line on errors.
1314
- Bump the injected nREPL to [1.1.1](https://github.com/nrepl/nrepl/blob/v1.1.1/CHANGELOG.md#111-2024-02-20).
1415
- Bump the injected `cider-nrepl` to [0.46.0](https://github.com/clojure-emacs/cider-nrepl/blob/1cc9b2/CHANGELOG.md#0460-2024-0305).
1516
- Updates [Orchard](https://github.com/clojure-emacs/orchard/blob/v0.23.0/CHANGELOG.md#0230-2024-03-03).

cider-ns.el

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,23 @@ namespace-qualified function of zero arity."
169169
(goto-char (point-max))))
170170

171171
(when (member "error" status)
172-
(cider--render-stacktrace-causes error))))
172+
(let* ((buf)
173+
(jump-args (seq-some (lambda (cause-dict) ;; a dict representing an exception cause
174+
(nrepl-dbind-response cause-dict (file-url line column)
175+
(when (and file-url
176+
;; jars are unlikely sources of user errors, so we favor the next `cause-dict':
177+
(not (string-prefix-p "jar:" file-url))
178+
line)
179+
(setq buf (cider--find-buffer-for-file file-url))
180+
(list buf (cons line column)))))
181+
error)))
182+
(when jump-args
183+
(apply #'cider-jump-to jump-args))
184+
(cider--render-stacktrace-causes error)
185+
;; Select the window displaying the 'culprit' buffer so that the user can immediately fix it,
186+
;; as most times the displayed stacktrace doesn't need much inspection:
187+
(when buf
188+
(select-window (get-buffer-window buf)))))))
173189

174190
(defun cider-ns-refresh--save-modified-buffers ()
175191
"Ensure any relevant modified buffers are saved before refreshing.
@@ -219,10 +235,11 @@ indirectly load via require\"."
219235

220236
;;;###autoload
221237
(defun cider-ns-refresh (&optional mode)
222-
"Reload modified and unloaded namespaces on the classpath.
238+
"Reload modified and unloaded namespaces on the configured refresh dirs
239+
(defaults to the classpath dirs).
223240
224241
With a single prefix argument, or if MODE is `refresh-all', reload all
225-
namespaces on the classpath unconditionally.
242+
namespaces on the classpath dirs unconditionally.
226243
227244
With a double prefix argument, or if MODE is `clear', clear the state of
228245
the namespace tracker before reloading. This is useful for recovering from

0 commit comments

Comments
 (0)