-
Notifications
You must be signed in to change notification settings - Fork 2
/
minitest-coverage.el
66 lines (59 loc) · 2.36 KB
/
minitest-coverage.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
(defface mtc-uncovered
'((t :background "#ffdddd"))
"Face for uncovered lines of code"
:group 'mtc)
(defface mtc-covered
'((t :background "#ddffdd" :inherit region))
"Face for covered lines of code"
:group 'mtc)
(defun mtc-overlay (coverage-path)
(let ((coverage (assoc (intern (buffer-file-name))
(json-read-file coverage-path))))
(when coverage
(let ((coverage (cdr coverage))
(line-pos
(save-excursion
(goto-char (point-min))
(mapcar (lambda (n) (cons (line-beginning-position n)
(line-end-position n)))
(number-sequence 1 (line-number-at-pos (point-max)))))))
(remove-overlays)
(mapcar* (lambda (cov range)
(when cov
(let ((start (car range))
(stop (cdr range))
(color (if (zerop cov) 'mtc-uncovered 'mtc-covered)))
(if nil
;; bad w/ font-lock
(with-silent-modifications
(put-text-property start stop 'font-lock-face color))
;; bad with highlighted region
(overlay-put (make-overlay start stop)
'face
;; (cons 'background-color color)
(list color)))
)))
coverage line-pos)))))
(defun mtc-find-project-file (file &optional dir)
(or dir (setq dir default-directory))
(let ((file-path (concat (file-name-as-directory dir) file)))
(if (file-exists-p file-path)
file-path
(if (equal dir "/")
nil
(mtc-find-project-file file
(directory-file-name (file-name-directory dir)))))))
(defun mtc-update ()
(interactive)
(let ((coverage-path (mtc-find-project-file "coverage.json")))
(when coverage-path
(mtc-clear)
(mtc-overlay coverage-path)
nil)))
(defun mtc-clear ()
(interactive)
(remove-overlays))
;; (with-current-buffer (window-buffer (next-window)) (mtc-update))
;; (with-current-buffer (window-buffer (next-window)) (mtc-clear))
;; (global-set-key (kbd "C-c u") 'mtc-update)
;; (global-set-key (kbd "C-c U") 'mtc-clear)