Skip to content

Commit 478252a

Browse files
[inspector] Add configuration for max-nested-depth and spacious
1 parent 47e2902 commit 478252a

File tree

1 file changed

+45
-16
lines changed

1 file changed

+45
-16
lines changed

cider-inspector.el

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ The max size can be also changed interactively within the inspector."
6464
:type '(integer :tag "Max collection size" 5)
6565
:package-version '(cider . "1.1.0"))
6666

67+
(defcustom cider-inspector-max-nested-depth 5
68+
"Default level of nesting for collections to display before truncating.
69+
The max depth can be also changed interactively within the inspector."
70+
:type '(integer :tag "Max nested collection depth" 5)
71+
:package-version '(cider . "1.2.0"))
72+
73+
(defvar cider-inspector-spacious-collections nil
74+
"Controls whether the inspector renders values in collections spaciously.")
75+
6776
(defcustom cider-inspector-fill-frame nil
6877
"Controls whether the CIDER inspector window fills its frame."
6978
:type 'boolean
@@ -114,6 +123,7 @@ by clicking or navigating to them by other means."
114123
(define-key map "s" #'cider-inspector-set-page-size)
115124
(define-key map "a" #'cider-inspector-set-max-atom-length)
116125
(define-key map "c" #'cider-inspector-set-max-coll-size)
126+
(define-key map "C" #'cider-inspector-set-max-nested-depth)
117127
(define-key map "d" #'cider-inspector-def-current-val)
118128
(define-key map "t" #'cider-inspector-tap-current-val)
119129
(define-key map "1" #'cider-inspector-tap-at-point)
@@ -219,12 +229,7 @@ current buffer's namespace."
219229
(interactive (list (cider-read-from-minibuffer "Inspect expression: " (cider-sexp-at-point))
220230
(cider-current-ns)))
221231
(setq cider-inspector--current-repl (cider-current-repl))
222-
(let ((result (cider-sync-request:inspect-expr
223-
expr ns
224-
cider-inspector-page-size
225-
cider-inspector-max-atom-length
226-
cider-inspector-max-coll-size
227-
'v2)))
232+
(let ((result (cider-sync-request:inspect-expr expr ns 'v2)))
228233
(when (nrepl-dict-get result "value")
229234
(cider-inspector--render-value result 'v2))))
230235

@@ -340,6 +345,14 @@ MAX-SIZE is the new value."
340345
(when (nrepl-dict-get result "value")
341346
(cider-inspector--render-value result 'v2))))
342347

348+
(defun cider-inspector-set-max-nested-depth (max-nested-depth)
349+
"Set the level of nesting for collections to display beflore truncating.
350+
MAX-NESTED-DEPTH is the new value."
351+
(interactive (list (read-number "Max nested depth: " cider-inspector-max-nested-depth)))
352+
(let ((result (cider-sync-request:inspect-set-max-nested-depth max-nested-depth 'v2)))
353+
(when (nrepl-dict-get result "value")
354+
(cider-inspector--render-value result 'v2))))
355+
343356
(defcustom cider-inspector-preferred-var-names nil
344357
"The preferred var names to be suggested by `cider-inspector-def-current-val'.
345358
@@ -522,6 +535,17 @@ instead of just its \"value\" entry."
522535
result
523536
(nrepl-dict-get result "value"))))
524537

538+
(defun cider-sync-request:inspect-set-max-nested-depth (max-nested-depth &optional v2)
539+
"Set the level of nesting for collections to display before truncating.
540+
MAX-NESTED-DEPTH is the new value, V2 indicates if the entire response should be returned
541+
instead of just its \"value\" entry."
542+
(let ((result (thread-first `("op" "inspect-set-max-nested-depth"
543+
"max-nested-depth" ,max-nested-depth)
544+
(cider-nrepl-send-sync-request cider-inspector--current-repl))))
545+
(if v2
546+
result
547+
(nrepl-dict-get result "value"))))
548+
525549
(defun cider-sync-request:inspect-def-current-val (ns var-name &optional v2)
526550
"Defines a var with VAR-NAME in NS with the current inspector value,
527551
V2 indicates if the entire response should be returned
@@ -545,22 +569,27 @@ instead of just its \"value\" entry."
545569
"idx" ,idx)
546570
cider-inspector--current-repl))
547571

548-
(defun cider-sync-request:inspect-expr (expr ns page-size max-atom-length max-coll-size &optional v2)
572+
(defun cider-sync-request:inspect-expr (expr ns &optional v2)
549573
"Evaluate EXPR in context of NS and inspect its result.
550574
Set the page size in paginated view to PAGE-SIZE, maximum length of atomic
551575
collection members to MAX-ATOM-LENGTH, and maximum size of nested collections to
552576
MAX-COLL-SIZE if non nil,
553577
V2 indicates if the entire response should be returned
554578
instead of just its \"value\" entry."
555-
(let ((result (thread-first (append (nrepl--eval-request expr ns)
556-
`("inspect" "true"
557-
,@(when page-size
558-
`("page-size" ,page-size))
559-
,@(when max-atom-length
560-
`("max-atom-length" ,max-atom-length))
561-
,@(when max-coll-size
562-
`("max-coll-size" ,max-coll-size))))
563-
(cider-nrepl-send-sync-request cider-inspector--current-repl))))
579+
(let ((result (thread-first
580+
(append (nrepl--eval-request expr ns)
581+
`("inspect" "true"
582+
,@(when cider-inspector-page-size
583+
`("page-size" ,cider-inspector-page-size))
584+
,@(when cider-inspector-max-atom-length
585+
`("max-atom-length" ,cider-inspector-max-atom-length))
586+
,@(when cider-inspector-max-coll-size
587+
`("max-coll-size" ,cider-inspector-max-coll-size))
588+
,@(when cider-inspector-max-nested-depth
589+
`("max-nested-depth" ,cider-inspector-max-nested-depth))
590+
"spacious" ,(if cider-inspector-spacious-collections
591+
"true" "false")))
592+
(cider-nrepl-send-sync-request cider-inspector--current-repl))))
564593
(if v2
565594
result
566595
(nrepl-dict-get result "value"))))

0 commit comments

Comments
 (0)