Skip to content

Commit c3a6e9d

Browse files
[inspect] Add support for :table view-mode
1 parent 5e81c0f commit c3a6e9d

File tree

5 files changed

+26
-4
lines changed

5 files changed

+26
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
## master (unreleased)
44

5-
* Bump `orchard` to [0.32.0](https://github.com/clojure-emacs/orchard/blob/master/CHANGELOG.md#0320-2025-04-05).
5+
* Bump `orchard` to [0.32.1](https://github.com/clojure-emacs/orchard/blob/master/CHANGELOG.md#0320-2025-04-05).
66
* [#925](https://github.com/clojure-emacs/cider-nrepl/pull/9250): Stop vendoring Puget dependency.
77
* [#917](https://github.com/clojure-emacs/cider-nrepl/pull/917): Sort printed maps in test output.
88
* [#927](https://github.com/clojure-emacs/cider-nrepl/pull/927): Add `inspect-display-analytics` op.
9+
* [#928](https://github.com/clojure-emacs/cider-nrepl/pull/922): Add support for `:table` view-mode in inspector.
910

1011
## 0.53.2 (2025-03-26)
1112

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ Returns::
763763

764764
=== `inspect-toggle-view-mode`
765765

766-
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 ``: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.
766+
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.
767767

768768
Required parameters::
769769
* `:session` The current session

src/cider/nrepl.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ if applicable, and re-render the updated value."
342342
"view-mode" "Mode of viewing the value - either `:normal` or `:object`"}
343343
:returns inspector-returns}
344344
"inspect-toggle-view-mode"
345-
{: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 `: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."
345+
{: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."
346346
:requires {"session" "The current session"}
347347
:returns inspector-returns}
348348
"inspect-display-analytics"

src/cider/nrepl/middleware/inspect.clj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@
7777
(inspector-response msg (swap-inspector! msg #(inspect/refresh % overrides)))))
7878

7979
(defn- toggle-view-mode [{:keys [view-mode] :as inspector}]
80-
(let [toggle-order {:normal :object, :object :normal}
80+
;; The order in which view modes are cycled depends on the inspected object.
81+
(let [toggle-order (if (inspect/supports-table-view-mode? inspector)
82+
{:normal :table, :table :object, :object :normal}
83+
{:normal :object, :object :normal})
8184
next-view-mode (toggle-order view-mode :normal)]
8285
(inspect/set-view-mode inspector next-view-mode)))
8386

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,15 @@
630630
" " [:value "_rest" number?] " = " [:value "(2 3)" number?]
631631
[:newline]])
632632

633+
(def table-mode-prefix
634+
["--- Contents:" [:newline]
635+
[:newline]
636+
" | " [:value "#" pos?] " | " [:value ":a" pos?] " | " [:newline]
637+
" |----+----|" [:newline]
638+
" | " [:value "0" pos?] " | " [:value "1" pos?] " | " [:newline]
639+
" | " [:value "1" pos?] " | " [:value "1" pos?] " | " [:newline]
640+
" | " [:value "2" pos?] " | " [:value "1" pos?] " | " [:newline]])
641+
633642
(deftest object-view-mode-integration-test
634643
(testing "view-mode can be toggled with inspect-toggle-view-mode op"
635644
(session/message {:op "inspect-clear"})
@@ -673,6 +682,15 @@
673682
:code "(range 100)"
674683
:display-analytics-hint "true"})))))
675684

685+
(deftest table-view-mode-integration-test
686+
(testing "table view-mode is supported for lists of maps"
687+
(session/message {:op "inspect-clear"})
688+
(session/message {:op "eval"
689+
:inspect "true"
690+
:code "(repeat 20 {:a 1})"})
691+
(is+ (matchers/prefix table-mode-prefix)
692+
(value-skip-header (session/message {:op "inspect-toggle-view-mode"})))))
693+
676694
(deftest print-length-independence-test
677695
(testing "*print-length* doesn't break rendering of long collections"
678696
(is (re-find #"showing page: \d+ of \d+"

0 commit comments

Comments
 (0)