Skip to content

Commit 8c1cdbc

Browse files
[inspector] Add configuration for max-nested-depth and spacious
1 parent 8b2ef5f commit 8c1cdbc

File tree

1 file changed

+47
-16
lines changed

1 file changed

+47
-16
lines changed

cider-inspector.el

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,17 @@ 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+
(defcustom cider-inspector-spacious-collections nil
74+
"Controls whether the inspector renders values in collections spaciously."
75+
:type 'boolean
76+
:package-version '(cider . "1.2.0"))
77+
6778
(defcustom cider-inspector-fill-frame nil
6879
"Controls whether the CIDER inspector window fills its frame."
6980
:type 'boolean
@@ -114,6 +125,7 @@ by clicking or navigating to them by other means."
114125
(define-key map "s" #'cider-inspector-set-page-size)
115126
(define-key map "a" #'cider-inspector-set-max-atom-length)
116127
(define-key map "c" #'cider-inspector-set-max-coll-size)
128+
(define-key map "C" #'cider-inspector-set-max-nested-depth)
117129
(define-key map "d" #'cider-inspector-def-current-val)
118130
(define-key map "t" #'cider-inspector-tap-current-val)
119131
(define-key map "1" #'cider-inspector-tap-at-point)
@@ -219,12 +231,7 @@ current buffer's namespace."
219231
(interactive (list (cider-read-from-minibuffer "Inspect expression: " (cider-sexp-at-point))
220232
(cider-current-ns)))
221233
(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)))
234+
(let ((result (cider-sync-request:inspect-expr expr ns 'v2)))
228235
(when (nrepl-dict-get result "value")
229236
(cider-inspector--render-value result 'v2))))
230237

@@ -340,6 +347,14 @@ MAX-SIZE is the new value."
340347
(when (nrepl-dict-get result "value")
341348
(cider-inspector--render-value result 'v2))))
342349

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

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

548-
(defun cider-sync-request:inspect-expr (expr ns page-size max-atom-length max-coll-size &optional v2)
574+
(defun cider-sync-request:inspect-expr (expr ns &optional v2)
549575
"Evaluate EXPR in context of NS and inspect its result.
550576
Set the page size in paginated view to PAGE-SIZE, maximum length of atomic
551577
collection members to MAX-ATOM-LENGTH, and maximum size of nested collections to
552578
MAX-COLL-SIZE if non nil,
553579
V2 indicates if the entire response should be returned
554580
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))))
581+
(let ((result (thread-first
582+
(append (nrepl--eval-request expr ns)
583+
`("inspect" "true"
584+
,@(when cider-inspector-page-size
585+
`("page-size" ,cider-inspector-page-size))
586+
,@(when cider-inspector-max-atom-length
587+
`("max-atom-length" ,cider-inspector-max-atom-length))
588+
,@(when cider-inspector-max-coll-size
589+
`("max-coll-size" ,cider-inspector-max-coll-size))
590+
,@(when cider-inspector-max-nested-depth
591+
`("max-nested-depth" ,cider-inspector-max-nested-depth))
592+
"spacious" ,(if cider-inspector-spacious-collections
593+
"true" "false")))
594+
(cider-nrepl-send-sync-request cider-inspector--current-repl))))
564595
(if v2
565596
result
566597
(nrepl-dict-get result "value"))))

0 commit comments

Comments
 (0)