Skip to content

[inspector] Add configuration for max-nested-depth and spacious #3664

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 17, 2024
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
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
61 changes: 45 additions & 16 deletions cider-inspector.el
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe explain a bit more what "spaciously" means in this context. If I didn't know what this controls I'd have a hard time figuring it out.

Btw, why did you decide to make this a defvar instead of defcusom? I doubt anyone was particularly attached to the extra spaces, but defcustoms are easier to discover.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw your other comment, forget about this.


(defcustom cider-inspector-fill-frame nil
"Controls whether the CIDER inspector window fills its frame."
:type 'boolean
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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))))

Expand Down Expand Up @@ -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'.

Expand Down Expand Up @@ -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
Expand All @@ -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"))))
Expand Down
11 changes: 8 additions & 3 deletions doc/modules/ROOT/pages/debugging/inspector.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'd better to pick some free lowercase letter for this. (e.g. d)

Copy link
Member Author

@alexander-yakushev alexander-yakushev May 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I chose a capital letter intentionally to not take away a letter from the binding space. I don't consider this customization to be used often or ever. We'll probably change the default some time down the road I expect this variable will be changed dynamically in some unique cases, but otherwise, it's a meh variable to customize.

Copy link
Member Author

@alexander-yakushev alexander-yakushev May 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides, there is certain synergy in changing length (*print-length*) and depth (*print-depth*), so they can be neighbours on the same letter, even if the letter itself does not relate to depth much.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough.

| `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
Expand Down Expand Up @@ -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.
Expand Down