Function: consult-flymake--candidates

consult-flymake--candidates is a byte-compiled function defined in consult-flymake.el.

Signature

(consult-flymake--candidates DIAGS)

Documentation

Return Flymake errors from DIAGS as formatted candidates.

DIAGS should be a list of diagnostics as returned from flymake-diagnostics.

Source Code

;; Defined in ~/.emacs.d/elpa/consult-20261004.957/consult-flymake.el
(defun consult-flymake--candidates (diags)
  "Return Flymake errors from DIAGS as formatted candidates.
DIAGS should be a list of diagnostics as returned from `flymake-diagnostics'."
  (let* ((diags
          (mapcar
           (lambda (diag)
             (let ((buffer (flymake-diagnostic-buffer diag))
                   (type (flymake-diagnostic-type diag)))
               (when (buffer-live-p buffer)
                 (with-current-buffer buffer
                   (save-excursion
                     (without-restriction
                       (goto-char (flymake-diagnostic-beg diag))
                       (list (buffer-name buffer)
                             (line-number-at-pos)
                             type
                             (flymake-diagnostic-text diag)
                             (point-marker)
                             (flymake-diagnostic-end diag)
                             (pcase (flymake--lookup-type-property type 'flymake-category)
                               ('flymake-error ?e)
                               ('flymake-warning ?w)
                               (_ ?n)))))))))
           diags))
         (diags (or (delq nil diags)
                    (user-error "No flymake errors (Status: %s)"
                                (if (seq-difference (flymake-running-backends)
                                                    (flymake-reporting-backends))
                                    'running 'finished))))
         (buffer-width (cl-loop for x in diags maximize (length (nth 0 x))))
         (line-width (cl-loop for x in diags maximize (length (number-to-string (nth 1 x)))))
         (fmt (format "%%-%ds %%-%dd %%-7s %%s" buffer-width line-width)))
    (mapcar
     (pcase-lambda (`(,buffer ,line ,type ,text ,beg ,end ,narrow))
       (propertize (format fmt buffer line
                           (propertize (format "%s" (flymake--lookup-type-property
                                                     type 'flymake-type-name type))
                                       'face (flymake--lookup-type-property
                                              type 'mode-line-face 'flymake-error))
                           text)
                   'consult--candidate (list beg (cons 0 (- end beg)))
                   'consult--type narrow))
     ;; Sort by buffer, severity and position.
     (sort diags
           (pcase-lambda (`(,b1 _ ,t1 _ ,m1 _) `(,b2 _ ,t2 _ ,m2 _))
             (let ((s1 (flymake--severity t1))
                   (s2 (flymake--severity t2)))
               (or
                (string-lessp b1 b2)
                (and (string-equal b1 b2)
                     (or
                      (> s1 s2)
                      (and (= s1 s2)
                           (< m1 m2)))))))))))