Half-revert & rewrite +lsp-init-a
The original lsp is just too opinionated to delegate to. Better we just initialize lsp entirely by hand, instead.
This commit is contained in:
parent
3eb61601e5
commit
844a236949
1 changed files with 27 additions and 20 deletions
|
@ -67,35 +67,42 @@ auto-killed (which is usually an expensive process)."
|
||||||
nil)
|
nil)
|
||||||
((lsp--find-root-interactively session))))
|
((lsp--find-root-interactively session))))
|
||||||
|
|
||||||
(defadvice! +lsp-init-a (orig-fn &optional arg)
|
(defadvice! +lsp-init-a (&optional arg)
|
||||||
"Enable `lsp-mode' in the current buffer.
|
"Enable `lsp-mode' in the current buffer.
|
||||||
|
|
||||||
Meant to gimp `lsp', which is too eager about installing LSP servers,
|
Meant to gimp `lsp', which is too eager about installing LSP servers, or
|
||||||
initializing lsp-ui-mode, company, yasnippet and flycheck. Instead, these are
|
prompting to do so, or complaining about no LSP servers, or initializing
|
||||||
handled by our modules. Also see:
|
lsp-ui-mode, company, yasnippet and flycheck. We want LSP to work only if the
|
||||||
|
server is present, and for server installation to be a deliberate act by the
|
||||||
|
end-user. Also, setting up these other packages are handled by their respective
|
||||||
|
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')
|
||||||
|
|
||||||
This also logs the resolved project root, if found, so we know where we are."
|
This also logs the resolved project root, if found, so we know where we are."
|
||||||
:around #'lsp
|
:override #'lsp
|
||||||
(interactive "P")
|
(interactive "P")
|
||||||
(require 'lsp-mode)
|
(require 'lsp-mode)
|
||||||
(cl-letf
|
(and (buffer-file-name)
|
||||||
(;; Our system, our rules. Don't install things on it without our
|
(setq-local
|
||||||
;; permission. Use `lsp-install-server' deliberately, instead.
|
lsp--buffer-workspaces
|
||||||
((symbol-function #'lsp--client-download-server-fn)
|
(or (lsp--try-open-in-library-workspace)
|
||||||
(lambda (&rest _) nil))
|
(lsp--try-project-root-workspaces
|
||||||
;; Don't set up company, lsp-ui, yasnippet, or flycheck. We have
|
(equal arg '(4))
|
||||||
;; modules dedicated to these things already.
|
(and arg (not (equal arg 1))))))
|
||||||
((symbol-function #'lsp--auto-configure)
|
(prog1 (lsp-mode 1)
|
||||||
(lambda (&rest _)
|
(setq-local lsp-buffer-uri (lsp--buffer-uri))
|
||||||
;; 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."))
|
||||||
(funcall orig-fn arg))
|
(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
|
;; 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)))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue