From a493a4032c4bbd3c5d8b7816266f07b8ee15c7f0 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sun, 21 Jan 2018 12:27:33 -0800 Subject: [PATCH] Add +tools/lsp layer for lsp-mode & lsp-ui This is a starting point to bring LSP ecosystem into spacemacs. Theme by 0bl.blwl --- layers/+tools/lsp/README.org | 23 ++++++++++++ layers/+tools/lsp/funcs.el | 18 +++++++++ layers/+tools/lsp/packages.el | 70 +++++++++++++++++++++++++++++++++++ 3 files changed, 111 insertions(+) create mode 100644 layers/+tools/lsp/README.org create mode 100644 layers/+tools/lsp/funcs.el create mode 100644 layers/+tools/lsp/packages.el diff --git a/layers/+tools/lsp/README.org b/layers/+tools/lsp/README.org new file mode 100644 index 000000000000..94daff3063a8 --- /dev/null +++ b/layers/+tools/lsp/README.org @@ -0,0 +1,23 @@ +#+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-mode][lsp-ui]]. +Please check out their documentation. diff --git a/layers/+tools/lsp/funcs.el b/layers/+tools/lsp/funcs.el new file mode 100644 index 000000000000..06603427b574 --- /dev/null +++ b/layers/+tools/lsp/funcs.el @@ -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)) + ) diff --git a/layers/+tools/lsp/packages.el b/layers/+tools/lsp/packages.el new file mode 100644 index 000000000000..6abdbb9b42fd --- /dev/null +++ b/layers/+tools/lsp/packages.el @@ -0,0 +1,70 @@ +(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) + + (require 'lsp-imenu) + (add-hook 'lsp-after-open-hook #'lsp-enable-imenu) + + ;; 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) + )))