alexmurray / flycheck-posframe

Show flycheck errors via posframe.el
60 stars 9 forks source link

Add an option to match `-posframe-border-face` to highest error level. #31

Closed DivvyCr closed 2 years ago

DivvyCr commented 2 years ago

I want the posframe border colour to reflect the severity of the error(s).

With my limited experience, I was thinking of adding the following function:

(defun flycheck-posframe-highest-error-level-face (errs)
  "Return the face corresponding to the highest error level from ERRS."
  (flycheck-posframe-get-face-for-error (cl-reduce
                     (lambda (err1 err2) (if (flycheck-error-level-< err1 err2) err2 err1))
                     errs)))

To apply for the border colour, based on the option flycheck-posframe-border-use-error-face:

(defun flycheck-posframe-show-posframe (errors)
  "Display ERRORS, using posframe.el library."
  (posframe-hide flycheck-posframe-buffer)
  (when (and errors
             (not (run-hook-with-args-until-success 'flycheck-posframe-inhibit-functions)))
    (let ((poshandler (intern (format "posframe-poshandler-%s" flycheck-posframe-position))))
      (unless (functionp poshandler)
        (setq poshandler nil))
      (flycheck-posframe-check-position)
      (posframe-show
       flycheck-posframe-buffer
       :string (flycheck-posframe-format-errors errors)
       :background-color (face-background 'flycheck-posframe-background-face nil t)
       :position (point)
       :internal-border-width flycheck-posframe-border-width
-      :internal-border-color (face-foreground 'flycheck-posframe-border-face nil t)
+      :internal-border-color (face-foreground (if flycheck-posframe-border-use-error-face
+                          (flycheck-posframe-highest-error-level-face errors)
+                        'flycheck-posframe-border-face) nil t)
       :poshandler poshandler
       :hidehandler #'flycheck-posframe-hidehandler))))

Examples from my local implementation:

alexmurray commented 2 years ago

Sure, please feel free to send a PR since it looks like you probably have most of the code to do this.

alexmurray commented 2 years ago

Pull #32 has been merged, closing this issue. Thanks again for this.