tools/lsp: log project root when starting lsp #1928

This commit is contained in:
Henrik Lissner 2019-10-21 18:28:45 -04:00
parent 4c2f718557
commit 0cca037448
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -21,7 +21,6 @@ This can be a single company backend or a list thereof. It can be anything
:references 'lsp-find-references) :references 'lsp-find-references)
(defadvice! +lsp-init-a (&optional arg) (defadvice! +lsp-init-a (&optional arg)
:override #'lsp
"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 be a lighter alternative to `lsp', which is too eager about
@ -29,26 +28,32 @@ initializing lsp-ui-mode, company, yasnippet and flycheck. Instead, these have
been moved out to their respective modules, or these hooks: been moved out to their respective modules, or these hooks:
+ `+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."
:override #'lsp
(interactive "P") (interactive "P")
(if (bound-and-true-p lsp-mode) t (if (bound-and-true-p lsp-mode) t
(require 'lsp-mode) (require 'lsp-mode)
(when lsp-auto-configure (when lsp-auto-configure
(require 'lsp-clients)) (require 'lsp-clients))
(when (and (buffer-file-name) (and (buffer-file-name)
(setq-local (setq-local
lsp--buffer-workspaces lsp--buffer-workspaces
(or (lsp--try-open-in-library-workspace) (or (lsp--try-open-in-library-workspace)
(lsp--try-project-root-workspaces (lsp--try-project-root-workspaces
(equal arg '(4)) (equal arg '(4))
(and arg (not (equal arg 1))))))) (and arg (not (equal arg 1))))))
(prog1 (lsp-mode 1) (prog1 (lsp-mode 1)
(lsp--info ;; Announce what project root we're using, for diagnostic purposes
"Connected to %s." (if-let (root (lsp--calculate-root (lsp-session) (buffer-file-name)))
(apply (lsp--info "Guessed project root is %s" (abbreviate-file-name root))
#'concat (mapcar (lsp--info "Could not guess project root."))
(lambda (it) (format "[%s]" (lsp--workspace-print it))) (lsp--info "Connected to %s."
lsp--buffer-workspaces))))))) (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)))