Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Make eglot use flycheck
(defvar-local flycheck-eglot-current-errors nil)
(defun flycheck-eglot-report-fn (diags &rest _)
(setq flycheck-eglot-current-errors
(mapcar (lambda (diag)
(goto-char (flymake--diag-beg diag))
(flycheck-error-new-at (line-number-at-pos)
(1+ (- (point) (line-beginning-position)))
(pcase (flymake--diag-type diag)
('eglot-error 'error)
('eglot-warning 'warning)
('eglot-note 'info)
(_ (error "Unknown diag type, %S" diag)))
(flymake--diag-text diag)
:checker 'eglot)))
(defun flycheck-eglot--start (checker callback)
(funcall callback 'finished flycheck-eglot-current-errors))
(defun flycheck-eglot--available-p ()
(bound-and-true-p eglot--managed-mode))
(flycheck-define-generic-checker 'eglot
"Report `eglot' diagnostics using `flycheck'."
:start #'flycheck-eglot--start
:predicate #'flycheck-eglot--available-p
:modes '(prog-mode text-mode))
(push 'eglot flycheck-checkers)
(defun sanityinc/eglot-prefer-flycheck ()
(when eglot--managed-mode
(flycheck-add-mode 'eglot major-mode)
(flycheck-select-checker 'eglot)
(flymake-mode -1)
(setq eglot--current-flymake-report-fn 'flycheck-eglot-report-fn)))
(add-hook 'eglot--managed-mode-hook 'sanityinc/eglot-prefer-flycheck)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment