From 46aaeee81872c18d30305f488438cfa5093340d7 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Fri, 10 Jan 2020 04:42:54 -0500 Subject: [PATCH] Update tools/lsp to reflect upstream changes LSP has taken it upon themselves to aggressively install servers if they are missing. No thanks. Promote deliberate use of lsp-install-server where we can and load lsp-clients sooner. --- modules/tools/lsp/config.el | 53 +++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/modules/tools/lsp/config.el b/modules/tools/lsp/config.el index fb43788a1..23c0791ab 100644 --- a/modules/tools/lsp/config.el +++ b/modules/tools/lsp/config.el @@ -11,7 +11,7 @@ This can be a single company backend or a list thereof. It can be anything ;;; Packages (use-package! lsp-mode - :defer t + :commands lsp-install-server :init (setq lsp-session-file (concat doom-etc-dir "lsp-session")) ;; Don't prompt the user for the project root every time we open a new @@ -27,6 +27,9 @@ This can be a single company backend or a list thereof. It can be anything lsp-intelephense-storage-path (concat doom-cache-dir "lsp-intelephense/")) :config + (when (and lsp-auto-configure lsp-auto-require-clients) + (require 'lsp-clients)) + (set-lookup-handlers! 'lsp-mode :async t :documentation 'lsp-describe-thing-at-point :definition 'lsp-find-definition @@ -64,39 +67,35 @@ auto-killed (which is usually an expensive process)." nil) ((lsp--find-root-interactively session)))) - (defadvice! +lsp-init-a (&optional arg) + (defadvice! +lsp-init-a (orig-fn &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: +Meant to gimp `lsp', which is too eager about installing LSP servers, +initializing lsp-ui-mode, company, yasnippet and flycheck. Instead, these are +handled by our modules. Also see: + `+lsp-init-company-h' (on `lsp-mode-hook') + `+lsp-init-ui-flycheck-or-flymake-h' (on `lsp-ui-mode-hook') -Also logs the resolved project root, if found." - :override #'lsp +This also logs the resolved project root, if found, so we know where we are." + :around #'lsp (interactive "P") (require 'lsp-mode) - (when lsp-auto-configure - (require 'lsp-clients)) - (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) - ;; Announce what project root we're using, for diagnostic purposes - (if-let (root (lsp--calculate-root (lsp-session) (buffer-file-name))) - (lsp--info "Guessed project root is %s" (abbreviate-file-name root)) - (lsp--info "Could not guess project root.")) - (lsp--info "Connected to %s." - (apply #'concat - (mapcar - (lambda (it) (format "[%s]" (lsp--workspace-print it))) - lsp--buffer-workspaces)))))) + (cl-letf + (;; Our system, our rules. Don't install things on it without our + ;; permission. Use `lsp-install-server' deliberately, instead. + ((symbol-function #'lsp--client-download-server-fn) + (lambda (&rest _) nil)) + ;; Don't set up company, lsp-ui, yasnippet, or flycheck. We have + ;; modules dedicated to these things already. + ((symbol-function #'lsp--auto-configure) + (lambda (&rest _) + ;; Announce what project root we're using, for diagnostic + ;; purposes + (if-let (root (lsp--calculate-root (lsp-session) (buffer-file-name))) + (lsp--info "Guessed project root is %s" (abbreviate-file-name root)) + (lsp--info "Could not guess project root.")))))) + (apply orig-fn args)) ;; Don't prompt to restart LSP servers while quitting Emacs (add-hook! 'kill-emacs-hook (setq lsp-restart 'ignore))) @@ -149,10 +148,12 @@ Also logs the resolved project root, if found." :config (setq company-lsp-cache-candidates 'auto)) ;; cache candidates for better performance + (use-package! helm-lsp :when (featurep! :completion helm) :commands helm-lsp-workspace-symbol helm-lsp-global-workspace-symbol) + (use-package! lsp-ivy :when (featurep! :completion ivy) :commands lsp-ivy-workspace-symbol lsp-ivy-global-workspace-symbol)