refactor(lsp): switch to flycheck-eglot package
We no longer need to maintain our own juryrigged version of this functionality.
This commit is contained in:
parent
83a53259fe
commit
25611707ed
3 changed files with 8 additions and 81 deletions
|
@ -25,10 +25,6 @@
|
||||||
|
|
||||||
(add-to-list 'doom-debug-variables '(eglot-events-buffer-size . 0))
|
(add-to-list 'doom-debug-variables '(eglot-events-buffer-size . 0))
|
||||||
|
|
||||||
(when (modulep! :checkers syntax)
|
|
||||||
(after! flycheck
|
|
||||||
(load! "autoload/flycheck-eglot")))
|
|
||||||
|
|
||||||
(defadvice! +lsp--defer-server-shutdown-a (fn &optional server)
|
(defadvice! +lsp--defer-server-shutdown-a (fn &optional server)
|
||||||
"Defer server shutdown for a few seconds.
|
"Defer server shutdown for a few seconds.
|
||||||
This gives the user a chance to open other project files before the server is
|
This gives the user a chance to open other project files before the server is
|
||||||
|
@ -55,3 +51,8 @@ server getting expensively restarted when reverting buffers."
|
||||||
:when (modulep! :completion vertico)
|
:when (modulep! :completion vertico)
|
||||||
:init
|
:init
|
||||||
(map! :map eglot-mode-map [remap xref-find-apropos] #'consult-eglot-symbols))
|
(map! :map eglot-mode-map [remap xref-find-apropos] #'consult-eglot-symbols))
|
||||||
|
|
||||||
|
|
||||||
|
(use-package! flycheck-eglot
|
||||||
|
:when (modulep! :checkers syntax)
|
||||||
|
:hook (eglot-managed-mode . flycheck-eglot-mode))
|
||||||
|
|
|
@ -1,76 +0,0 @@
|
||||||
;;; flycheck-eglot --- Hacky eglot support in flycheck -*- lexical-binding: t; -*-
|
|
||||||
;;; Commentary:
|
|
||||||
;; This file sets up flycheck so that, when eglot receives a publishDiagnostics method
|
|
||||||
;; from the server, flycheck updates the reports.
|
|
||||||
;;
|
|
||||||
;; Thanks to:
|
|
||||||
;; - joaotavora for adding a handle to plug flycheck, and
|
|
||||||
;; - purcell for finding out the initial stub and the current implementation
|
|
||||||
;;
|
|
||||||
;; It works by creating a bridge function which can be used as the argument of
|
|
||||||
;; `eglot-flymake-backend', which both consumes diagnostics and queue a call to
|
|
||||||
;; 'flycheck-buffer'
|
|
||||||
;;
|
|
||||||
;;; Code:
|
|
||||||
|
|
||||||
(defvar-local +lsp--flycheck-eglot--current-errors nil)
|
|
||||||
|
|
||||||
(defun +lsp--flycheck-eglot-init (checker callback)
|
|
||||||
"CHECKER is the checker (eglot).
|
|
||||||
CALLBACK is the function that we need to call when we are done, on all the errors."
|
|
||||||
(eglot-flymake-backend #'+lsp--flycheck-eglot--on-diagnostics)
|
|
||||||
(funcall callback 'finished +lsp--flycheck-eglot--current-errors))
|
|
||||||
|
|
||||||
(defun +lsp--flycheck-eglot--on-diagnostics (diags &rest _)
|
|
||||||
(cl-labels
|
|
||||||
((flymake-diag->flycheck-err
|
|
||||||
(diag)
|
|
||||||
(with-current-buffer (flymake--diag-buffer diag)
|
|
||||||
(flycheck-error-new-at-pos
|
|
||||||
(flymake--diag-beg diag)
|
|
||||||
(pcase (flymake--diag-type diag)
|
|
||||||
('eglot-note 'info)
|
|
||||||
('eglot-warning 'warning)
|
|
||||||
('eglot-error 'error)
|
|
||||||
(_ (error "Unknown diagnostic type, %S" diag)))
|
|
||||||
(flymake--diag-text diag)
|
|
||||||
:end-pos (flymake--diag-end diag)
|
|
||||||
:checker 'eglot
|
|
||||||
:buffer (current-buffer)
|
|
||||||
:filename (buffer-file-name)))))
|
|
||||||
(setq +lsp--flycheck-eglot--current-errors
|
|
||||||
(mapcar #'flymake-diag->flycheck-err diags))
|
|
||||||
;; Call Flycheck to update the diagnostics annotations
|
|
||||||
(flycheck-buffer-deferred)))
|
|
||||||
|
|
||||||
(defun +lsp--flycheck-eglot-available-p ()
|
|
||||||
(bound-and-true-p eglot--managed-mode))
|
|
||||||
|
|
||||||
(flycheck-define-generic-checker 'eglot
|
|
||||||
"Report `eglot' diagnostics using `flycheck'."
|
|
||||||
:start #'+lsp--flycheck-eglot-init
|
|
||||||
:predicate #'+lsp--flycheck-eglot-available-p
|
|
||||||
:modes '(prog-mode text-mode))
|
|
||||||
|
|
||||||
(push 'eglot flycheck-checkers)
|
|
||||||
|
|
||||||
(add-hook! 'eglot-managed-mode-hook
|
|
||||||
(defun +lsp-eglot-prefer-flycheck-h ()
|
|
||||||
(when eglot--managed-mode
|
|
||||||
(flymake-mode -1)
|
|
||||||
(when-let ((current-checker (flycheck-get-checker-for-buffer)))
|
|
||||||
(unless (equal current-checker 'eglot)
|
|
||||||
(flycheck-add-next-checker 'eglot current-checker)))
|
|
||||||
(flycheck-add-mode 'eglot major-mode)
|
|
||||||
(flycheck-mode 1)
|
|
||||||
;; Call flycheck on initilization to make sure to display initial
|
|
||||||
;; errors
|
|
||||||
(flycheck-buffer-deferred))))
|
|
||||||
|
|
||||||
(after! flymake
|
|
||||||
(when (and
|
|
||||||
(not (fboundp 'flymake--diag-buffer))
|
|
||||||
(fboundp 'flymake--diag-locus))
|
|
||||||
(defalias 'flymake--diag-buffer 'flymake--diag-locus)))
|
|
||||||
|
|
||||||
;;; flycheck-eglot.el ends here
|
|
|
@ -5,7 +5,9 @@
|
||||||
(progn
|
(progn
|
||||||
(package! eglot :pin "e501275e06952889056268dabe08ccd0dbaf23e5")
|
(package! eglot :pin "e501275e06952889056268dabe08ccd0dbaf23e5")
|
||||||
(when (modulep! :completion vertico)
|
(when (modulep! :completion vertico)
|
||||||
(package! consult-eglot :pin "6504ccd2b7555452c61cc24a45965f7e2a37c44d")))
|
(package! consult-eglot :pin "6504ccd2b7555452c61cc24a45965f7e2a37c44d"))
|
||||||
|
(when (modulep! :checkers syntax)
|
||||||
|
(package! flycheck-eglot :pin "9abab011071c93250a894cf2bfeaf30c8e3367a7")))
|
||||||
(package! lsp-mode :pin "a655f3600e040f872408da0e9c1b9fe65ca0aad9")
|
(package! lsp-mode :pin "a655f3600e040f872408da0e9c1b9fe65ca0aad9")
|
||||||
(package! lsp-ui :pin "295d8984da06a745b0a36c56e28ce915bc389adb")
|
(package! lsp-ui :pin "295d8984da06a745b0a36c56e28ce915bc389adb")
|
||||||
(when (modulep! :completion ivy)
|
(when (modulep! :completion ivy)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue