From 2d2413d293532ddb56098348723febf4b140d89a Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Fri, 18 Oct 2019 20:28:28 -0400 Subject: [PATCH] tools/lsp: defer lsp init until buffer is visible --- modules/tools/lsp/autoload.el | 29 +---------------------------- modules/tools/lsp/config.el | 33 +++++++++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 32 deletions(-) diff --git a/modules/tools/lsp/autoload.el b/modules/tools/lsp/autoload.el index b84f6bf9d..ae45c1ef1 100644 --- a/modules/tools/lsp/autoload.el +++ b/modules/tools/lsp/autoload.el @@ -1,31 +1,4 @@ ;;; feature/lsp/autoload.el -*- lexical-binding: t; -*- ;;;###autodef -(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-h' (on `lsp-mode-hook') -+ `+lsp-init-ui-flycheck-or-flymake-h' (on `lsp-ui-mode-hook')" - (if (bound-and-true-p lsp-mode) - t - (require 'lsp-mode) - (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))))))) - (prog1 (lsp-mode 1) - (lsp--info - "Connected to %s." - (apply - #'concat (mapcar - (lambda (it) (format "[%s]" (lsp--workspace-print it))) - lsp--buffer-workspaces))))))) +(defalias 'lsp! #'lsp-deferred) diff --git a/modules/tools/lsp/config.el b/modules/tools/lsp/config.el index b6beca4fa..18d5d3dc1 100644 --- a/modules/tools/lsp/config.el +++ b/modules/tools/lsp/config.el @@ -20,10 +20,35 @@ This can be a single company backend or a list thereof. It can be anything :definition 'lsp-find-definition :references 'lsp-find-references) - ;; 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!) + (defadvice! +lsp-init-a (&optional arg) + :override #'lsp + "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-h' (on `lsp-mode-hook') ++ `+lsp-init-ui-flycheck-or-flymake-h' (on `lsp-ui-mode-hook')" + (interactive "P") + (if (bound-and-true-p lsp-mode) t + (require 'lsp-mode) + (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))))))) + (prog1 (lsp-mode 1) + (lsp--info + "Connected to %s." + (apply + #'concat (mapcar + (lambda (it) (format "[%s]" (lsp--workspace-print it))) + lsp--buffer-workspaces))))))) ;; Don't prompt to restart LSP servers while quitting Emacs (add-hook! 'kill-emacs-hook (setq lsp-restart 'ignore)))