Skip to content

Commit 8a47f7b

Browse files
[stacktrace] Allow inspecting ex-data directly
1 parent 2b2492b commit 8a47f7b

File tree

3 files changed

+53
-31
lines changed

3 files changed

+53
-31
lines changed

cider-inspector.el

+8-11
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,16 @@ See `cider-sync-request:inspect-push' and `cider-inspector--render-value'"
252252
(push (point) cider-inspector-location-stack)
253253
(cider-inspector--render-value result :next-inspectable))))
254254

255-
(defun cider-inspector-inspect-last-exception (index)
256-
"Inspects the exception in the cause stack identified by INDEX."
255+
(defun cider-inspector-inspect-last-exception (index &optional ex-data)
256+
"Inspects the exception in the cause stack identified by INDEX.
257+
If EX-DATA is true, inspect ex-data of the exception instead."
257258
(interactive)
258259
(cl-assert (numberp index))
259-
(let ((result (cider-sync-request:inspect-last-exception index)))
260+
(let ((result (cider-nrepl-send-sync-request `("op" "inspect-last-exception"
261+
"index" ,index
262+
,@(when ex-data
263+
`("ex-data" "true")))
264+
(cider-current-repl))))
260265
(when (nrepl-dict-get result "value")
261266
(setq cider-inspector-location-stack nil)
262267
(cider-inspector--render-value result :next-inspectable))))
@@ -423,14 +428,6 @@ current-namespace."
423428
(cider-nrepl-send-sync-request `("op" "inspect-previous-sibling")
424429
(cider-current-repl)))
425430

426-
;;;###autoload
427-
(defun cider-sync-request:inspect-last-exception (index)
428-
"Inspects the exception in the cause stack identified by INDEX."
429-
(cl-assert (numberp index))
430-
(cider-nrepl-send-sync-request `("op" "inspect-last-exception"
431-
"index" ,index)
432-
(cider-current-repl)))
433-
434431
(defun cider-sync-request:inspect-next-sibling ()
435432
"Inspect the next sibling value within a sequential parent."
436433
(cider-nrepl-send-sync-request `("op" "inspect-next-sibling")

cider-stacktrace.el

+37-13
Original file line numberDiff line numberDiff line change
@@ -796,27 +796,44 @@ the NAME. The whole group is prefixed by string INDENT."
796796

797797
(declare-function cider-inspector-inspect-last-exception "cider-inspector")
798798

799-
(defun cider-stacktrace--inspect-class (event)
799+
(defun cider-stacktrace--inspect-mouse (event &optional ex-data)
800800
"Mouse handler for EVENT."
801801
(interactive "e")
802802
(let* ((pos (posn-point (event-end event)))
803803
(window (posn-window (event-end event)))
804804
(buffer (window-buffer window))
805805
(inspect-index (with-current-buffer buffer
806806
(get-text-property pos 'inspect-index))))
807-
(cider-inspector-inspect-last-exception inspect-index)))
807+
(cider-inspector-inspect-last-exception inspect-index ex-data)))
808808

809-
(defun cider-stacktrace--inspect-class-kbd ()
809+
(defun cider-stacktrace--inspect-kbd (&optional ex-data)
810810
"Keyboard handler."
811811
(interactive)
812812
(when-let ((inspect-index (get-text-property (point) 'inspect-index)))
813-
(cider-inspector-inspect-last-exception inspect-index)))
813+
(cider-inspector-inspect-last-exception inspect-index ex-data)))
814+
815+
(defun cider-stacktrace--inspect-ex-data-mouse (event)
816+
(interactive "e")
817+
(cider-stacktrace--inspect-mouse event t))
818+
819+
(defun cider-stacktrace--inspect-ex-data-kbd ()
820+
(interactive)
821+
(cider-stacktrace--inspect-kbd t))
814822

815823
(defvar cider-stacktrace-exception-map
816824
(let ((map (make-sparse-keymap)))
817-
(define-key map [mouse-1] #'cider-stacktrace--inspect-class)
818-
(define-key map (kbd "p") #'cider-stacktrace--inspect-class-kbd)
819-
(define-key map (kbd "i") #'cider-stacktrace--inspect-class-kbd)
825+
(define-key map [mouse-1] #'cider-stacktrace--inspect-mouse)
826+
(define-key map (kbd "p") #'cider-stacktrace--inspect-kbd)
827+
(define-key map (kbd "i") #'cider-stacktrace--inspect-kbd)
828+
(define-key map (kbd "RET") #'cider-stacktrace--inspect-kbd)
829+
map))
830+
831+
(defvar cider-stacktrace-ex-data-map
832+
(let ((map (make-sparse-keymap)))
833+
(define-key map [mouse-1] #'cider-stacktrace--inspect-ex-data-mouse)
834+
(define-key map (kbd "p") #'cider-stacktrace--inspect-ex-data-kbd)
835+
(define-key map (kbd "i") #'cider-stacktrace--inspect-ex-data-kbd)
836+
(define-key map (kbd "RET") #'cider-stacktrace--inspect-ex-data-kbd)
820837
map))
821838

822839
(defun cider-stacktrace-render-cause (buffer cause num note &optional inspect-index)
@@ -839,10 +856,10 @@ make INSPECT-INDEX actionable if present."
839856
,cider-stacktrace-exception-map)
840857
(insert (format "%d. " num)
841858
(propertize note 'font-lock-face 'font-lock-comment-face) " "
842-
(propertize class 'font-lock-face class-face 'mouse-face 'highlight)))
859+
(propertize class 'font-lock-face class-face 'mouse-face 'highlight)
860+
"\n"))
843861
;; Detail level 1: message + ex-data
844862
(cider-propertize-region '(detail 1)
845-
(insert "\n")
846863
(if (equal class "clojure.lang.Compiler$CompilerException")
847864
(cider-stacktrace-render-compile-error buffer cause)
848865
(cider-stacktrace-emit-indented
@@ -859,18 +876,25 @@ make INSPECT-INDEX actionable if present."
859876
(cider-stacktrace--emit-spec-problems spec (concat indent " ")))
860877
(when data
861878
(insert "\n")
862-
(cider-stacktrace-emit-indented data indent nil t)))
879+
(cider-propertize-region `(inspect-index
880+
,inspect-index
881+
keymap
882+
,cider-stacktrace-ex-data-map
883+
mouse-face
884+
highlight)
885+
(cider-stacktrace-emit-indented data indent nil t)))
886+
(insert "\n"))
863887
;; Detail level 2: stacktrace
864888
(cider-propertize-region '(detail 2)
865889
(let ((beg (point))
866890
(bg `(:background ,cider-stacktrace-frames-background-color :extend t)))
867891
(dolist (frame stacktrace)
868-
(insert "\n")
869-
(cider-stacktrace-render-frame buffer frame))
892+
(cider-stacktrace-render-frame buffer frame)
893+
(insert "\n"))
870894
(overlay-put (make-overlay beg (point)) 'font-lock-face bg)))
871895
;; Add line break between causes, even when collapsed.
872896
(cider-propertize-region '(detail 0)
873-
(insert "\n\n")))))))
897+
(insert "\n")))))))
874898

875899
(defun cider-stacktrace-initialize (causes)
876900
"Set and apply CAUSES initial visibility, filters, and cursor position."

doc/modules/ROOT/pages/usage/dealing_with_errors.adoc

+8-7
Original file line numberDiff line numberDiff line change
@@ -212,18 +212,19 @@ for instance:
212212

213213
== Inspector integration
214214

215-
Within `*cider-error*`, when clicking directly a top-level exception (any of them in the cause chain),
216-
that specific exception will be inspected with the CIDER xref:debugging/inspector.adoc[Inspector].
215+
Within `*cider-error*`, when clicking directly a top-level exception (any of
216+
them in the cause chain), that specific exception will be inspected with the
217+
CIDER xref:debugging/inspector.adoc[Inspector]. You can also click on the
218+
rendered exception data to inspect it directly.
217219

218-
This allows you to better understand intrincate `ex-data`.
219-
220-
This clicking is defined and customizable in `cider-stacktrace-exception-map`, which has the following defaults:
220+
This clicking is defined and customizable in `cider-stacktrace-exception-map`
221+
and `cider-stacktrace-ex-data-map`.
221222

222223
=== Keybindings
223224

224225
|===
225226
| Action | Description
226227

227-
| kbd:[click] or kbd:[i] or kbd:[p]
228-
| Open the given exception in the Inspector.
228+
| kbd:[click] or kbd:[i] or kbd:[p] or kbd:[Return]
229+
| Open the given exception or ex-data in the Inspector.
229230
|===

0 commit comments

Comments
 (0)