Skip to content

Commit ca6f01c

Browse files
authored
ensure flycheck checker is registered before calling lsp-flycheck-add-mode (#2606)
Fixes #2594
1 parent 38d434f commit ca6f01c

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

lsp-diagnostics.el

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,7 @@ from the language server."
202202

203203
(defvar lsp-diagnostics-mode) ;; properly defined by define-minor-mode below
204204

205-
(defun lsp-diagnostics-flycheck-enable (&rest _)
206-
"Enable flycheck integration for the current buffer."
207-
(require 'flycheck)
205+
(defun lsp-diagnostics-lsp-checker-if-needed ()
208206
(unless (flycheck-valid-checker-p 'lsp)
209207
(flycheck-define-generic-checker 'lsp
210208
"A syntax checker using the Language Server Protocol (LSP)
@@ -215,10 +213,15 @@ See https://github.com/emacs-lsp/lsp-mode."
215213
:predicate (lambda () lsp-diagnostics-mode)
216214
:error-explainer (lambda (e)
217215
(lsp-diagnostics-flycheck-error-explainer
218-
e (lsp--workspace-server-id (car-safe (lsp-workspaces)))))))
216+
e (lsp--workspace-server-id (car-safe (lsp-workspaces))))))))
217+
218+
(defun lsp-diagnostics-flycheck-enable (&rest _)
219+
"Enable flycheck integration for the current buffer."
220+
(require 'flycheck)
221+
(lsp-diagnostics-lsp-checker-if-needed)
219222
(and (not lsp-diagnostics--flycheck-enabled)
220-
(not (eq flycheck-checker 'lsp))
221-
(setq lsp-diagnostics--flycheck-checker flycheck-checker))
223+
(not (eq flycheck-checker 'lsp))
224+
(setq lsp-diagnostics--flycheck-checker flycheck-checker))
222225
(setq-local lsp-diagnostics--flycheck-enabled t)
223226
(flycheck-mode 1)
224227
(flycheck-stop)

lsp-mode.el

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8190,9 +8190,11 @@ This avoids overloading the server with many files when starting Emacs."
81908190

81918191
(declare-function flycheck-checker-supports-major-mode-p "ext:flycheck")
81928192
(declare-function flycheck-add-mode "ext:flycheck")
8193+
(declare-function lsp-diagnostics-lsp-checker-if-needed "lsp-diagnostics")
81938194

81948195
(defun lsp-flycheck-add-mode (mode)
81958196
"Register flycheck support for MODE."
8197+
(lsp-diagnostics-lsp-checker-if-needed)
81968198
(unless (flycheck-checker-supports-major-mode-p 'lsp mode)
81978199
(flycheck-add-mode 'lsp mode)))
81988200

0 commit comments

Comments
 (0)