Skip to content

Commit ebbc24f

Browse files
[inspect] Add support for sort-maps and diff view
1 parent 44c47ad commit ebbc24f

File tree

8 files changed

+36
-9
lines changed

8 files changed

+36
-9
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## master (unreleased)
44

5+
* Bump `orchard` to [0.36.0](https://github.com/clojure-emacs/orchard/blob/master/CHANGELOG.md#0360-2025-06-29).
6+
57
## 0.56.0 (2025-05-29)
68

79
* Bump `orchard` to [0.35.0](https://github.com/clojure-emacs/orchard/blob/master/CHANGELOG.md#0350-2025-05-28).

doc/modules/ROOT/pages/nrepl-api/ops.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,10 @@ Optional parameters::
631631
* `:max-atom-length` New max length of single rendered value
632632
* `:max-coll-size` New max size of rendered collection
633633
* `:max-nested-depth` New max nested depth of rendered collection
634+
* `:only-diff` Set to true to only display values that differ when inspecting a diff
634635
* `:page-size` New page size
636+
* `:pretty-print` Set to true to pretty-print values within the inspector
637+
* `:sort-maps` Set to true to sort maps by their keys when inspecting a map
635638
* `:view-mode` Mode of viewing the value - either ``:normal`` or ``:object``
636639

637640

project.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
:url "http://www.eclipse.org/legal/epl-v10.html"}
2222
:scm {:name "git" :url "https://github.com/clojure-emacs/cider-nrepl"}
2323
:dependencies [[nrepl/nrepl "1.3.1" :exclusions [org.clojure/clojure]]
24-
[cider/orchard "0.35.0" :exclusions [org.clojure/clojure]]
24+
[cider/orchard "0.36.0" :exclusions [org.clojure/clojure]]
2525
^:inline-dep [compliment "0.7.0"]
2626
^:inline-dep [org.rksm/suitable "0.6.2" :exclusions [org.clojure/clojure
2727
org.clojure/clojurescript]]

src/cider/nrepl.clj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,10 @@ if applicable, and re-render the updated value."
344344
"max-atom-length" "New max length of single rendered value"
345345
"max-coll-size" "New max size of rendered collection"
346346
"max-nested-depth" "New max nested depth of rendered collection"
347-
"view-mode" "Mode of viewing the value - either `:normal` or `:object`"}
347+
"view-mode" "Mode of viewing the value - either `:normal` or `:object`"
348+
"pretty-print" "Set to true to pretty-print values within the inspector"
349+
"sort-maps" "Set to true to sort maps by their keys when inspecting a map"
350+
"only-diff" "Set to true to only display values that differ when inspecting a diff"}
348351
:returns inspector-returns}
349352
"inspect-toggle-pretty-print"
350353
{:doc "Toggles the pretty printing of values in the inspector."

src/cider/nrepl/middleware/inspect.clj

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,16 @@
3333
:path (pr-str (seq (:path inspector)))})]
3434
(response-for msg data extra-response-data))))
3535

36+
(defn- booleanize [m keys]
37+
(reduce (fn [m k] (cond-> m
38+
(contains? m k) (update k = "true")))
39+
m keys))
40+
3641
(defn- msg->inspector-config [msg]
3742
(-> (select-keys msg [:page-size :max-atom-length :max-coll-size
3843
:max-value-length :max-nested-depth :display-analytics-hint
39-
:pretty-print])
40-
(update :pretty-print #(= "true" %))))
44+
:pretty-print :sort-maps :only-diff])
45+
(booleanize [:pretty-print :sort-maps :only-diff])))
4146

4247
(defn inspect-reply* [{:keys [view-mode] :as msg} value]
4348
(let [config (msg->inspector-config msg)

test/clj/cider/nrepl/middleware/inspect_test.clj

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,14 @@
7575
" ●normal object pretty"])
7676

7777
(defn value [{:keys [value]}]
78-
(edn/read-string (first value)))
78+
(->> (edn/read-string (first value))
79+
;; Merge strings
80+
(reduce (fn [acc x]
81+
(let [lst (peek acc)]
82+
(if (and (string? x) (string? lst))
83+
(conj (pop acc) (str lst x))
84+
(conj acc x))))
85+
[])))
7986

8087
(defn value-skip-header [resp]
8188
(drop-while #(not (and (string? %) (.startsWith ^String % "---")))
@@ -524,7 +531,7 @@
524531
"\n :c ({:d 2} {:d 2} {:d 2} {:d 2} {:d 2} {:d 2})}") 5]
525532
[:newline] [:newline]
526533
#"--- View mode" [:newline]
527-
" ●normal table object ●pretty"]
534+
" ●normal table object ●pretty sort-maps"]
528535
(value-skip-header (session/message {:op "inspect-toggle-pretty-print"}))))
529536
(testing "toggle pretty printing and turn it off"
530537
(is+ ["--- Contents:" [:newline]
@@ -544,7 +551,7 @@
544551
" :c ({:d 2} {:d 2} {:d 2} {:d 2} {:d 2} {:d 2})}") 5]
545552
[:newline] [:newline]
546553
#"--- View mode" [:newline]
547-
" ●normal table object pretty"]
554+
" ●normal table object pretty sort-maps"]
548555
(value-skip-header (session/message {:op "inspect-toggle-pretty-print"}))))))
549556

550557
(deftest print-length-independence-test

test/clj/cider/nrepl/middleware/profile_test.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
(is+ {:status #{"done"}
3434
:value [(mc/via read-string
3535
(mc/prefix ["Class: " [:value "clojure.lang.ArraySeq" 0] [:newline]
36-
"Count: 1" [:newline] [:newline]
36+
"Count: " "1" [:newline] [:newline]
3737
"--- Contents:" [:newline] [:newline]]))]}
3838
(session/message {:op "cider/profile-summary"}))))
3939

test/cljs/cider/nrepl/middleware/cljs_inspect_test.clj

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,14 @@
3333
" 34. " [:value "34" 3]])
3434

3535
(defn value [{:keys [value]}]
36-
(edn/read-string (first value)))
36+
(->> (edn/read-string (first value))
37+
;; Merge strings
38+
(reduce (fn [acc x]
39+
(let [lst (peek acc)]
40+
(if (and (string? x) (string? lst))
41+
(conj (pop acc) (str lst x))
42+
(conj acc x))))
43+
[])))
3744

3845
;; integration tests
3946

0 commit comments

Comments
 (0)