Count flymake diagnostics by severity (#163)

Count flymake diagnostics by severity
This commit is contained in:
Vincent Zhang 2019-04-26 11:10:26 -05:00 committed by GitHub
commit 5f028129be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -128,6 +128,7 @@
(declare-function flymake--backend-state-diags 'flymake) (declare-function flymake--backend-state-diags 'flymake)
(declare-function flymake--diag-type 'flymake) (declare-function flymake--diag-type 'flymake)
(declare-function flymake--handle-report 'flymake) (declare-function flymake--handle-report 'flymake)
(declare-function flymake--severity 'flymake)
(declare-function flymake-disabled-backends 'flymake) (declare-function flymake-disabled-backends 'flymake)
(declare-function flymake-goto-next-error 'flymake) (declare-function flymake-goto-next-error 'flymake)
(declare-function flymake-goto-prev-error 'flymake) (declare-function flymake-goto-prev-error 'flymake)
@ -170,6 +171,7 @@
(declare-function tracking-shorten 'tracking) (declare-function tracking-shorten 'tracking)
(declare-function undo-tree-redo-1 'undo-tree) (declare-function undo-tree-redo-1 'undo-tree)
(declare-function undo-tree-undo-1 'undo-tree) (declare-function undo-tree-undo-1 'undo-tree)
(declare-function warning-numeric-level 'warnings)
(declare-function window-numbering-clear-mode-line 'window-numbering) (declare-function window-numbering-clear-mode-line 'window-numbering)
(declare-function window-numbering-get-number-string 'window-numbering) (declare-function window-numbering-get-number-string 'window-numbering)
(declare-function window-numbering-install-mode-line 'window-numbering) (declare-function window-numbering-install-mode-line 'window-numbering)
@ -759,31 +761,35 @@ wheel-up/wheel-down: Previous/next error"))
(running (flymake-running-backends)) (running (flymake-running-backends))
(disabled (flymake-disabled-backends)) (disabled (flymake-disabled-backends))
(reported (flymake-reporting-backends)) (reported (flymake-reporting-backends))
(diags-by-type (make-hash-table))
(all-disabled (and disabled (null running))) (all-disabled (and disabled (null running)))
(some-waiting (cl-set-difference running reported))) (some-waiting (cl-set-difference running reported)))
(maphash (lambda (_b state)
(mapc (lambda (diag)
(push diag
(gethash (flymake--diag-type diag)
diags-by-type)))
(flymake--backend-state-diags state)))
flymake--backend-state)
(when-let (when-let
((icon ((icon
(cond (cond
(some-waiting (doom-modeline-checker-icon "access_time" "*" 'doom-modeline-debug)) (some-waiting (doom-modeline-checker-icon "access_time" "*" 'doom-modeline-debug))
((null known) (doom-modeline-checker-icon "sim_card_alert" "?" 'doom-modeline-debug)) ((null known) (doom-modeline-checker-icon "sim_card_alert" "?" 'doom-modeline-debug))
(all-disabled (doom-modeline-checker-icon "sim_card_alert" "!" 'doom-modeline-urgent)) (all-disabled (doom-modeline-checker-icon "sim_card_alert" "!" 'doom-modeline-urgent))
(t (let ((.error (length (gethash :error diags-by-type))) (t (let ((.error 0)
(.warning (length (gethash :warning diags-by-type))) (.warning 0)
(.note (length (gethash :note diags-by-type)))) (.note 0))
(progn
(cl-loop
with warning-level = (warning-numeric-level :warning)
with note-level = (warning-numeric-level :debug)
for state being the hash-values of flymake--backend-state
do (cl-loop
with diags = (flymake--backend-state-diags state)
for diag in diags do
(let ((severity (flymake--severity (flymake--diag-type diag))))
(cond ((> severity warning-level) (cl-incf .error))
((> severity note-level) (cl-incf .warning))
(t (cl-incf .note))))))
(if (> (+ .error .warning .note) 0) (if (> (+ .error .warning .note) 0)
(doom-modeline-checker-icon "do_not_disturb_alt" "!" (doom-modeline-checker-icon "do_not_disturb_alt" "!"
(cond ((> .error 0) 'doom-modeline-urgent) (cond ((> .error 0) 'doom-modeline-urgent)
((> .warning 0) 'doom-modeline-warning) ((> .warning 0) 'doom-modeline-warning)
(t 'doom-modeline-info))) (t 'doom-modeline-info)))
(doom-modeline-checker-icon "check" "-" 'doom-modeline-info))))))) (doom-modeline-checker-icon "check" "-" 'doom-modeline-info))))))))
(propertize (propertize
icon icon
'help-echo (concat "Flymake\n" 'help-echo (concat "Flymake\n"
@ -826,19 +832,22 @@ mouse-2: Show help for minor mode"
(running (flymake-running-backends)) (running (flymake-running-backends))
(disabled (flymake-disabled-backends)) (disabled (flymake-disabled-backends))
(reported (flymake-reporting-backends)) (reported (flymake-reporting-backends))
(diags-by-type (make-hash-table))
(all-disabled (and disabled (null running))) (all-disabled (and disabled (null running)))
(some-waiting (cl-set-difference running reported))) (some-waiting (cl-set-difference running reported))
(warning-level (warning-numeric-level :warning))
(note-level (warning-numeric-level :debug))
(.error 0)
(.warning 0)
(.note 0))
(maphash (lambda (_b state) (maphash (lambda (_b state)
(mapc (lambda (diag) (cl-loop
(push diag with diags = (flymake--backend-state-diags state)
(gethash (flymake--diag-type diag) for diag in diags do
diags-by-type))) (let ((severity (flymake--severity (flymake--diag-type diag))))
(flymake--backend-state-diags state))) (cond ((> severity warning-level) (cl-incf .error))
((> severity note-level) (cl-incf .warning))
(t (cl-incf .note))))))
flymake--backend-state) flymake--backend-state)
(let ((.error (length (gethash :error diags-by-type)))
(.warning (length (gethash :warning diags-by-type)))
(.note (length (gethash :note diags-by-type))))
(when-let (when-let
((text ((text
(cond (cond
@ -885,7 +894,7 @@ wheel-up/wheel-down: Previous/next problem"
(interactive "e") (interactive "e")
(with-selected-window (posn-window (event-start event)) (with-selected-window (posn-window (event-start event))
(flymake-goto-next-error 1 nil t)))) (flymake-goto-next-error 1 nil t))))
map))))))) map))))))
(advice-add #'flymake--handle-report :after #'doom-modeline-update-flymake-text) (advice-add #'flymake--handle-report :after #'doom-modeline-update-flymake-text)
(doom-modeline-def-segment checker (doom-modeline-def-segment checker