diff --git a/CHANGELOG.md b/CHANGELOG.md index 96ee21708..ade86966e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ ### Changes +- [#3626](https://github.com/clojure-emacs/cider/issues/3626): `cider-ns-refresh`: jump to the relevant file/line on errors. - Bump the injected nREPL to [1.1.1](https://github.com/nrepl/nrepl/blob/v1.1.1/CHANGELOG.md#111-2024-02-20). - Bump the injected `cider-nrepl` to [0.46.0](https://github.com/clojure-emacs/cider-nrepl/blob/1cc9b2/CHANGELOG.md#0460-2024-0305). - Updates [Orchard](https://github.com/clojure-emacs/orchard/blob/v0.23.0/CHANGELOG.md#0230-2024-03-03). diff --git a/cider-ns.el b/cider-ns.el index 9e938f36e..81b0cd81b 100644 --- a/cider-ns.el +++ b/cider-ns.el @@ -118,6 +118,27 @@ namespace-qualified function of zero arity." :group 'cider :package-version '(cider . "0.10.0")) +(defun cider-ns--present-error (error) + "Render the `ERROR' stacktrace, +and jump to the adequate file/line location." + (let* ((buf) + (jump-args (seq-some (lambda (cause-dict) ;; a dict representing an exception cause + (nrepl-dbind-response cause-dict (file-url line column) + (when (and file-url + ;; jars are unlikely sources of user errors, so we favor the next `cause-dict': + (not (string-prefix-p "jar:" file-url)) + line) + (setq buf (cider--find-buffer-for-file file-url)) + (list buf (cons line column))))) + error))) + (when jump-args + (apply #'cider-jump-to jump-args)) + (cider--render-stacktrace-causes error) + ;; Select the window displaying the 'culprit' buffer so that the user can immediately fix it, + ;; as most times the displayed stacktrace doesn't need much inspection: + (when buf + (select-window (get-buffer-window buf))))) + (defun cider-ns-refresh--handle-response (response log-buffer) "Refresh LOG-BUFFER with RESPONSE." (nrepl-dbind-response response (out err reloading status error error-ns after before) @@ -168,8 +189,9 @@ namespace-qualified function of zero arity." (with-current-buffer cider-ns-refresh-log-buffer (goto-char (point-max)))) - (when (member "error" status) - (cider--render-stacktrace-causes error)))) + (when (and (member "error" status) + error) + (cider-ns--present-error error)))) (defun cider-ns-refresh--save-modified-buffers () "Ensure any relevant modified buffers are saved before refreshing. @@ -219,10 +241,11 @@ indirectly load via require\"." ;;;###autoload (defun cider-ns-refresh (&optional mode) - "Reload modified and unloaded namespaces on the classpath. + "Reload modified and unloaded namespaces, using the Reloaded Workflow. +Uses the configured 'refresh dirs' \(defaults to the classpath dirs). With a single prefix argument, or if MODE is `refresh-all', reload all -namespaces on the classpath unconditionally. +namespaces on the classpath dirs unconditionally. With a double prefix argument, or if MODE is `clear', clear the state of the namespace tracker before reloading. This is useful for recovering from