From 0484b7389a233ec983b02203819f5caa038464b5 Mon Sep 17 00:00:00 2001 From: Oleksandr Yakushev Date: Wed, 18 Jun 2025 10:06:11 +0300 Subject: [PATCH 1/3] [inspect] Display string length --- CHANGELOG.md | 1 + src/orchard/inspect.clj | 8 +++----- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eac0bf6d..3a785a95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## 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. ## 0.35.0 (2025-05-28) diff --git a/src/orchard/inspect.clj b/src/orchard/inspect.clj index db11c98c..89bc68d8 100644 --- a/src/orchard/inspect.clj +++ b/src/orchard/inspect.clj @@ -367,11 +367,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) @@ -822,6 +819,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) From 227d960ea66c8bd5db1be32397d4f03d56de3ab7 Mon Sep 17 00:00:00 2001 From: Oleksandr Yakushev Date: Wed, 18 Jun 2025 10:24:47 +0300 Subject: [PATCH 2/3] [inspect] Enable hex-mode for byte arrays by default --- src/orchard/inspect.clj | 41 ++++++++++++++++++++--------------- test/orchard/inspect_test.clj | 24 +++++++++++++++++--- 2 files changed, 44 insertions(+), 21 deletions(-) diff --git a/src/orchard/inspect.clj b/src/orchard/inspect.clj index 89bc68d8..cd2a608f 100644 --- a/src/orchard/inspect.clj +++ b/src/orchard/inspect.clj @@ -23,7 +23,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 @@ -177,16 +177,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." @@ -290,7 +290,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)) @@ -318,10 +318,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)))) @@ -1116,11 +1119,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.`" diff --git a/test/orchard/inspect_test.clj b/test/orchard/inspect_test.clj index 285d871e..75d2d671 100644 --- a/test/orchard/inspect_test.clj +++ b/test/orchard/inspect_test.clj @@ -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) @@ -1527,7 +1527,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" @@ -1553,7 +1553,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)) From a540f9d32afe995d7ef46fea6592981bd6147496 Mon Sep 17 00:00:00 2001 From: Oleksandr Yakushev Date: Wed, 18 Jun 2025 10:34:46 +0300 Subject: [PATCH 3/3] [inspect] Display class flags --- CHANGELOG.md | 1 + src/orchard/inspect.clj | 5 +++++ test/orchard/inspect_test.clj | 6 ++++-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a785a95..46aa4c39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - [#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) diff --git a/src/orchard/inspect.clj b/src/orchard/inspect.clj index cd2a608f..af4b3c8a 100644 --- a/src/orchard/inspect.clj +++ b/src/orchard/inspect.clj @@ -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] @@ -955,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 %))) diff --git a/test/orchard/inspect_test.clj b/test/orchard/inspect_test.clj index 75d2d671..62386f1c 100644 --- a/test/orchard/inspect_test.clj +++ b/test/orchard/inspect_test.clj @@ -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:" @@ -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")]