Skip to content

Commit 16e2a72

Browse files
Dan Suttonbbatsov
authored andcommitted
Introduce positive filters for stackframes
when filtering stackframes, there was only a "remove" type of filter. If we wish to filter to just our project, we need a way to ensure that project frames persist even if another tag says to remove it. This adds the "positive" filter mechanics.
1 parent 644b37c commit 16e2a72

File tree

2 files changed

+45
-11
lines changed

2 files changed

+45
-11
lines changed

cider-stacktrace.el

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ cyclical data structures."
9191
(defvar-local cider-stacktrace-filters nil)
9292
(defvar-local cider-stacktrace-prior-filters nil)
9393
(defvar-local cider-stacktrace-cause-visibility nil)
94+
(defvar-local cider-stacktrace-positive-filters nil)
9495

9596
(defconst cider-error-buffer "*cider-error*")
9697
(add-to-list 'cider-ancillary-buffers cider-error-buffer)
@@ -274,16 +275,31 @@ searching and update the hidden count text."
274275
(number-to-string cider-stacktrace-hidden-frame-count)))))))
275276

276277
(defun cider-stacktrace-frame-p ()
278+
"Indicate if the text at point is a stack frame."
277279
(get-text-property (point) 'cider-stacktrace-frame))
278280

279281
(defun cider-stacktrace-collapsed-p ()
282+
"Indicate if the stackframe was collapsed."
280283
(get-text-property (point) 'collapsed))
281284

282-
(defun cider-stacktrace-apply-filters (filters)
283-
"Set visibility on stack frames using FILTERS.
285+
(defun cider-stacktrace--should-hide-p (neg-filters pos-filters flags)
286+
"Decide whether a stackframe should be hidden or not.
287+
NEG-FILTERS dictate which frames should be hidden while POS-FILTERS can
288+
override this and ensure that those frames are shown.
289+
Argument FLAGS are the flags set on the stackframe, ie: clj dup, etc."
290+
(let ((neg (seq-intersection neg-filters flags))
291+
(pos (seq-intersection pos-filters flags)))
292+
(cond ((and pos neg) nil)
293+
(pos nil)
294+
(neg t)
295+
(t nil))))
296+
297+
(defun cider-stacktrace-apply-filters (neg-filters pos-filters)
298+
"Set visibility on stack frames.
284299
Update `cider-stacktrace-hidden-frame-count' and indicate filters applied.
285300
Currently collapsed stacktraces are ignored, and do not contribute to the
286-
hidden count."
301+
hidden count. NEG-FILTERS remove frames with the flag in that list and
302+
POS-FILTERS ensure that frames with flag is shown."
287303
(with-current-buffer cider-error-buffer
288304
(save-excursion
289305
(goto-char (point-min))
@@ -293,13 +309,15 @@ hidden count."
293309
(when (and (cider-stacktrace-frame-p)
294310
(not (cider-stacktrace-collapsed-p)))
295311
(let* ((flags (get-text-property (point) 'flags))
296-
(hide (if (seq-intersection filters flags) t nil)))
312+
(hide (cider-stacktrace--should-hide-p neg-filters
313+
pos-filters
314+
flags)))
297315
(when hide (cl-incf hidden))
298316
(put-text-property (point) (line-beginning-position 2)
299317
'invisible hide)))
300318
(forward-line 1))
301319
(setq cider-stacktrace-hidden-frame-count hidden)))
302-
(cider-stacktrace-indicate-filters filters)))
320+
(cider-stacktrace-indicate-filters neg-filters pos-filters)))
303321

304322

305323
(defun cider-stacktrace-apply-cause-visibility ()
@@ -325,8 +343,8 @@ hidden count."
325343
(add-text-properties (point) detail-end
326344
(list 'invisible hide
327345
'collapsed hide))))))))
328-
(cider-stacktrace-apply-filters
329-
cider-stacktrace-filters))))
346+
(cider-stacktrace-apply-filters cider-stacktrace-filters
347+
cider-stacktrace-positive-filters))))
330348

331349
;;; Internal/Middleware error suppression
332350

@@ -435,15 +453,18 @@ When it reaches 3, it wraps to 0."
435453
(cider-stacktrace-apply-filters
436454
(setq cider-stacktrace-filters
437455
(unless cider-stacktrace-filters ; when current filters are nil,
438-
cider-stacktrace-prior-filters)))) ; reenable prior filter set
456+
cider-stacktrace-prior-filters)) ; reenable prior filter set
457+
cider-stacktrace-positive-filters))
439458

440459
(defun cider-stacktrace-toggle (flag)
441460
"Update `cider-stacktrace-filters' to add or remove FLAG, and apply filters."
442461
(cider-stacktrace-apply-filters
443462
(setq cider-stacktrace-filters
444463
(if (memq flag cider-stacktrace-filters)
445464
(remq flag cider-stacktrace-filters)
446-
(cons flag cider-stacktrace-filters)))))
465+
(cons flag cider-stacktrace-filters)))
466+
cider-stacktrace-positive-filters))
467+
447468

448469
(defun cider-stacktrace-toggle-java ()
449470
"Toggle display of Java stack frames."

test/cider-stacktrace-tests.el

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,12 @@
8787
(defun cider--testing-dict (names &optional stipulated)
8888
(let ((numeric? (lambda (sym) (member sym '(line column)))))
8989
(apply #'nrepl-dict
90-
(append (mapcan (lambda (name) (list (symbol-name name)
90+
(append (apply #'append
91+
(mapcar (lambda (name) (list (symbol-name name)
9192
(if (funcall numeric? name)
9293
4
9394
(symbol-name name))))
94-
names)
95+
names))
9596
stipulated))))
9697

9798
(defun cider--frame-of-type (flags)
@@ -114,3 +115,15 @@
114115
(cider--testing-dict '(file path column line)))
115116
(goto-char (point-min))
116117
(expect (cider-stacktrace-frame-p) :to-be nil))))
118+
119+
(describe "cider-stacktrace--should-hide-p-tests"
120+
(it "should hide when members of the neg filters"
121+
(let ((hidden1 (cider-stacktrace--should-hide-p '(a b c) '() '(a)))
122+
(hidden2 (cider-stacktrace--should-hide-p '(a) '(b) '(a)))
123+
(both (cider-stacktrace--should-hide-p '(a) '(a) '(a)))
124+
(shown1 (cider-stacktrace--should-hide-p '(a) '(b) '(b)))
125+
(shown2 (cider-stacktrace--should-hide-p '() '(a) '(a))))
126+
(expect (and hidden1 hidden2)
127+
:to-be-truthy)
128+
(expect (or both shown1 shown2)
129+
:to-be nil))))

0 commit comments

Comments
 (0)