From 6f5fc2900f0f698915b0d13fd6c91dfa0e187180 Mon Sep 17 00:00:00 2001 From: qcfu Date: Fri, 3 Mar 2023 00:22:17 -0500 Subject: [PATCH] support for eglot generated flymake diagnostics --- mood-line.el | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/mood-line.el b/mood-line.el index cc19d64..13866a3 100644 --- a/mood-line.el +++ b/mood-line.el @@ -54,6 +54,7 @@ ;; ---------------------------------- ;; (eval-when-compile + (require 'cl-lib) (require 'flymake)) ;; ---------------------------------- ;; @@ -571,14 +572,6 @@ Counts will be returned in an alist as the `cdr' of the following keys: (defvar-local mood-line--checker-flymake-text nil) -(defun mood-line--checker-flymake-count-report-type (type) - "Return count of current flymake reports of TYPE." - (let ((count 0)) - (dolist (d (flymake-diagnostics)) - (when (eq (cl-struct-slot-value 'flymake--diag 'type d) type) - (cl-incf count))) - count)) - (defun mood-line--checker-flymake-count-errors () "Return alist with count of all current flymake diagnostic reports. @@ -588,9 +581,22 @@ Counts will be returned in an alist as the cdr of the following keys: `'warning-count' | All warnings reported by checkero `'issue-count' | All errors and warnings reported by checker `'all-count' | Everything reported by checker" - (let ((note-count (mood-line--checker-flymake-count-report-type :note)) - (error-count (mood-line--checker-flymake-count-report-type :error)) - (warning-count (mood-line--checker-flymake-count-report-type :warning))) + (let ((error-count 0) + (warning-count 0) + (note-count 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--state + do (cl-loop + with diags = (flymake--state-diags state) + for diag in diags do + (let ((severity (flymake--lookup-type-property (flymake--diag-type diag) 'severity + (warning-numeric-level :error)))) + (cond ((> severity warning-level) (cl-incf error-count)) + ((> severity note-level) (cl-incf warning-count)) + (t (cl-incf note-count))))))) `((note-count . ,note-count) (error-count . ,error-count) (warning-count . ,warning-count)