From ee69a4e664eb3a926702c90d2b8401e891a33b6a Mon Sep 17 00:00:00 2001 From: Oleksandr Yakushev Date: Tue, 14 May 2024 10:37:03 +0300 Subject: [PATCH 1/3] [inspector] Add configuration for max-nested-depth and spacious --- cider-inspector.el | 61 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 45 insertions(+), 16 deletions(-) diff --git a/cider-inspector.el b/cider-inspector.el index d4fe36307..dee954011 100644 --- a/cider-inspector.el +++ b/cider-inspector.el @@ -64,6 +64,15 @@ The max size can be also changed interactively within the inspector." :type '(integer :tag "Max collection size" 5) :package-version '(cider . "1.1.0")) +(defcustom cider-inspector-max-nested-depth 5 + "Default level of nesting for collections to display before truncating. +The max depth can be also changed interactively within the inspector." + :type '(integer :tag "Max nested collection depth" 5) + :package-version '(cider . "1.14.0")) + +(defvar cider-inspector-spacious-collections nil + "Controls whether the inspector renders values in collections spaciously.") + (defcustom cider-inspector-fill-frame nil "Controls whether the CIDER inspector window fills its frame." :type 'boolean @@ -114,6 +123,7 @@ by clicking or navigating to them by other means." (define-key map "s" #'cider-inspector-set-page-size) (define-key map "a" #'cider-inspector-set-max-atom-length) (define-key map "c" #'cider-inspector-set-max-coll-size) + (define-key map "C" #'cider-inspector-set-max-nested-depth) (define-key map "d" #'cider-inspector-def-current-val) (define-key map "t" #'cider-inspector-tap-current-val) (define-key map "1" #'cider-inspector-tap-at-point) @@ -219,12 +229,7 @@ current buffer's namespace." (interactive (list (cider-read-from-minibuffer "Inspect expression: " (cider-sexp-at-point)) (cider-current-ns))) (setq cider-inspector--current-repl (cider-current-repl)) - (let ((result (cider-sync-request:inspect-expr - expr ns - cider-inspector-page-size - cider-inspector-max-atom-length - cider-inspector-max-coll-size - 'v2))) + (let ((result (cider-sync-request:inspect-expr expr ns 'v2))) (when (nrepl-dict-get result "value") (cider-inspector--render-value result 'v2)))) @@ -340,6 +345,14 @@ MAX-SIZE is the new value." (when (nrepl-dict-get result "value") (cider-inspector--render-value result 'v2)))) +(defun cider-inspector-set-max-nested-depth (max-nested-depth) + "Set the level of nesting for collections to display beflore truncating. +MAX-NESTED-DEPTH is the new value." + (interactive (list (read-number "Max nested depth: " cider-inspector-max-nested-depth))) + (let ((result (cider-sync-request:inspect-set-max-nested-depth max-nested-depth 'v2))) + (when (nrepl-dict-get result "value") + (cider-inspector--render-value result 'v2)))) + (defcustom cider-inspector-preferred-var-names nil "The preferred var names to be suggested by `cider-inspector-def-current-val'. @@ -522,6 +535,17 @@ instead of just its \"value\" entry." result (nrepl-dict-get result "value")))) +(defun cider-sync-request:inspect-set-max-nested-depth (max-nested-depth &optional v2) + "Set the level of nesting for collections to display before truncating. +MAX-NESTED-DEPTH is the new value, V2 indicates if the entire response should be returned +instead of just its \"value\" entry." + (let ((result (thread-first `("op" "inspect-set-max-nested-depth" + "max-nested-depth" ,max-nested-depth) + (cider-nrepl-send-sync-request cider-inspector--current-repl)))) + (if v2 + result + (nrepl-dict-get result "value")))) + (defun cider-sync-request:inspect-def-current-val (ns var-name &optional v2) "Defines a var with VAR-NAME in NS with the current inspector value, V2 indicates if the entire response should be returned @@ -545,22 +569,27 @@ instead of just its \"value\" entry." "idx" ,idx) cider-inspector--current-repl)) -(defun cider-sync-request:inspect-expr (expr ns page-size max-atom-length max-coll-size &optional v2) +(defun cider-sync-request:inspect-expr (expr ns &optional v2) "Evaluate EXPR in context of NS and inspect its result. Set the page size in paginated view to PAGE-SIZE, maximum length of atomic collection members to MAX-ATOM-LENGTH, and maximum size of nested collections to MAX-COLL-SIZE if non nil, V2 indicates if the entire response should be returned instead of just its \"value\" entry." - (let ((result (thread-first (append (nrepl--eval-request expr ns) - `("inspect" "true" - ,@(when page-size - `("page-size" ,page-size)) - ,@(when max-atom-length - `("max-atom-length" ,max-atom-length)) - ,@(when max-coll-size - `("max-coll-size" ,max-coll-size)))) - (cider-nrepl-send-sync-request cider-inspector--current-repl)))) + (let ((result (thread-first + (append (nrepl--eval-request expr ns) + `("inspect" "true" + ,@(when cider-inspector-page-size + `("page-size" ,cider-inspector-page-size)) + ,@(when cider-inspector-max-atom-length + `("max-atom-length" ,cider-inspector-max-atom-length)) + ,@(when cider-inspector-max-coll-size + `("max-coll-size" ,cider-inspector-max-coll-size)) + ,@(when cider-inspector-max-nested-depth + `("max-nested-depth" ,cider-inspector-max-nested-depth)) + "spacious" ,(if cider-inspector-spacious-collections + "true" "false"))) + (cider-nrepl-send-sync-request cider-inspector--current-repl)))) (if v2 result (nrepl-dict-get result "value")))) From aa6f6816e557b633ca92ab3d5fa18a44d5fba26e Mon Sep 17 00:00:00 2001 From: Oleksandr Yakushev Date: Tue, 14 May 2024 10:37:16 +0300 Subject: [PATCH 2/3] Update docs --- doc/modules/ROOT/pages/debugging/inspector.adoc | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/doc/modules/ROOT/pages/debugging/inspector.adoc b/doc/modules/ROOT/pages/debugging/inspector.adoc index 6f4c4cd94..fc82481dc 100644 --- a/doc/modules/ROOT/pages/debugging/inspector.adoc +++ b/doc/modules/ROOT/pages/debugging/inspector.adoc @@ -68,6 +68,10 @@ You'll have access to additional keybindings in the inspector buffer | `cider-inspector-set-max-coll-size` | Set a new maximum size above which nested collections are truncated +| kbd:[C] +| `cider-inspector-set-max-nested-depth +| Set a new maximum nesting level above which the collections are truncated + | kbd:[a] | `cider-inspector-set-max-atom-length` | Set a new maximum length above which nested atoms (non-collections) are truncated @@ -118,9 +122,10 @@ can disable the auto selection with the variable `cider-inspector-auto-select-buffer`. You can set the amount of data shown by default with the variables -`cider-inspector-page-size`, `cider-inspector-max-coll-size`, and -`cider-inspector-max-atom-length`. The values can be adjusted for the current -inspector buffer using the `s`, `c`, and `a` keybindings. +`cider-inspector-page-size`, `cider-inspector-max-coll-size`, +`cider-inspector-max-nested-depth`, and `cider-inspector-max-atom-length`. The +values can be adjusted for the current inspector buffer using the keybidings +listed in the table above. If you enable `cider-inspector-fill-frame`, the inspector window fills its frame. From 5a0f08d0261562a5f34c7ae48b3add77b93cfb09 Mon Sep 17 00:00:00 2001 From: Oleksandr Yakushev Date: Tue, 14 May 2024 09:55:23 +0300 Subject: [PATCH 3/3] Update CHANGELOG --- CHANGELOG.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f30fe8eb..2398f8b1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,12 +19,18 @@ - [#3628](https://github.com/clojure-emacs/cider/issues/3628): `cider-ns-refresh`: summarize errors as an overlay. - [#3660](https://github.com/clojure-emacs/cider/issues/3660): Fix `cider-inspector-def-current-val` always defining in `user` namespace. - [#3661](https://github.com/clojure-emacs/cider/issues/3661): Truncate echo area output ahead of time. +- [#3664](https://github.com/clojure-emacs/cider/issues/3664): Add customization inspector op to change max nested collection depth. - Bump the injected `enrich-classpath` to [1.19.3](https://github.com/clojure-emacs/enrich-classpath/compare/v1.19.0...v1.19.3). - Bump the injected nREPL to [1.1.1](https://github.com/nrepl/nrepl/blob/v1.1.1/CHANGELOG.md#111-2024-02-20). - Bump the injected `cider-nrepl` to [0.48.0](https://github.com/clojure-emacs/cider-nrepl/blob/v0.48.0/CHANGELOG.md#0480-2024-05-13). - Updates [Orchard](https://github.com/clojure-emacs/orchard/blob/v0.23.2/CHANGELOG.md#0232-2024-03-10). +- Bump the injected `cider-nrepl` to [0.48.0](https://github.com/clojure-emacs/cider-nrepl/blob/master/CHANGELOG.md#0480-2024-05-13). + - Updates [clj-reload](https://github.com/tonsky/clj-reload/blob/0.6.0/CHANGELOG.md#060---may-3-2024). + - Updates [tools.reader](https://github.com/clojure/tools.reader/blob/master/CHANGELOG.md). + - Updates [nREPL](https://github.com/nrepl/nrepl/blob/master/CHANGELOG.md#111-2024-02-20). + - Updates [Orchard](https://github.com/clojure-emacs/orchard/blob/master/CHANGELOG.md#0250-2024-05-03). - Updates [Logjam](https://github.com/clojure-emacs/logjam/blob/v0.3.0/CHANGELOG.md#030-2024-03-03). - - Updates [Compliment](https://github.com/alexander-yakushev/compliment/blob/951604/CHANGELOG.md#master-unreleased). + - Updates [Compliment](https://github.com/alexander-yakushev/compliment/blob/master/CHANGELOG.md#055-2024-05-06). - [orchard#245](https://github.com/clojure-emacs/orchard/pull/245), [cider-nrepl#868](https://github.com/clojure-emacs/cider-nrepl/pull/868): Drop support for Clojure 1.9. ### Bugs fixed