Skip to content

Commit 0070159

Browse files
committed
Add inspect-toggle-pretty-print op
1 parent 46cc444 commit 0070159

File tree

4 files changed

+60
-18
lines changed

4 files changed

+60
-18
lines changed

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

+16
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,22 @@ Returns::
730730
* `:value` The inspector result. Contains a specially-formatted string that can be ``read`` and then rendered client-side.
731731

732732

733+
=== `inspect-toggle-pretty-print`
734+
735+
Toggles the pretty printing of values in the inspector. When enabled, values are printed in the inspector with the `orchard.pp` pretty printer.
736+
737+
Required parameters::
738+
* `:session` The current session
739+
740+
Optional parameters::
741+
{blank}
742+
743+
Returns::
744+
* `:path` Printed representation of current inspector path.
745+
* `:status` "done"
746+
* `:value` The inspector result. Contains a specially-formatted string that can be ``read`` and then rendered client-side.
747+
748+
733749

734750
=== `inspect-toggle-view-mode`
735751

src/cider/nrepl.clj

+4
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,10 @@ if applicable, and re-render the updated value."
341341
"max-nested-depth" "New max nested depth of rendered collection"
342342
"view-mode" "Mode of viewing the value - either `:normal` or `:object`"}
343343
:returns inspector-returns}
344+
"inspect-toggle-pretty-print"
345+
{:doc "Toggles the pretty printing of values in the inspector."
346+
:requires {"session" "The current session"}
347+
:returns inspector-returns}
344348
"inspect-toggle-view-mode"
345349
{:doc "Toggles the viewing mode of the inspector. This influences the way how inspector is rendering the current value. `:normal` is the default. When view mode is `:table`, the value will be rendered as a table (only supported for sequences of maps or tuples). When view mode is `:object`, any value will be rendered as a Java object (fields shown as is). View mode is automatically reset back to normal when navigating to child values."
346350
:requires {"session" "The current session"}

src/cider/nrepl/middleware/inspect.clj

+4
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@
7979
(let [overrides (msg->inspector-config msg)]
8080
(inspector-response msg (swap-inspector! msg #(inspect/refresh % overrides)))))
8181

82+
(defn toggle-pretty-print-reply [msg]
83+
(inspector-response msg (swap-inspector! msg #(-> (update % :pretty-print not) (inspect/inspect-render)))))
84+
8285
(defn- toggle-view-mode [{:keys [view-mode] :as inspector}]
8386
;; The order in which view modes are cycled depends on the inspected object.
8487
(let [toggle-order (if (inspect/supports-table-view-mode? inspector)
@@ -122,6 +125,7 @@
122125
"inspect-next-page" next-page-reply
123126
"inspect-prev-page" prev-page-reply
124127
"inspect-refresh" refresh-reply
128+
"inspect-toggle-pretty-print" toggle-pretty-print-reply
125129
"inspect-toggle-view-mode" toggle-view-mode-reply
126130
"inspect-display-analytics" display-analytics-reply
127131
"inspect-set-page-size" refresh-reply

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

+36-18
Original file line numberDiff line numberDiff line change
@@ -697,24 +697,42 @@
697697
(session/message {:op "eval"
698698
:inspect "true"
699699
:code "(repeat 5 {:a (repeat 5 {:b 2}) :c (repeat 5 {:d 2})})"})
700-
(is+ ["--- Contents:" [:newline]
701-
" 0. " [:value (str "{:a ({:b 2} {:b 2} {:b 2} {:b 2} {:b 2}),"
702-
"\n :c ({:d 2} {:d 2} {:d 2} {:d 2} {:d 2})}") 1]
703-
[:newline]
704-
" 1. " [:value (str "{:a ({:b 2} {:b 2} {:b 2} {:b 2} {:b 2}),"
705-
"\n :c ({:d 2} {:d 2} {:d 2} {:d 2} {:d 2})}") 2]
706-
[:newline]
707-
" 2. " [:value (str "{:a ({:b 2} {:b 2} {:b 2} {:b 2} {:b 2}),"
708-
"\n :c ({:d 2} {:d 2} {:d 2} {:d 2} {:d 2})}") 3]
709-
[:newline]
710-
" 3. " [:value (str "{:a ({:b 2} {:b 2} {:b 2} {:b 2} {:b 2}),"
711-
"\n :c ({:d 2} {:d 2} {:d 2} {:d 2} {:d 2})}") 4]
712-
[:newline]
713-
" 4. " [:value (str "{:a ({:b 2} {:b 2} {:b 2} {:b 2} {:b 2}),"
714-
"\n :c ({:d 2} {:d 2} {:d 2} {:d 2} {:d 2})}") 5]
715-
[:newline]]
716-
(value-skip-header (session/message {:op "inspect-refresh"
717-
:pretty-print "true"})))))
700+
(testing "toggle pretty printing and turn it on"
701+
(is+ ["--- Contents:" [:newline]
702+
" 0. " [:value (str "{:a ({:b 2} {:b 2} {:b 2} {:b 2} {:b 2}),"
703+
"\n :c ({:d 2} {:d 2} {:d 2} {:d 2} {:d 2})}") 1]
704+
[:newline]
705+
" 1. " [:value (str "{:a ({:b 2} {:b 2} {:b 2} {:b 2} {:b 2}),"
706+
"\n :c ({:d 2} {:d 2} {:d 2} {:d 2} {:d 2})}") 2]
707+
[:newline]
708+
" 2. " [:value (str "{:a ({:b 2} {:b 2} {:b 2} {:b 2} {:b 2}),"
709+
"\n :c ({:d 2} {:d 2} {:d 2} {:d 2} {:d 2})}") 3]
710+
[:newline]
711+
" 3. " [:value (str "{:a ({:b 2} {:b 2} {:b 2} {:b 2} {:b 2}),"
712+
"\n :c ({:d 2} {:d 2} {:d 2} {:d 2} {:d 2})}") 4]
713+
[:newline]
714+
" 4. " [:value (str "{:a ({:b 2} {:b 2} {:b 2} {:b 2} {:b 2}),"
715+
"\n :c ({:d 2} {:d 2} {:d 2} {:d 2} {:d 2})}") 5]
716+
[:newline]]
717+
(value-skip-header (session/message {:op "inspect-toggle-pretty-print"}))))
718+
(testing "toggle pretty printing and turn it off"
719+
(is+ ["--- Contents:" [:newline]
720+
" 0. " [:value (str "{:a ({:b 2} {:b 2} {:b 2} {:b 2} {:b 2}),"
721+
" :c ({:d 2} {:d 2} {:d 2} {:d 2} {:d 2})}") 1]
722+
[:newline]
723+
" 1. " [:value (str "{:a ({:b 2} {:b 2} {:b 2} {:b 2} {:b 2}),"
724+
" :c ({:d 2} {:d 2} {:d 2} {:d 2} {:d 2})}") 2]
725+
[:newline]
726+
" 2. " [:value (str "{:a ({:b 2} {:b 2} {:b 2} {:b 2} {:b 2}),"
727+
" :c ({:d 2} {:d 2} {:d 2} {:d 2} {:d 2})}") 3]
728+
[:newline]
729+
" 3. " [:value (str "{:a ({:b 2} {:b 2} {:b 2} {:b 2} {:b 2}),"
730+
" :c ({:d 2} {:d 2} {:d 2} {:d 2} {:d 2})}") 4]
731+
[:newline]
732+
" 4. " [:value (str "{:a ({:b 2} {:b 2} {:b 2} {:b 2} {:b 2}),"
733+
" :c ({:d 2} {:d 2} {:d 2} {:d 2} {:d 2})}") 5]
734+
[:newline]]
735+
(value-skip-header (session/message {:op "inspect-toggle-pretty-print"}))))))
718736

719737
(deftest print-length-independence-test
720738
(testing "*print-length* doesn't break rendering of long collections"

0 commit comments

Comments
 (0)