lsp-mode use lsp-ui as it's default flycheck checker, and it runned by language server. If I want to add new flycheck checker after lsp-ui, how should I do?
I have tried:
(defun my-flycheck-setup ()
(flycheck-add-next-checker 'lsp-ui 'python-pylint)
)
(add-hook 'python-mode-hook 'my-flycheck-setup)
Give this a try:
;; add to ~/.doom.d/config.el
(defun my-flycheck-setup ()
(flycheck-add-next-checker 'lsp-ui 'python-pylint))
;; These MODE-local-vars-hook hooks are a Doom thing. They're executed after
;; MODE-hook, on hack-local-variables-hook. Although `lsp!` is attached to
;; python-mode-local-vars-hook, it should occur earlier than my-flycheck-setup
;; this way:
(add-hook 'python-mode-local-vars-hook #'my-flycheck-setup)
Seems to work fine 馃憤

@hlissner
This doesn't seem to work any more I have an error in my messages buffer saying:
File local-variables error: (doom-hook-error my-flycheck-setup (error lsp-ui is not a valid syntax checker))
Although lsp-ui does work perfectly fine once i open a python file
Ok I changed the hook to lsp-ui-mode-local-vars-hook now it no longer throws an error, but it doesn't seem to use my second checker either
@vikigenius MODE-local-vars-hook hooks are only run for major modes. lsp-ui-mode is a minor mode. You're getting no error before it's not being run.
I can't reproduce your other issues.
@gagbo How about you?
I'm using the method we discussed about in the discord (using the local-vars-hook method to create a lsp-ui-hook family)
;; config.el
(after! lsp-ui
(add-hook! 'lsp-ui-mode-hook
(run-hooks (intern (format "%s-lsp-ui-hook" major-mode)))))
(defun gagbo-go-flycheck-setup ()
"Setup Flycheck checkers for Golang"
(flycheck-add-next-checker 'lsp-ui 'golangci-lint))
(add-hook 'go-mode-lsp-ui-hook
#'gagbo-go-flycheck-setup)
(defun gagbo-python-flycheck-setup ()
"Setup Flycheck checkers for Python"
(flycheck-add-next-checker 'lsp-ui 'python-pylint))
(add-hook 'python-mode-lsp-ui-hook
#'gagbo-python-flycheck-setup)
With this I don't have any issues running multiple checkers (these days I mostly use Go, I didn't check again for Python)
Side note 1 :
The next-checkers attribute list is a global one. Meaning after a long session, changing mode/projects multiple times, the next-checker attribute of 'lsp-ui checker will be very long with a lot of duplicate. I don't know how it affects performance yet
Side note 2 :
That will also probably allow me to disable some lsp-ui features for specific languages/major-modes.
Side note 3 :
Actually I would have liked a way to disable lsp-ui altogether for specific languages, and with this method it's possible but lsp-ui will have to load before being deactivated (since the hook is after lsp-ui is loaded). For now I don't need to do this so I don't care, but maybe that's worth exploring
I've added
(add-hook 'lsp-after-initialize-hook (lambda
()
(flycheck-add-next-checker 'lsp-ui 'elixir-credo)))
to my ~/.doom.d/config.el which seems to be working fine too (and is not duplicating entries in next-chekers list, to my knowledge).
Hrm, none of these seemed to do anything when I added them to my config.el. Trying to get golangci-lint to run while using lsp-mode. Just curious if anyone had any updated workarounds I could try? If not, sorry for the noise!
The checker has been renamed from lsp-ui to lsp, so changing the name like this should work.
Also, a recent patch of Doom (yesterday I believe ?) automated the change; if you already have golangci-lint as your flycheck linter when lsp starts, lsp will just add itself to golangci
EDIT : well, not yesterday https://github.com/hlissner/doom-emacs/commit/134554dd69d9b1cea3d2190422de580fddf40ecd
That fixed it! Thanks very much!
Somewhy this fix https://github.com/hlissner/doom-emacs/commit/134554dd69d9b1cea3d2190422de580fddf40ecd does not work for me.
I have the following in my config.el
(add-hook 'go-mode-local-vars-hook
(lambda ()
(when (flycheck-may-enable-checker 'golangci-lint)
(flycheck-select-checker 'golangci-lint))))
And I can see errors only from golangci-lint
UPD: Probably because of this commit https://github.com/hlissner/doom-emacs/commit/50f1391e86e35542d60cfa0e42356ae49d86bad4
Bot now I have same problem as described above.
When I tried to do it like @hlissner described here https://github.com/hlissner/doom-emacs/issues/1530#issuecomment-507653761 I got lsp is not a valid syntax checker
UPD2: Finally I made it work
(add-hook! 'lsp-after-initialize-hook
(run-hooks (intern (format "%s-lsp-hook" major-mode))))
(defun go-flycheck-setup ()
(flycheck-add-next-checker 'lsp 'golangci-lint))
(add-hook 'go-mode-lsp-hook
#'go-flycheck-setup)
Most helpful comment
The checker has been renamed from
lsp-uitolsp, so changing the name like this should work.Also, a recent patch of Doom (yesterday I believe ?) automated the change; if you already have golangci-lint as your flycheck linter when lsp starts, lsp will just add itself to golangci
EDIT : well, not yesterday https://github.com/hlissner/doom-emacs/commit/134554dd69d9b1cea3d2190422de580fddf40ecd