Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
## master (unreleased)

- [#346](https://github.com/clojure-emacs/orchard/pull/346): Inspector: only show those datafied collection items that have unique datafy represantation.
- [#348](https://github.com/clojure-emacs/orchard/pull/348): Inspector: display length of inspected strings.
- [#348](https://github.com/clojure-emacs/orchard/pull/348): Inspector: display class flags.

## 0.35.0 (2025-05-28)

Expand Down
54 changes: 31 additions & 23 deletions src/orchard/inspect.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
Pretty wild, right?"
(:require
[clojure.core.protocols :refer [datafy nav]]
[clojure.reflect :as reflect]
[clojure.string :as str]
[orchard.inspect.analytics :as analytics]
[orchard.java.compatibility :as compat]
Expand All @@ -23,7 +24,7 @@
;; Navigating Inspector State
;;

(declare inspect-render)
(declare inspect-render supported-view-modes)

(defn push-item-to-path
"Takes `path` and the role and key of the value to be navigated to, and returns
Expand Down Expand Up @@ -177,16 +178,16 @@
;; :current-page may be wrong, recompute it.
current-page (if (number? child-key)
(quot child-key page-size)
current-page)]
(-> inspector
(assoc :value child)
(dissoc :value-analysis)
(update :stack conj value)
(assoc :current-page 0)
(update :pages-stack conj current-page)
(assoc :view-mode :normal)
(update :view-modes-stack conj view-mode)
(update :path push-item-to-path child-role child-key))))
current-page)
ins (-> inspector
(assoc :value child)
(dissoc :value-analysis)
(update :stack conj value)
(assoc :current-page 0)
(update :pages-stack conj current-page)
(update :view-modes-stack conj view-mode)
(update :path push-item-to-path child-role child-key))]
(assoc ins :view-mode (first (supported-view-modes ins)))))

(defn down
"Drill down to an indexed object referred to by the previously rendered value."
Expand Down Expand Up @@ -290,7 +291,7 @@

;; View modes

(def ^:private view-mode-order [:normal :hex :table :object])
(def ^:private view-mode-order [:hex :normal :table :object])

(defmulti view-mode-supported? (fn [_inspector view-mode] view-mode))

Expand Down Expand Up @@ -318,10 +319,13 @@
(pre-ex (view-mode-supported? inspector mode))
(inspect-render (assoc inspector :view-mode mode)))

(defn- supported-view-modes [inspector]
(filter #(view-mode-supported? inspector %) view-mode-order))

(defn toggle-view-mode
"Switch to the next supported view mode."
[{:keys [view-mode] :as inspector}]
(let [supported (filter #(view-mode-supported? inspector %) view-mode-order)
(let [supported (supported-view-modes inspector)
transitions (zipmap supported (rest (cycle supported)))]
(set-view-mode inspector (transitions view-mode))))

Expand Down Expand Up @@ -367,11 +371,8 @@
(render-onto (render-indent inspector) values)))

(defn- render-indent-ln [inspector & values]
(let [padding (padding inspector)]
(cond-> inspector
padding (render padding)
(seq values) (render-onto values)
true (render '(:newline)))))
(-> (apply render-indent inspector values)
(render-ln)))

(defn- render-section-header [inspector section]
(-> (render-ln inspector)
Expand Down Expand Up @@ -822,6 +823,7 @@
(-> (render-class-name inspector obj)
(render "Value: " (print-string inspector obj))
(render-ln)
(render-indent-ln "Length: " (str (.length obj)))
(render-section-header "Print")
(indent)
(render-indent-str-lines obj)
Expand Down Expand Up @@ -954,6 +956,10 @@
(-> inspector
(render-labeled-value "Name" (-> obj .getName symbol))
(render-class-name obj)
(render "Flags: " (->> (#'clojure.reflect/parse-flags (.getModifiers obj) :class)
(map name)
(str/join " ")))
(render-ln)
(render-class-hierarchy obj)
(render-class-section :Constructors (.getConstructors obj)
(print-fn #(.toGenericString ^Constructor %)))
Expand Down Expand Up @@ -1118,11 +1124,13 @@
of supported keys."
([value] (start {} value))
([config value]
(-> default-inspector-config
(merge (validate-config config))
(assoc :stack [], :path [], :pages-stack [], :current-page 0,
:view-modes-stack [], :view-mode :normal, :value value)
(inspect-render))))
(let [inspector (-> default-inspector-config
(merge (validate-config config))
(assoc :stack [], :path [], :pages-stack [], :current-page 0,
:view-modes-stack [], :value value))]
(-> inspector
(assoc :view-mode (first (supported-view-modes inspector)))
inspect-render))))

(defn ^:deprecated clear
"If necessary, use `(start inspector nil) instead.`"
Expand Down
30 changes: 25 additions & 5 deletions test/orchard/inspect_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@
:value))))
(testing "sibling functions work with arrays"
(is+ {:value 35, :pages-stack [1], :path '[(nth 35)]}
(-> (byte-array (range 40))
(-> (long-array (range 40))
inspect
(inspect/down 33)
(inspect/next-sibling)
Expand Down Expand Up @@ -931,7 +931,8 @@
(testing "renders the header section"
(is+ ["Name: "
[:value "java.lang.Object" 0] [:newline]
"Class: " [:value "java.lang.Class" 1] [:newline] [:newline]]
"Class: " [:value "java.lang.Class" 1] [:newline]
"Flags: public" [:newline] [:newline]]
(header rendered)))
(testing "renders the constructors section"
(is+ ["--- Constructors:"
Expand Down Expand Up @@ -997,7 +998,8 @@
(testing "renders the header section"
(is+ ["Name: "
[:value "java.lang.ClassValue" 0] [:newline]
"Class: " [:value "java.lang.Class" 1] [:newline] [:newline]]
"Class: " [:value "java.lang.Class" 1] [:newline]
"Flags: public abstract" [:newline] [:newline]]
(header rendered)))
(testing "renders the methods section"
(let [methods (section rendered "Methods")]
Expand Down Expand Up @@ -1527,7 +1529,7 @@
" 0x00000050 │ 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f │ PQRSTUVWXYZ[\\]^_" [:newline]
" 0x00000060 │ 60 61 62 63 │ `abc"]
(contents-section rendered))
(is+ [#"--- View mode" [:newline] " normal ●hex object pretty"]
(is+ [#"--- View mode" [:newline] " ●hex normal object pretty"]
(section rendered "View mode"))))

(testing "works with paging"
Expand All @@ -1553,7 +1555,25 @@
(set-page-size 2)
inspect/next-page
render
contents-section))))
contents-section))

(testing "enabled by default for byte arrays"
(is+ (matchers/prefix
["--- Contents:" [:newline]
" 0x00000000 │ 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f │ ················"])
(-> (byte-array (range 100))
inspect
render
contents-section))

(is+ (matchers/prefix
["--- Contents:" [:newline]
" 0x00000000 │ 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f │ ················"])
(-> [(byte-array (range 100))]
inspect
(inspect/down 1)
render
contents-section)))))

(deftest toggle-view-mode-test
(is+ :normal (-> (repeat 10 [1 2]) inspect :view-mode))
Expand Down