2018-01-21 20:27:33 +00:00
|
|
|
|
#+TITLE: LSP layer
|
|
|
|
|
|
2018-09-19 03:54:47 +00:00
|
|
|
|
* Table of Contents :TOC_4_gh:noexport:
|
2018-01-21 20:27:33 +00:00
|
|
|
|
- [[#description][Description]]
|
|
|
|
|
- [[#features][Features:]]
|
|
|
|
|
- [[#configuration][Configuration]]
|
2018-03-16 00:38:24 +00:00
|
|
|
|
- [[#variables][Variables]]
|
2018-09-20 15:59:40 +00:00
|
|
|
|
- [[#navigation-mode][Navigation mode]]
|
2018-11-22 10:56:35 +00:00
|
|
|
|
- [[#key-bindings][Key bindings]]
|
|
|
|
|
- [[#key-binding-prefixes][Key binding prefixes]]
|
|
|
|
|
- [[#core-key-bindings][Core key bindings]]
|
|
|
|
|
- [[#language-specific-key-binding-extensions][Language-specific key binding extensions]]
|
|
|
|
|
- [[#spacemacslsp-define-extensions-layer-name-kind-request-optional-extra-parameters][~spacemacs/lsp-define-extensions layer-name kind request &optional extra-parameters~]]
|
|
|
|
|
- [[#spacemacslsp-bind-extensions-for-mode][~spacemacs/lsp-bind-extensions-for-mode~]]
|
|
|
|
|
- [[#diagnostics][Diagnostics]]
|
2018-03-16 00:38:24 +00:00
|
|
|
|
- [[#references][References]]
|
2018-01-21 20:27:33 +00:00
|
|
|
|
|
|
|
|
|
* Description
|
2018-09-19 03:54:47 +00:00
|
|
|
|
This layer adds support for basic language server protocol packages speaking
|
|
|
|
|
[[https://microsoft.github.io/language-server-protocol/specification][language server protocol]].
|
2018-03-16 00:38:24 +00:00
|
|
|
|
|
2018-09-19 03:54:47 +00:00
|
|
|
|
Different language servers may support the language server protocol to varying degrees
|
|
|
|
|
and they may also provide extensions; check the language server’s website for
|
|
|
|
|
details.
|
2019-02-19 05:25:28 +00:00
|
|
|
|
=M-x lsp-describe-session= in a LSP buffer to list capabilities of the server.
|
2018-01-21 20:27:33 +00:00
|
|
|
|
|
|
|
|
|
** Features:
|
2018-09-19 03:54:47 +00:00
|
|
|
|
- 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=)
|
|
|
|
|
- Navigation using imenu
|
2018-12-22 11:04:49 +00:00
|
|
|
|
- Consistent core key bindings in LSP modes
|
2018-01-21 20:27:33 +00:00
|
|
|
|
|
|
|
|
|
* Configuration
|
2018-09-19 03:54:47 +00:00
|
|
|
|
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.
|
2018-03-16 00:38:24 +00:00
|
|
|
|
|
2018-09-19 03:54:47 +00:00
|
|
|
|
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.
|
2018-03-16 00:38:24 +00:00
|
|
|
|
|
|
|
|
|
** Variables
|
2018-09-19 03:54:47 +00:00
|
|
|
|
A number of configuration variables have been exposed via the LSP layer =config.el=.
|
|
|
|
|
Sensible defaults have been provided, however they may all be overridden in your .spacemacs, or dynamically using the bindings added
|
|
|
|
|
under the derived mode t prefix by =(spacemacs/lsp-bind-keys-for-mode mode)=
|
|
|
|
|
|
2019-03-18 06:36:56 +00:00
|
|
|
|
| Variable name | Default | Description |
|
|
|
|
|
|---------------------------------+---------+-------------------------------------------------------------------------------------------------|
|
|
|
|
|
| =lsp-navigation= | `both’ | `simple’ or `peek’ to bind only xref OR lsp-ui-peek navigation functions |
|
|
|
|
|
| =lsp-ui-remap-xref-keybindings= | nil | When non-nil, xref key bindings remapped to lsp-ui-peek-find-{definition,references} |
|
|
|
|
|
| =lsp-ui-doc-enable= | t | When non-nil, the documentation overlay is displayed |
|
|
|
|
|
| =lsp-ui-doc-include-signature= | nil | When nil, signature omitted from lsp-ui-doc overlay (this is usually redundant) |
|
|
|
|
|
| =lsp-ui-sideline-enable= | t | When non-nil, the symbol information overlay is displayed |
|
|
|
|
|
| =lsp-ui-sideline-show-symbol= | nil | When non-nil, the symbol information overlay includes symbol name (redundant for c-modes) |
|
|
|
|
|
| =lsp-prefer-flymake= | nil | When non-nil, flymake checker is used. When :none, neither flycheck nor flymake checker is user |
|
2018-03-16 00:38:24 +00:00
|
|
|
|
|
2018-09-20 15:59:40 +00:00
|
|
|
|
** Navigation mode
|
|
|
|
|
The ~lsp-navigation~ variable defined in =config.el= allows you to define a preference for lightweight or pretty
|
|
|
|
|
(using =lsp-ui-peek=) source navigation styles. By default, the lightweight functions are bound under ~SPC m g~
|
2018-11-08 20:21:30 +00:00
|
|
|
|
and the =lsp-ui-peek= variants under ~SPC m G~. Setting ~lsp-navigation~ to either ~'simple~ or ~'peek~ eliminates
|
2018-09-20 15:59:40 +00:00
|
|
|
|
the bindings under ~SPC m G~ and creates bindings under ~SPC m g~ according to the specified preference.
|
|
|
|
|
|
2018-11-22 10:56:35 +00:00
|
|
|
|
* Key bindings
|
2018-12-22 11:04:49 +00:00
|
|
|
|
A number of lsp features useful for all/most modes have been bound to the lsp minor mode, meaning they’ll be
|
2018-11-22 10:56:35 +00:00
|
|
|
|
available in all language layers based on the lsp layer.
|
|
|
|
|
|
|
|
|
|
** Key binding prefixes
|
|
|
|
|
The key bindings are grouped under the following prefixes:
|
|
|
|
|
|
|
|
|
|
| prefix | name | functional area |
|
|
|
|
|
|-----------+-------------+----------------------------------------------------------------------------|
|
|
|
|
|
| ~SPC m =~ | format | Source formatting |
|
|
|
|
|
| ~SPC m g~ | goto | Source navigation |
|
|
|
|
|
| ~SPC m G~ | peek | Source navigation (lsp-ui-peek overlay) |
|
|
|
|
|
| ~SPC m h~ | help | Help |
|
|
|
|
|
| ~SPC m b~ | lsp/backend | Catchall. Restart LSP backend, other implementation-specific functionality |
|
|
|
|
|
| ~SPC m r~ | refactor | What it says on the tin |
|
|
|
|
|
| ~SPC m T~ | toggle | Toggle LSP backend features (documentation / symbol info overlays etc.) |
|
|
|
|
|
|
2018-12-22 11:04:49 +00:00
|
|
|
|
Some navigation key bindings (i.e. ~SPC m g~ / ~SPC m G~) use an additional level of grouping:
|
2018-11-22 10:56:35 +00:00
|
|
|
|
|
|
|
|
|
| prefix | name | functional area |
|
|
|
|
|
|-----------------+------------------+----------------------------------------------------------|
|
|
|
|
|
| ~SPC m <g/G> h~ | hierarchy | Heirarchy (i.e. call/inheritance hierarchy etc. ) |
|
|
|
|
|
| ~SPC m <g/G> m~ | member hierarchy | Class/namespace members (functions, nested classes, vars |
|
|
|
|
|
|
|
|
|
|
** Core key bindings
|
|
|
|
|
The lsp minor mode bindings are:
|
|
|
|
|
|
|
|
|
|
| binding | function |
|
|
|
|
|
|-------------+--------------------------------------------------------------------------------|
|
|
|
|
|
| ~SPC m = b~ | format buffer (lsp) |
|
|
|
|
|
|-------------+--------------------------------------------------------------------------------|
|
|
|
|
|
| ~SPC m g t~ | goto type-definition (lsp) |
|
|
|
|
|
| ~SPC m g k~ | goto viewport word (avy) (See Note 1) |
|
|
|
|
|
| ~SPC m g K~ | goto viewport symbol (avy) (See Note 1) |
|
|
|
|
|
| ~SPC m g e~ | browse flycheck errors |
|
|
|
|
|
| ~SPC m g M~ | browse file symbols (lsp-ui-imenu) |
|
|
|
|
|
|-------------+--------------------------------------------------------------------------------|
|
|
|
|
|
| Note | /Replaced by the lsp-ui-peek equivalents when ~lsp-navigation~ == ='peek=/ |
|
|
|
|
|
| ~SPC m g i~ | find implementations (lsp) |
|
|
|
|
|
| ~SPC m g d~ | find definitions (xref/lsp) |
|
|
|
|
|
| ~SPC m g r~ | find references (xref/lsp) |
|
|
|
|
|
| ~SPC m g s~ | find-workspace-symbol (lsp-ui) |
|
|
|
|
|
| ~SPC m g p~ | goto previous (xref-pop-marker-stack) |
|
|
|
|
|
|-------------+--------------------------------------------------------------------------------|
|
|
|
|
|
| Note | /Omitted when ~lsp-navigation~ == ='peek= or ='simple=/ |
|
|
|
|
|
| | /Bound under ~SPC m g~ rather than ~SPC m G~ when ~lsp-navigation~ == ='peek=/ |
|
|
|
|
|
| ~SPC m G i~ | find implementation (lsp-ui-peek) |
|
|
|
|
|
| ~SPC m G d~ | find definitions (lsp-ui-peek) |
|
|
|
|
|
| ~SPC m G r~ | find references (lsp-ui-peek) |
|
|
|
|
|
| ~SPC m G s~ | find-workspace-symbol (lsp-ui-peek) |
|
|
|
|
|
| ~SPC m G p~ | goto previous (lsp-ui-peek stack - see Note 2) |
|
|
|
|
|
| ~SPC m G n~ | goto next (lsp-ui-peek stack - see Note 2) |
|
|
|
|
|
|-------------+--------------------------------------------------------------------------------|
|
|
|
|
|
| ~SPC m h h~ | describe thing at point |
|
|
|
|
|
|-------------+--------------------------------------------------------------------------------|
|
|
|
|
|
| ~SPC m b r~ | lsp-restart-workspace |
|
|
|
|
|
| ~SPC m b a~ | execute code action |
|
2019-02-19 05:25:28 +00:00
|
|
|
|
| ~SPC m b d~ | lsp-describe-session |
|
2018-11-22 10:56:35 +00:00
|
|
|
|
|-------------+--------------------------------------------------------------------------------|
|
|
|
|
|
| ~SPC m r r~ | rename |
|
|
|
|
|
|-------------+--------------------------------------------------------------------------------|
|
|
|
|
|
| ~SPC m T d~ | toggle documentation overlay |
|
|
|
|
|
| ~SPC m T F~ | toggle documentation overlay function signature |
|
|
|
|
|
| ~SPC m T s~ | toggle symbol info overlay |
|
|
|
|
|
| ~SPC m T S~ | toggle symbol info overlay symbol name |
|
|
|
|
|
| ~SPC m T I~ | toggle symbol info overlay duplicates |
|
|
|
|
|
|
|
|
|
|
Note 1: Your language server may not distinguish between the word and symbol variants of this binding.
|
|
|
|
|
Note 2: There is a window local jump list dedicated to cross references.
|
|
|
|
|
|
|
|
|
|
** Language-specific key binding extensions
|
2018-09-20 15:59:40 +00:00
|
|
|
|
Some LSP server implementations provide extensions to the protocol, which can be leveraged using ~lsp-find-custom~
|
|
|
|
|
or ~lsp-ui-peek-find-custom~. A number of additional functions have been provided to facilitate wrapping these extensions
|
|
|
|
|
in a manner consistent with the ~lsp-navigation~ setting.
|
|
|
|
|
|
2018-11-22 10:56:35 +00:00
|
|
|
|
*** ~spacemacs/lsp-define-extensions layer-name kind request &optional extra-parameters~
|
2018-09-20 15:59:40 +00:00
|
|
|
|
Use this to define an extension to the lsp find functions. An example from the c-c++ layer:
|
|
|
|
|
|
|
|
|
|
#+BEGIN_SRC elisp
|
|
|
|
|
(spacemacs/lsp-define-extensions "c-c++" 'refs-address
|
|
|
|
|
"textDocument/references"
|
|
|
|
|
'(plist-put (lsp--text-document-position-params) :context '(:role 128)))
|
|
|
|
|
#+END_SRC
|
|
|
|
|
|
|
|
|
|
This defines the following interactive functions:
|
|
|
|
|
- ~c-c++/find-refs-address~
|
|
|
|
|
- ~c-c++/peek-refs-address~
|
|
|
|
|
|
2018-11-22 10:56:35 +00:00
|
|
|
|
*** ~spacemacs/lsp-bind-extensions-for-mode~
|
2018-09-20 15:59:40 +00:00
|
|
|
|
Use this to bind one or more extensions under ~SPC m g~ and/or ~SPC m G~, as dictated by the value of ~lsp-navigation~.
|
|
|
|
|
Using another example from the c-c++ layer:
|
|
|
|
|
|
|
|
|
|
#+BEGIN_SRC elisp
|
|
|
|
|
(spacemacs/lsp-bind-extensions-for-mode mode "c-c++"
|
|
|
|
|
"&" 'refs-address
|
|
|
|
|
"R" 'refs-read
|
|
|
|
|
"W" 'refs-write
|
|
|
|
|
"c" 'callers
|
|
|
|
|
"C" 'callees
|
|
|
|
|
"v" 'vars)
|
|
|
|
|
#+END_SRC
|
|
|
|
|
|
|
|
|
|
With ~lsp-navigation~ set to ~'both~ (the default), this is equivalent to:
|
|
|
|
|
|
|
|
|
|
#+BEGIN_SRC elisp
|
|
|
|
|
(spacemacs/set-leader-keys-for-major-mode mode
|
|
|
|
|
"g&" 'c-c++/find-refs-address
|
|
|
|
|
"gR" 'c-c++/find-refs-read
|
|
|
|
|
"gW" 'c-c++/find-refs-write
|
|
|
|
|
"gc" 'c-c++/find-callers
|
|
|
|
|
"gC" 'c-c++/find-callees
|
|
|
|
|
"gv" 'c-c++/find-vars
|
|
|
|
|
"G&" 'c-c++/peek-refs-address
|
|
|
|
|
"GR" 'c-c++/peek-refs-read
|
|
|
|
|
"GW" 'c-c++/peek-refs-write
|
|
|
|
|
"Gc" 'c-c++/peek-callers
|
|
|
|
|
"GC" 'c-c++/peek-callees
|
|
|
|
|
"Gv" 'c-c++/peek-vars)
|
|
|
|
|
#+END_SRC
|
2018-11-08 20:21:30 +00:00
|
|
|
|
|
2018-09-20 15:59:40 +00:00
|
|
|
|
whereas with ~lsp-navigation~ set to ~'peek~, this is equivalent to:
|
|
|
|
|
|
|
|
|
|
#+BEGIN_SRC elisp
|
|
|
|
|
(spacemacs/set-leader-keys-for-major-mode mode
|
|
|
|
|
"g&" 'c-c++/peek-refs-address
|
|
|
|
|
"gR" 'c-c++/peek-refs-read
|
|
|
|
|
"gW" 'c-c++/peek-refs-write
|
|
|
|
|
"gc" 'c-c++/peek-callers
|
|
|
|
|
"gC" 'c-c++/peek-callees
|
|
|
|
|
"gv" 'c-c++/peek-vars)
|
|
|
|
|
#+END_SRC
|
|
|
|
|
|
|
|
|
|
etc.
|
|
|
|
|
|
2018-11-22 10:56:35 +00:00
|
|
|
|
* Diagnostics
|
2018-09-19 03:54:47 +00:00
|
|
|
|
If some features do not work as expected, here is a common check list.
|
2019-02-19 05:25:28 +00:00
|
|
|
|
- =M-x lsp-describe-session= If the LSP workspace is initialized correctly
|
2018-09-19 03:54:47 +00:00
|
|
|
|
- =M-: xref-backend-functions= should be =(lsp--xref-backend)= for cross
|
|
|
|
|
references
|
|
|
|
|
- =M-: completion-at-point-functions= should be =(lsp-completion-at-point)= for
|
|
|
|
|
completion
|
2018-01-21 20:27:33 +00:00
|
|
|
|
|
2018-03-16 00:38:24 +00:00
|
|
|
|
* References
|
2018-09-19 03:54:47 +00:00
|
|
|
|
- [[https://github.com/emacs-lsp/lsp-mode][lsp-mode repo]]
|
|
|
|
|
- [[https://github.com/emacs-lsp/lsp-ui][lsp-ui repo]]
|