diff --git a/modules/tools/lsp/autoload.el b/modules/tools/lsp/autoload.el index f2d778975..a7d4f3b07 100644 --- a/modules/tools/lsp/autoload.el +++ b/modules/tools/lsp/autoload.el @@ -1,4 +1,23 @@ ;;; feature/lsp/autoload.el -*- lexical-binding: t; -*- ;;;###autodef -(defalias 'lsp! #'lsp) +(defun lsp! (&optional arg) + "Enable `lsp-mode' in the current buffer. + +Meant to be a lighter alternative to `lsp', which is too eager about +initializing lsp-ui-mode, company, yasnippet and flycheck. Instead, these have +been moved out to their respective modules, or these hooks: + ++ `+lsp|init-company' (on `lsp-mode-hook') ++ `+lsp|init-ui-flycheck-or-flymake' (on `lsp-ui-mode-hook')" + (when lsp-auto-configure + (require 'lsp-clients)) + (when (and (buffer-file-name) + (setq-local lsp--buffer-workspaces + (or (lsp--try-open-in-library-workspace) + (lsp--try-project-root-workspaces (equal arg '(4)) + (and arg (not (equal arg 1))))))) + (lsp-mode 1) + (lsp--info "Connected to %s." + (apply 'concat (--map (format "[%s]" (lsp--workspace-print it)) + lsp--buffer-workspaces))))) diff --git a/modules/tools/lsp/config.el b/modules/tools/lsp/config.el index 9ee8b2aab..e1b0be6e2 100644 --- a/modules/tools/lsp/config.el +++ b/modules/tools/lsp/config.el @@ -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))))