Skip to content

Commit db14cf4

Browse files
[inspect] Add support for diff mode and sort-maps
1 parent aa8d638 commit db14cf4

File tree

3 files changed

+54
-6
lines changed

3 files changed

+54
-6
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
### New features
66

77
- [#3359](https://github.com/clojure-emacs/cider/pull/3359): Add customizable default connection params
8+
- [#3828](https://github.com/clojure-emacs/cider/issues/3828): Inspector: diff mode.
9+
- [#3828](https://github.com/clojure-emacs/cider/issues/3828): Inspector: sorting maps by keys.
810

911
### Changes
1012

cider-inspector.el

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,16 @@ The max depth can be also changed interactively within the inspector."
8484
:type 'boolean
8585
:package-version '(cider . "1.18.0"))
8686

87+
(defcustom cider-inspector-sort-maps nil
88+
"When true, sort inspected maps by keys."
89+
:type 'boolean
90+
:package-version '(cider . "1.19.0"))
91+
92+
(defcustom cider-inspector-only-diff nil
93+
"When true and inspecting a diff result, only display values that differ."
94+
:type 'boolean
95+
:package-version '(cider . "1.19.0"))
96+
8797
(defcustom cider-inspector-skip-uninteresting t
8898
"Controls whether to skip over uninteresting values in the inspector.
8999
Only applies to navigation with `cider-inspector-prev-inspectable-object'
@@ -147,6 +157,8 @@ Can be turned to nil once the user sees and acknowledges the feature."
147157
(define-key map [(shift tab)] #'cider-inspector-previous-inspectable-object)
148158
(define-key map "p" #'cider-inspector-previous-inspectable-object)
149159
(define-key map "P" #'cider-inspector-toggle-pretty-print)
160+
(define-key map "S" #'cider-inspector-toggle-sort-maps)
161+
(define-key map "D" #'cider-inspector-toggle-only-diff)
150162
(define-key map (kbd "C-c C-p") #'cider-inspector-print-current-value)
151163
(define-key map ":" #'cider-inspect-expr-from-inspector)
152164
(define-key map "f" #'forward-char)
@@ -185,6 +197,16 @@ Can be turned to nil once the user sees and acknowledges the feature."
185197
(setq-local sesman-system 'CIDER)
186198
(visual-line-mode 1))
187199

200+
(defun cider-inspector--highlight-diff-tags ()
201+
"Apply face to #± using overlays. We use overlays here because font-locking
202+
doesn't seem to work for this."
203+
(save-excursion
204+
(goto-char (point-min))
205+
(while (search-forward "" nil t)
206+
(let ((overlay (make-overlay (match-beginning 0) (match-end 0))))
207+
(overlay-put overlay 'face 'font-lock-warning-face)
208+
(overlay-put overlay 'priority 100)))))
209+
188210
;;;###autoload
189211
(defun cider-inspect-last-sexp ()
190212
"Inspect the result of the the expression preceding point."
@@ -354,9 +376,23 @@ MAX-NESTED-DEPTH is the new value."
354376
(defun cider-inspector-toggle-pretty-print ()
355377
"Toggle the pretty printing of values in the inspector."
356378
(interactive)
357-
(let ((result (cider-nrepl-send-sync-request `("op" "inspect-toggle-pretty-print"))))
358-
(when (nrepl-dict-get result "value")
359-
(cider-inspector--render-value result))))
379+
(customize-set-variable 'cider-inspector-pretty-print (not cider-inspector-pretty-print))
380+
(cider-inspector--refresh-with-opts
381+
"pretty-print" (if cider-inspector-pretty-print "true" "false")))
382+
383+
(defun cider-inspector-toggle-sort-maps ()
384+
"Toggle the sorting of maps in the inspector."
385+
(interactive)
386+
(customize-set-variable 'cider-inspector-sort-maps (not cider-inspector-sort-maps))
387+
(cider-inspector--refresh-with-opts
388+
"sort-maps" (if cider-inspector-sort-maps "true" "false")))
389+
390+
(defun cider-inspector-toggle-only-diff ()
391+
"Toggle the display of only differing values when inspecting diff results."
392+
(interactive)
393+
(customize-set-variable 'cider-inspector-only-diff (not cider-inspector-only-diff))
394+
(cider-inspector--refresh-with-opts
395+
"only-diff" (if cider-inspector-only-diff "true" "false")))
360396

361397
(defun cider-inspector-toggle-view-mode ()
362398
"Toggle the view mode of the inspector between normal and object view mode."
@@ -454,8 +490,9 @@ MAX-COLL-SIZE if non nil."
454490
`("max-nested-depth" ,cider-inspector-max-nested-depth))
455491
,@(when cider-inspector-display-analytics-hint
456492
`("display-analytics-hint" "true"))
457-
,@(when cider-inspector-pretty-print
458-
`("pretty-print" "true"))))
493+
"pretty-print" ,(if cider-inspector-pretty-print "true" "false")
494+
"sort-maps" ,(if cider-inspector-sort-maps "true" "false")
495+
"only-diff" ,(if cider-inspector-only-diff "true" "false")))
459496
(cider-nrepl-send-sync-request)))
460497

461498
(declare-function cider-set-buffer-ns "cider-mode")
@@ -522,7 +559,8 @@ from stack), `:next-inspectable' (move point to next inspectable object)."
522559
"Render ELEMENTS."
523560
(setq cider-inspector-looking-at-java-p nil)
524561
(dolist (el elements)
525-
(cider-inspector-render-el* el)))
562+
(cider-inspector-render-el* el))
563+
(cider-inspector--highlight-diff-tags))
526564

527565
(defconst cider--inspector-java-headers
528566
;; NOTE "--- Static fields:" "--- Instance fields:" are for objects,

doc/modules/ROOT/pages/debugging/inspector.adoc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ You'll have access to additional keybindings in the inspector buffer
8585
| `cider-inspector-toggle-pretty-print`
8686
| Toggle the pretty printing of values in the inspector. You can set the `cider-inspector-pretty-print` customization option to `t`, if you always want values to be be pretty printed.
8787

88+
| kbd:[S]
89+
| `cider-inspector-toggle-sort-maps`
90+
| Toggle the sorting of maps by key in the inspector. You can set the `cider-inspector-sort-maps` customization option to `t` if you always want maps to be displayed sorted.
91+
92+
| kbd:[D]
93+
| `cider-inspector-toggle-only-diff`
94+
| When inspecting a diff result, toggle only displaying the differing values. You can set the `cider-inspector-only-diff` customization option to `t` if you always want to only show the diff instead of all values.
95+
8896
| kbd:[d]
8997
| `cider-inspector-def-current-val`
9098
| Defines a var in the REPL namespace with current inspector value. If you tend to always choose the same name(s), you may want to set the `cider-inspector-preferred-var-names` customization option.

0 commit comments

Comments
 (0)