Skip to content

Commit

Permalink
Add +tools/lsp layer for lsp-mode & lsp-ui
Browse files Browse the repository at this point in the history
This is a starting point to bring LSP ecosystem into spacemacs.

Theme by 0bl.blwl
  • Loading branch information
MaskRay committed Jan 31, 2018
1 parent 64cf9f5 commit fe2d831
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 0 deletions.
25 changes: 25 additions & 0 deletions layers/+tools/lsp/README.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#+TITLE: LSP layer

* Table of Contents :TOC_4_gh:noexport:
- [[#description][Description]]
- [[#features][Features:]]
- [[#configuration][Configuration]]

* Description
This layer adds support for basic language server protocol packages speaking [[https://microsoft.github.io/language-server-protocol/specification][language server protocol]].

** Features:
- Cross references (definitions, references, document symbol, workspace symbol search and others)
- Workspace-wide symbol rename
- Symbol highlighting
- Flycheck
- Completion with =company-lsp=
- Signature help with eldoc
- Symbol documentation in a child frame (=lsp-ui-doc=)
- Each language server may support a subset of these features and may have their extension, check =M-x lsp-capabilities= in a LSP buffer and the language server's website for details.

* Configuration
The LSP ecosystem is based on two packages: [[https://github.com/emacs-lsp/lsp-mode][lsp-mode]] and [[https://github.com/emacs-lsp/lsp-ui][lsp-ui]].
Please check out their documentation.

If you add =lsp-*-enable= to major mode hooks for auto initialization of language clients, customize =lsp-project-whitelist= =lsp-project-blacklist= to disable projects you don't want to enable LSP.
18 changes: 18 additions & 0 deletions layers/+tools/lsp/funcs.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
(defun lsp//sync-peek-face ()
(set-face-attribute 'lsp-ui-peek-list nil
:background (face-attribute 'hl-line :background))
(set-face-attribute 'lsp-ui-peek-peek nil
:background (face-attribute 'hl-line :background))
(set-face-attribute 'lsp-ui-peek-selection nil
:background (face-attribute 'highlight :background)
:foreground (face-attribute 'default :foreground))
(set-face-attribute 'lsp-ui-peek-filename nil
:foreground (face-attribute 'font-lock-constant-face :foreground))
(set-face-attribute 'lsp-ui-peek-highlight nil
:background (face-attribute 'highlight :background)
:foreground (face-attribute 'highlight :foreground)
:distant-foreground (face-attribute 'highlight :foreground))
(set-face-attribute 'lsp-ui-peek-header nil
:background (face-attribute 'highlight :background)
:foreground (face-attribute 'default :foreground))
)
67 changes: 67 additions & 0 deletions layers/+tools/lsp/packages.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
(defconst lsp-packages
'(
(company-lsp :requires company)
(helm-xref :requires helm)
(ivy-xref :requires ivy)
lsp-mode
lsp-ui
))

(defun lsp/init-company-lsp ()
(use-package company-lsp
:defer t
:init
;; Language servers have better idea filtering and sorting,
;; don't filter results on the client side.
(setq company-transformers nil
company-lsp-async t
company-lsp-cache-candidates nil)
;; (spacemacs|add-company-backends :backends company-lsp :modes c-mode-common)
))

(defun lsp/init-helm-xref ()
(use-package helm-xref
:defer t
:init
(progn
;; This is required to make xref-find-references not give a prompt.
;; xref-find-references asks the identifier (which has no text property) and then passes it to lsp-mode, which requires the text property at point to locate the references.
;; https://debbugs.gnu.org/cgi/bugreport.cgi?bug=29619
(setq xref-prompt-for-identifier
'(not xref-find-definitions xref-find-definitions-other-window xref-find-definitions-other-frame xref-find-references spacemacs/jump-to-definition))

;; Use helm-xref to display xref.el results.
(setq xref-show-xrefs-function #'helm-xref-show-xrefs)
)))

(defun lsp/init-ivy-xref ()
(use-package ivy-xref
:defer t
:init
(progn
(setq xref-prompt-for-identifier
'(not xref-find-definitions xref-find-definitions-other-window xref-find-definitions-other-frame xref-find-references spacemacs/jump-to-definition))

;; Use ivy-xref to display xref.el results.
(setq xref-show-xrefs-function #'ivy-xref-show-xrefs)
)))

(defun lsp/init-lsp-mode ()
(use-package lsp-mode
:config
(progn
(add-hook 'lsp-mode-hook #'lsp-ui-mode)

;; Disable lsp-flycheck.el in favor of lsp-ui-flycheck.el
(setq lsp-enable-flycheck nil)

(spacemacs|diminish lsp-mode "" " L")
)))

(defun lsp/init-lsp-ui ()
(use-package lsp-ui
:config
(progn
(lsp//sync-peek-face)
(add-hook 'spacemacs-post-theme-change-hook #'lsp//sync-peek-face)
)))

0 comments on commit fe2d831

Please sign in to comment.