Skip to content

Commit cfe2de3

Browse files
authored
cider-ns-refresh: jump to the relevant file/line on errors (#3627)
Fixes #3626
1 parent 89e66b3 commit cfe2de3

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
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: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,27 @@ namespace-qualified function of zero arity."
118118
:group 'cider
119119
:package-version '(cider . "0.10.0"))
120120

121+
(defun cider-ns--present-error (error)
122+
"Render the `ERROR' stacktrace,
123+
and jump to the adequate file/line location."
124+
(let* ((buf)
125+
(jump-args (seq-some (lambda (cause-dict) ;; a dict representing an exception cause
126+
(nrepl-dbind-response cause-dict (file-url line column)
127+
(when (and file-url
128+
;; jars are unlikely sources of user errors, so we favor the next `cause-dict':
129+
(not (string-prefix-p "jar:" file-url))
130+
line)
131+
(setq buf (cider--find-buffer-for-file file-url))
132+
(list buf (cons line column)))))
133+
error)))
134+
(when jump-args
135+
(apply #'cider-jump-to jump-args))
136+
(cider--render-stacktrace-causes error)
137+
;; Select the window displaying the 'culprit' buffer so that the user can immediately fix it,
138+
;; as most times the displayed stacktrace doesn't need much inspection:
139+
(when buf
140+
(select-window (get-buffer-window buf)))))
141+
121142
(defun cider-ns-refresh--handle-response (response log-buffer)
122143
"Refresh LOG-BUFFER with RESPONSE."
123144
(nrepl-dbind-response response (out err reloading status error error-ns after before)
@@ -168,8 +189,9 @@ namespace-qualified function of zero arity."
168189
(with-current-buffer cider-ns-refresh-log-buffer
169190
(goto-char (point-max))))
170191

171-
(when (member "error" status)
172-
(cider--render-stacktrace-causes error))))
192+
(when (and (member "error" status)
193+
error)
194+
(cider-ns--present-error error))))
173195

174196
(defun cider-ns-refresh--save-modified-buffers ()
175197
"Ensure any relevant modified buffers are saved before refreshing.
@@ -219,10 +241,11 @@ indirectly load via require\"."
219241

220242
;;;###autoload
221243
(defun cider-ns-refresh (&optional mode)
222-
"Reload modified and unloaded namespaces on the classpath.
244+
"Reload modified and unloaded namespaces, using the Reloaded Workflow.
245+
Uses the configured 'refresh dirs' \(defaults to the classpath dirs).
223246
224247
With a single prefix argument, or if MODE is `refresh-all', reload all
225-
namespaces on the classpath unconditionally.
248+
namespaces on the classpath dirs unconditionally.
226249
227250
With a double prefix argument, or if MODE is `clear', clear the state of
228251
the namespace tracker before reloading. This is useful for recovering from

0 commit comments

Comments
 (0)