Skip to content

Commit 644b37c

Browse files
Dan Suttonbbatsov
authored andcommitted
Show only or hide when on stackframe lines
In order to add "positive" filters, we must only show or hide when we're actually on a stackframe line. This method takes a very naive way of starting at the top of the buffer and considering whether to hide all lines. The other lines just don't have any 'flags properties so they never come up as needing to be hidden in the `(seq-intersection filters flags)` part, so hide is always false on them. But if we want to show _only_ those lines with a particular flag this hides the cause line and any other lines that don't have flags at all.
1 parent cb4ed93 commit 644b37c

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

cider-stacktrace.el

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,12 @@ searching and update the hidden count text."
273273
(replace-match
274274
(number-to-string cider-stacktrace-hidden-frame-count)))))))
275275

276+
(defun cider-stacktrace-frame-p ()
277+
(get-text-property (point) 'cider-stacktrace-frame))
278+
279+
(defun cider-stacktrace-collapsed-p ()
280+
(get-text-property (point) 'collapsed))
281+
276282
(defun cider-stacktrace-apply-filters (filters)
277283
"Set visibility on stack frames using FILTERS.
278284
Update `cider-stacktrace-hidden-frame-count' and indicate filters applied.
@@ -284,11 +290,13 @@ hidden count."
284290
(let ((inhibit-read-only t)
285291
(hidden 0))
286292
(while (not (eobp))
287-
(unless (get-text-property (point) 'collapsed)
293+
(when (and (cider-stacktrace-frame-p)
294+
(not (cider-stacktrace-collapsed-p)))
288295
(let* ((flags (get-text-property (point) 'flags))
289296
(hide (if (seq-intersection filters flags) t nil)))
290297
(when hide (cl-incf hidden))
291-
(put-text-property (point) (line-beginning-position 2) 'invisible hide)))
298+
(put-text-property (point) (line-beginning-position 2)
299+
'invisible hide)))
292300
(forward-line 1))
293301
(setq cider-stacktrace-hidden-frame-count hidden)))
294302
(cider-stacktrace-indicate-filters filters)))
@@ -606,7 +614,9 @@ This associates text properties to enable filtering and source navigation."
606614
(p2 (search-forward "/"))
607615
(p3 (search-forward-regexp "[^/$]+")))
608616
(put-text-property p1 p4 'font-lock-face 'cider-stacktrace-ns-face)
609-
(put-text-property p2 p3 'font-lock-face 'cider-stacktrace-fn-face)))
617+
(put-text-property p2 p3 'font-lock-face 'cider-stacktrace-fn-face)
618+
(put-text-property (line-beginning-position) (line-end-position)
619+
'cider-stacktrace-frame t)))
610620
(insert "\n")))))
611621

612622
(declare-function cider-jump-to "cider-interaction")
@@ -717,6 +727,7 @@ through the `cider-stacktrace-suppressed-errors' variable."
717727
(cider-stacktrace-initialize causes)
718728
(font-lock-refresh-defaults)))
719729

730+
720731
(provide 'cider-stacktrace)
721732

722733
;;; cider-stacktrace.el ends here

test/cider-stacktrace-tests.el

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,34 @@
8383
(cider-stacktrace-promote-error "x")
8484
:test 'equal)
8585
:not :to-be-truthy)))
86+
87+
(defun cider--testing-dict (names &optional stipulated)
88+
(let ((numeric? (lambda (sym) (member sym '(line column)))))
89+
(apply #'nrepl-dict
90+
(append (mapcan (lambda (name) (list (symbol-name name)
91+
(if (funcall numeric? name)
92+
4
93+
(symbol-name name))))
94+
names)
95+
stipulated))))
96+
97+
(defun cider--frame-of-type (flags)
98+
(cider--testing-dict '(file class method name var ns fn line column path)
99+
(list "flags" (mapcar #'symbol-name flags))))
100+
101+
(describe "cider-stacktrace-frame-p-tests"
102+
(it "returns true on frames"
103+
(with-temp-buffer
104+
;; a stackframe
105+
(cider-stacktrace-render-frame (current-buffer)
106+
(cider--frame-of-type '(clj)))
107+
(goto-char (point-min))
108+
(expect (cider-stacktrace-frame-p) :to-be-truthy)))
109+
110+
(it "returns false otherwise"
111+
(with-temp-buffer
112+
;; not a stackframe but a compile error
113+
(cider-stacktrace-render-compile-error (current-buffer)
114+
(cider--testing-dict '(file path column line)))
115+
(goto-char (point-min))
116+
(expect (cider-stacktrace-frame-p) :to-be nil))))

0 commit comments

Comments
 (0)