2019-02-21 16:08:27 -05:00
|
|
|
;;; tools/lsp/config.el -*- lexical-binding: t; -*-
|
|
|
|
|
2019-08-15 14:59:53 -04:00
|
|
|
(defvar +lsp-company-backend 'company-lsp
|
|
|
|
"What backend to prepend to `company-backends' when `lsp-mode' is active.
|
|
|
|
|
|
|
|
This can be a single company backend or a list thereof. It can be anything
|
|
|
|
`company-backends' will accept.")
|
|
|
|
|
|
|
|
|
2019-10-21 19:01:06 -04:00
|
|
|
;;
|
|
|
|
;;; Packages
|
|
|
|
|
|
|
|
(use-package! lsp-mode
|
|
|
|
:defer t
|
|
|
|
: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
|
|
|
|
;; lsp-worthy file, instead, try to guess it with projectile.
|
|
|
|
(setq lsp-auto-guess-root t)
|
|
|
|
;; Auto-kill LSP server once you've killed the last buffer associated with its
|
|
|
|
;; project.
|
|
|
|
(setq lsp-keep-workspace-alive nil)
|
|
|
|
|
|
|
|
:config
|
|
|
|
(setq lsp-fsharp-server-install-dir (concat doom-etc-dir "lsp-fsharp/")
|
|
|
|
lsp-groovy-server-install-dir (concat doom-etc-dir "lsp-groovy/")
|
|
|
|
lsp-intelephense-storage-path (concat doom-cache-dir "lsp-intelephense/"))
|
2019-02-24 13:49:12 -05:00
|
|
|
|
2019-05-03 20:03:32 -04:00
|
|
|
(set-lookup-handlers! 'lsp-mode :async t
|
2019-06-29 00:33:07 +02:00
|
|
|
:documentation 'lsp-describe-thing-at-point
|
|
|
|
:definition 'lsp-find-definition
|
|
|
|
:references 'lsp-find-references)
|
2019-04-16 20:21:13 -04:00
|
|
|
|
2019-10-21 18:29:11 -04:00
|
|
|
(defadvice! +lsp-prompt-if-no-project-a (root)
|
|
|
|
"Prompt for the project root only if no project was found.
|
|
|
|
Also refuses to recognize $HOME as a valid project root."
|
|
|
|
:filter-return #'lsp--calculate-root
|
|
|
|
(cond ((and root (not (file-equal-p root "~")))
|
|
|
|
root)
|
|
|
|
(lsp-auto-guess-root
|
|
|
|
(lsp--find-root-interactively (lsp-session)))))
|
|
|
|
|
2019-10-18 20:28:28 -04:00
|
|
|
(defadvice! +lsp-init-a (&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')
|
2019-10-21 18:28:45 -04:00
|
|
|
+ `+lsp-init-ui-flycheck-or-flymake-h' (on `lsp-ui-mode-hook')
|
|
|
|
|
|
|
|
Also logs the resolved project root, if found."
|
|
|
|
:override #'lsp
|
2019-10-18 20:28:28 -04:00
|
|
|
(interactive "P")
|
|
|
|
(if (bound-and-true-p lsp-mode) t
|
|
|
|
(require 'lsp-mode)
|
|
|
|
(when lsp-auto-configure
|
|
|
|
(require 'lsp-clients))
|
2019-10-21 18:28:45 -04:00
|
|
|
(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)))))))
|
2019-06-29 00:28:13 +02:00
|
|
|
|
2019-04-16 20:21:13 -04:00
|
|
|
;; Don't prompt to restart LSP servers while quitting Emacs
|
|
|
|
(add-hook! 'kill-emacs-hook (setq lsp-restart 'ignore)))
|
2019-02-28 05:01:40 -05:00
|
|
|
|
2019-02-24 13:49:12 -05:00
|
|
|
|
2019-07-23 12:44:03 +02:00
|
|
|
(use-package! lsp-ui
|
2019-02-21 16:08:27 -05:00
|
|
|
:hook (lsp-mode . lsp-ui-mode)
|
2019-06-29 00:28:13 +02:00
|
|
|
:init
|
2019-07-26 19:57:13 +02:00
|
|
|
(add-hook! 'lsp-ui-mode-hook
|
2019-07-18 15:27:20 +02:00
|
|
|
(defun +lsp-init-ui-flycheck-or-flymake-h ()
|
|
|
|
"Sets up flymake-mode or flycheck-mode, depending on `lsp-prefer-flymake'."
|
2019-09-30 12:42:56 -04:00
|
|
|
(cond ((eq :none lsp-prefer-flymake))
|
|
|
|
((and (not (version< emacs-version "26.1"))
|
|
|
|
lsp-prefer-flymake)
|
|
|
|
(lsp--flymake-setup))
|
|
|
|
((require 'flycheck nil t)
|
|
|
|
(require 'lsp-ui-flycheck)
|
|
|
|
(lsp-ui-flycheck-enable t)))))
|
2019-02-21 16:08:27 -05:00
|
|
|
:config
|
|
|
|
(setq lsp-prefer-flymake nil
|
|
|
|
lsp-ui-doc-max-height 8
|
|
|
|
lsp-ui-doc-max-width 35
|
2019-05-17 02:05:33 -04:00
|
|
|
lsp-ui-sideline-ignore-duplicate t
|
2019-07-22 00:43:50 +02:00
|
|
|
;; lsp-ui-doc is redundant with and more invasive than
|
2019-05-17 02:05:33 -04:00
|
|
|
;; `+lookup/documentation'
|
2019-07-22 00:43:50 +02:00
|
|
|
lsp-ui-doc-enable nil
|
|
|
|
;; Don't show symbol definitions in the sideline. They are pretty noisy,
|
|
|
|
;; and there is a bug preventing Flycheck errors from being shown (the
|
|
|
|
;; errors flash briefly and then disappear).
|
2019-09-26 14:26:08 -04:00
|
|
|
lsp-ui-sideline-show-hover nil)
|
2019-04-16 20:21:13 -04:00
|
|
|
|
2019-05-03 20:03:32 -04:00
|
|
|
(set-lookup-handlers! 'lsp-ui-mode :async t
|
|
|
|
:definition 'lsp-ui-peek-find-definitions
|
|
|
|
:references 'lsp-ui-peek-find-references))
|
2019-02-21 16:08:27 -05:00
|
|
|
|
2019-02-24 13:49:12 -05:00
|
|
|
|
2019-07-23 12:44:03 +02:00
|
|
|
(use-package! company-lsp
|
2019-02-21 16:08:27 -05:00
|
|
|
:when (featurep! :completion company)
|
2019-07-05 23:42:06 +02:00
|
|
|
:defer t
|
|
|
|
:init
|
2019-06-29 00:28:13 +02:00
|
|
|
;; Make sure that `company-capf' is disabled since it is incompatible with
|
|
|
|
;; `company-lsp' (see lsp-mode#884)
|
2019-07-26 19:57:13 +02:00
|
|
|
(add-hook! 'lsp-mode-hook
|
2019-07-18 15:27:20 +02:00
|
|
|
(defun +lsp-init-company-h ()
|
|
|
|
(if (not (bound-and-true-p company-mode))
|
|
|
|
(add-hook 'company-mode-hook #'+lsp-init-company-h t t)
|
|
|
|
(setq-local company-backends
|
2019-08-15 14:59:53 -04:00
|
|
|
(cons +lsp-company-backend
|
2019-07-05 23:42:06 +02:00
|
|
|
(remq 'company-capf company-backends)))
|
2019-07-27 04:28:22 +10:00
|
|
|
(remove-hook 'company-mode-hook #'+lsp-init-company-h t))))
|
|
|
|
:config
|
|
|
|
(setq company-lsp-cache-candidates 'auto)) ;; cache candidates for better performance
|