Hi!
For a long time, I have been using the following construct in my Emacs configuration to use specific flycheck checkers in addition to the default one provided by the respective LSP servers:
;; Add buffer local Flycheck checkers after LSP for different major modes.
;;
;; The following code was motivated by a discussion on the `lsp-mode' Discord
;; channel (credit goes to @yyoncho).
(defun my-flycheck-local-checker-get (fn checker property)
(or (alist-get property (alist-get checker my-flycheck-local-cache))
(funcall fn checker property)))
(defvar-local my-flycheck-local-cache nil)
(advice-add #'flycheck-checker-get :around #'my-flycheck-local-checker-get)
(add-hook 'lsp-managed-mode-hook
(lambda ()
(when (derived-mode-p 'sh-mode)
(setq my-flycheck-local-cache '((lsp . ((next-checkers . (sh-shellcheck)))))))))
(add-hook 'lsp-managed-mode-hook
(lambda ()
(when (derived-mode-p 'tex-mode)
(setq my-flycheck-local-cache '((lsp . ((next-checkers . (tex-chktex)))))))))
(add-hook 'lsp-managed-mode-hook
(lambda ()
(when (derived-mode-p 'typescript-mode)
(setq my-flycheck-local-cache '((lsp . ((next-checkers . (javascript-eslint)))))))))
That is, when editing a BASH script, I get flycheck errors from the language
server I am using, and also from sh-shellcheck
.
I thought that this was a common problem to solve and that my solution is rather complex. What are your solutions to using different flycheck checkers together with LSP servers?