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.
This commit is contained in:
Henrik Lissner 2020-01-10 04:42:54 -05:00
parent 4acd60aba3
commit 46aaeee818
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -11,7 +11,7 @@ This can be a single company backend or a list thereof. It can be anything
;;; Packages ;;; Packages
(use-package! lsp-mode (use-package! lsp-mode
:defer t :commands lsp-install-server
:init :init
(setq lsp-session-file (concat doom-etc-dir "lsp-session")) (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 ;; 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/")) lsp-intelephense-storage-path (concat doom-cache-dir "lsp-intelephense/"))
:config :config
(when (and lsp-auto-configure lsp-auto-require-clients)
(require 'lsp-clients))
(set-lookup-handlers! 'lsp-mode :async t (set-lookup-handlers! 'lsp-mode :async t
:documentation 'lsp-describe-thing-at-point :documentation 'lsp-describe-thing-at-point
:definition 'lsp-find-definition :definition 'lsp-find-definition
@ -64,39 +67,35 @@ auto-killed (which is usually an expensive process)."
nil) nil)
((lsp--find-root-interactively session)))) ((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. "Enable `lsp-mode' in the current buffer.
Meant to be a lighter alternative to `lsp', which is too eager about Meant to gimp `lsp', which is too eager about installing LSP servers,
initializing lsp-ui-mode, company, yasnippet and flycheck. Instead, these have initializing lsp-ui-mode, company, yasnippet and flycheck. Instead, these are
been moved out to their respective modules, or these hooks: handled by our modules. Also see:
+ `+lsp-init-company-h' (on `lsp-mode-hook') + `+lsp-init-company-h' (on `lsp-mode-hook')
+ `+lsp-init-ui-flycheck-or-flymake-h' (on `lsp-ui-mode-hook') + `+lsp-init-ui-flycheck-or-flymake-h' (on `lsp-ui-mode-hook')
Also logs the resolved project root, if found." This also logs the resolved project root, if found, so we know where we are."
:override #'lsp :around #'lsp
(interactive "P") (interactive "P")
(require 'lsp-mode) (require 'lsp-mode)
(when lsp-auto-configure (cl-letf
(require 'lsp-clients)) (;; Our system, our rules. Don't install things on it without our
(and (buffer-file-name) ;; permission. Use `lsp-install-server' deliberately, instead.
(setq-local ((symbol-function #'lsp--client-download-server-fn)
lsp--buffer-workspaces (lambda (&rest _) nil))
(or (lsp--try-open-in-library-workspace) ;; Don't set up company, lsp-ui, yasnippet, or flycheck. We have
(lsp--try-project-root-workspaces ;; modules dedicated to these things already.
(equal arg '(4)) ((symbol-function #'lsp--auto-configure)
(and arg (not (equal arg 1)))))) (lambda (&rest _)
(prog1 (lsp-mode 1) ;; Announce what project root we're using, for diagnostic
;; Announce what project root we're using, for diagnostic purposes ;; purposes
(if-let (root (lsp--calculate-root (lsp-session) (buffer-file-name))) (if-let (root (lsp--calculate-root (lsp-session) (buffer-file-name)))
(lsp--info "Guessed project root is %s" (abbreviate-file-name root)) (lsp--info "Guessed project root is %s" (abbreviate-file-name root))
(lsp--info "Could not guess project root.")) (lsp--info "Could not guess project root."))))))
(lsp--info "Connected to %s." (apply orig-fn args))
(apply #'concat
(mapcar
(lambda (it) (format "[%s]" (lsp--workspace-print it)))
lsp--buffer-workspaces))))))
;; Don't prompt to restart LSP servers while quitting Emacs ;; Don't prompt to restart LSP servers while quitting Emacs
(add-hook! 'kill-emacs-hook (setq lsp-restart 'ignore))) (add-hook! 'kill-emacs-hook (setq lsp-restart 'ignore)))
@ -149,10 +148,12 @@ Also logs the resolved project root, if found."
:config :config
(setq company-lsp-cache-candidates 'auto)) ;; cache candidates for better performance (setq company-lsp-cache-candidates 'auto)) ;; cache candidates for better performance
(use-package! helm-lsp (use-package! helm-lsp
:when (featurep! :completion helm) :when (featurep! :completion helm)
:commands helm-lsp-workspace-symbol helm-lsp-global-workspace-symbol) :commands helm-lsp-workspace-symbol helm-lsp-global-workspace-symbol)
(use-package! lsp-ivy (use-package! lsp-ivy
:when (featurep! :completion ivy) :when (featurep! :completion ivy)
:commands lsp-ivy-workspace-symbol lsp-ivy-global-workspace-symbol) :commands lsp-ivy-workspace-symbol lsp-ivy-global-workspace-symbol)