From 234cace977f58efab82b18ec267a0a6003f3a398 Mon Sep 17 00:00:00 2001 From: vemv Date: Tue, 5 Mar 2024 17:20:04 +0100 Subject: [PATCH 1/5] `cider-ns-refresh`: jump to the relevant file/line on errors Fixes #3626 --- CHANGELOG.md | 1 + cider-ns.el | 23 ++++++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) 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..8aa1d6767 100644 --- a/cider-ns.el +++ b/cider-ns.el @@ -169,7 +169,23 @@ namespace-qualified function of zero arity." (goto-char (point-max)))) (when (member "error" status) - (cider--render-stacktrace-causes error)))) + (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--save-modified-buffers () "Ensure any relevant modified buffers are saved before refreshing. @@ -219,10 +235,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 on 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 From 037dae48bf6895151e6f4bedcdbcd769c67f5ae4 Mon Sep 17 00:00:00 2001 From: vemv Date: Tue, 5 Mar 2024 17:30:59 +0100 Subject: [PATCH 2/5] Adapt docstring to linter --- cider-ns.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cider-ns.el b/cider-ns.el index 8aa1d6767..af17b2b62 100644 --- a/cider-ns.el +++ b/cider-ns.el @@ -235,8 +235,8 @@ indirectly load via require\"." ;;;###autoload (defun cider-ns-refresh (&optional mode) - "Reload modified and unloaded namespaces on the configured refresh dirs -(defaults to the classpath dirs). + "Reload modified and unloaded namespaces, +on 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 dirs unconditionally. From 0d30d5ec71268f9db86a6258190a9bf4c0b8097f Mon Sep 17 00:00:00 2001 From: vemv Date: Wed, 6 Mar 2024 04:53:06 +0100 Subject: [PATCH 3/5] Refine docstring --- cider-ns.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cider-ns.el b/cider-ns.el index af17b2b62..0d77faecb 100644 --- a/cider-ns.el +++ b/cider-ns.el @@ -235,8 +235,8 @@ indirectly load via require\"." ;;;###autoload (defun cider-ns-refresh (&optional mode) - "Reload modified and unloaded namespaces, -on the configured refresh dirs \(defaults to the classpath dirs). + "Reload modified and unloaded namespaces, using the Reload 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 dirs unconditionally. From 010803dbbb65e66fa6b519a5cbc095bcfe211315 Mon Sep 17 00:00:00 2001 From: vemv Date: Wed, 6 Mar 2024 04:58:30 +0100 Subject: [PATCH 4/5] Extract `cider-ns--present-error` --- cider-ns.el | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/cider-ns.el b/cider-ns.el index 0d77faecb..c87b00433 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,24 +189,9 @@ namespace-qualified function of zero arity." (with-current-buffer cider-ns-refresh-log-buffer (goto-char (point-max)))) - (when (member "error" status) - (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))))))) + (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. From 89d0f6a51bf3f4f0ca8c9ae30880778f76fc895a Mon Sep 17 00:00:00 2001 From: vemv Date: Wed, 6 Mar 2024 05:24:11 +0100 Subject: [PATCH 5/5] Typo --- cider-ns.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cider-ns.el b/cider-ns.el index c87b00433..81b0cd81b 100644 --- a/cider-ns.el +++ b/cider-ns.el @@ -241,7 +241,7 @@ indirectly load via require\"." ;;;###autoload (defun cider-ns-refresh (&optional mode) - "Reload modified and unloaded namespaces, using the Reload Workflow. + "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