tools/lsp: reduce lsp's self-configuring eagerness

The original `lsp' initializes too much, too quickly. Things like
flycheck, company, and yasnippet. Doom's modules already handle these
just fine, so we advice it to leave it to us to handle. I intentionally
avoid disabling lsp-auto-configure because doing so is much more
destructive than I'd like.

This update prevents lsp-ui-mode from being auto-enabled on lsp-mode.
You can now (remove-hook 'lsp-mode-hook #'lsp-ui-mode) to disable
lsp-ui.

This update also adds these two hooks:

+ +lsp|init-company (on `lsp-mode-hook')
+ +lsp|init-ui-flycheck-or-flymake (on `lsp-ui-mode-hook')
This commit is contained in:
Henrik Lissner 2019-06-29 00:28:13 +02:00
parent 380c3ac268
commit a9ca62070c
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 40 additions and 2 deletions

View file

@ -9,12 +9,27 @@
(set-lookup-handlers! 'lsp-mode :async t
:documentation 'lsp-describe-thing-at-point)
;; The original `lsp' initializes too much, too quickly. Things like flycheck,
;; company, and yasnippet. Doom's modules already handle these just fine, so
;; leave it to us.
(advice-add #'lsp :override #'lsp!)
;; Don't prompt to restart LSP servers while quitting Emacs
(add-hook! 'kill-emacs-hook (setq lsp-restart 'ignore)))
(def-package! lsp-ui
:hook (lsp-mode . lsp-ui-mode)
:init
(defun +lsp|init-ui-flycheck-or-flymake ()
"Sets up flymake-mode or flycheck-mode, depending on `lsp-prefer-flymake'."
(unless (eq :none lsp-prefer-flymake)
(if (and (not (version< emacs-version "26.1"))
lsp-prefer-flymake)
(lsp--flymake-setup))
(require 'lsp-ui-flycheck)
(lsp-ui-flycheck-enable t)))
(add-hook 'lsp-ui-mode-hook #'+lsp|init-ui-flycheck-or-flymake)
:config
(setq lsp-prefer-flymake nil
lsp-ui-doc-max-height 8
@ -33,4 +48,8 @@
:when (featurep! :completion company)
:after lsp-mode
:config
(set-company-backend! 'lsp-mode 'company-lsp))
;; Make sure that `company-capf' is disabled since it is incompatible with
;; `company-lsp' (see lsp-mode#884)
(setq-hook! 'lsp-mode-hook company-backends
(cons 'company-lsp
(remq 'company-capf company-backends))))