Use flycheck on eglot.

This commit is contained in:
kj 2022-11-19 14:25:30 -04:00
parent a7c0b5de66
commit 017566a9dd

View File

@ -14,6 +14,50 @@
(html-mode . eglot-ensure))
:config
(add-to-list 'eglot-server-programs '(php-mode . ("intelephense" "--stdio")))
(defvar-local flycheck-eglot-current-errors nil)
;; Use flycheck (https://gist.github.com/purcell/ca33abbea9a98bb0f8a04d790a0cadcd)
(defun flycheck-eglot-report-fn (diags &rest _)
(setq flycheck-eglot-current-errors
(mapcar (lambda (diag)
(save-excursion
(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)))
diags))
(flycheck-buffer))
(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)
(flycheck-mode)
(flymake-mode -1)
(setq eglot--current-flymake-report-fn 'flycheck-eglot-report-fn)))
(add-hook 'eglot--managed-mode-hook 'sanityinc/eglot-prefer-flycheck)
)
;; Emmet (mientras veo como hacer funcionar emmet-ls)