2017-12-22 20:52:38 +08:00
|
|
|
---
|
|
|
|
title: "SpaceVim language server protocol layer"
|
|
|
|
description: "This layers provides language server protocol for vim and neovim"
|
|
|
|
---
|
|
|
|
|
2018-06-23 14:37:41 +08:00
|
|
|
# [Available Layers](../) >> lsp
|
2017-12-22 20:52:38 +08:00
|
|
|
|
|
|
|
<!-- vim-markdown-toc GFM -->
|
|
|
|
|
|
|
|
- [Description](#description)
|
|
|
|
- [Features](#features)
|
|
|
|
- [Install](#install)
|
2017-12-24 20:17:24 +08:00
|
|
|
- [Install language server](#install-language-server)
|
2017-12-22 20:52:38 +08:00
|
|
|
- [Configuration](#configuration)
|
|
|
|
- [Key bindings](#key-bindings)
|
|
|
|
|
|
|
|
<!-- vim-markdown-toc -->
|
|
|
|
|
|
|
|
## Description
|
|
|
|
|
2018-05-21 21:13:54 +08:00
|
|
|
This layers adds extensive support for [language-server-protocol](https://microsoft.github.io/language-server-protocol/),
|
|
|
|
This layer is a heavy wallpaper of [LanguageClient-neovim](https://github.com/SpaceVim/LanguageClient-neovim) (an old fork),
|
|
|
|
The upstream is rewritten by rust.
|
2017-12-23 15:34:37 +08:00
|
|
|
|
2019-03-26 18:40:30 +08:00
|
|
|
We also include [vim-lsp](https://github.com/prabirshrestha/vim-lsp), which is written in pure vim script.
|
2017-12-23 15:34:37 +08:00
|
|
|
|
2019-01-08 22:59:27 +08:00
|
|
|
Note that if `coc` is used as autocomplete method in the `autocomplete` layer,
|
|
|
|
it will be used as lsp client.
|
|
|
|
|
|
|
|
The neovim team is going to implement the build-in LSP support, the
|
2018-05-21 21:13:54 +08:00
|
|
|
PR is [neovim#6856](https://github.com/neovim/neovim/pull/6856). and the author of this PR
|
|
|
|
create another plugin [tjdevries/nvim-langserver-shim](https://github.com/tjdevries/nvim-langserver-shim)
|
2017-12-23 15:34:37 +08:00
|
|
|
|
|
|
|
SpaceVim should works well in different version of vim/neovim, so in the features, the logic of this layer should be:
|
|
|
|
|
|
|
|
```vim
|
|
|
|
if has('nvim')
|
|
|
|
" use neovim build-in lsp
|
2019-01-08 22:59:27 +08:00
|
|
|
if SpaceVim#layers#isLoaded("autocomplete") && get(g:, "spacevim_autocomplete_method") ==# 'coc'
|
|
|
|
" use coc.nvim
|
2017-12-23 15:34:37 +08:00
|
|
|
elseif has('python3')
|
|
|
|
" use LanguageClient-neovim
|
|
|
|
else
|
|
|
|
" use vim-lsp
|
|
|
|
endif
|
|
|
|
```
|
|
|
|
|
2017-12-22 20:52:38 +08:00
|
|
|
## Features
|
|
|
|
|
2017-12-23 15:34:37 +08:00
|
|
|
- Asynchronous calls
|
2018-10-02 15:26:01 +08:00
|
|
|
- Code completion (provided by [autocomplete](https://spacevim.org/layers/autocomplete/) layer)
|
2017-12-23 15:34:37 +08:00
|
|
|
- Lint on the fly
|
|
|
|
- Rename symbol
|
|
|
|
- Hover/Get identifer info.
|
|
|
|
- Goto definition.
|
|
|
|
- Goto reference locations.
|
|
|
|
- Workspace/Document symbols query.
|
|
|
|
- Formatting.
|
|
|
|
- Code Action/Fix.
|
|
|
|
|
2018-05-21 21:13:54 +08:00
|
|
|
**Note:** All these features dependent on the implementation of the language server, please
|
|
|
|
check the list of [Language Servers](https://microsoft.github.io/language-server-protocol/implementors/servers/)
|
2017-12-23 15:34:37 +08:00
|
|
|
|
2017-12-22 20:52:38 +08:00
|
|
|
## Install
|
|
|
|
|
2018-05-21 21:13:54 +08:00
|
|
|
To use this configuration layer, update custom configuration file with:
|
|
|
|
|
|
|
|
```toml
|
|
|
|
[[layers]]
|
|
|
|
name = "lsp"
|
|
|
|
```
|
2017-12-22 20:52:38 +08:00
|
|
|
|
2017-12-24 20:17:24 +08:00
|
|
|
### Install language server
|
|
|
|
|
2018-08-15 21:26:38 +08:00
|
|
|
**Bash**
|
|
|
|
|
|
|
|
```sh
|
|
|
|
npm i -g bash-language-server
|
|
|
|
```
|
|
|
|
|
2017-12-24 20:17:24 +08:00
|
|
|
**JavaScript:**
|
|
|
|
|
|
|
|
```sh
|
|
|
|
npm install -g javascript-typescript-langserver
|
|
|
|
```
|
|
|
|
|
|
|
|
**Python:**
|
|
|
|
|
|
|
|
```sh
|
|
|
|
pip install --user python-language-server
|
|
|
|
```
|
|
|
|
|
2018-08-14 10:04:37 +08:00
|
|
|
**julia:**
|
|
|
|
|
|
|
|
The `LanguageServer` package must be installed in Julia (0.6 or greater), i.e.
|
|
|
|
|
|
|
|
```sh
|
|
|
|
julia> Pkg.clone("https://github.com/JuliaEditorSupport/LanguageServer.jl")
|
|
|
|
```
|
|
|
|
|
|
|
|
With new package system in Julia 0.7 and above, we have a package mode in Julia REPL.
|
|
|
|
in REPL, hit `]` to enter the package management mode, then `add LanguageServer` to install the package.
|
|
|
|
|
2018-08-18 16:41:50 +08:00
|
|
|
**PureScript**
|
|
|
|
|
|
|
|
```sh
|
|
|
|
npm install -g purescript-language-server
|
|
|
|
```
|
|
|
|
|
2018-09-09 13:13:55 +08:00
|
|
|
**Vue:**
|
|
|
|
|
|
|
|
```sh
|
|
|
|
npm install vue-language-server -g
|
|
|
|
```
|
|
|
|
|
2019-01-29 23:27:59 +08:00
|
|
|
**css:**
|
|
|
|
|
|
|
|
```sh
|
|
|
|
npm install -g vscode-css-languageserver-bin
|
|
|
|
```
|
|
|
|
|
2019-02-26 01:18:21 +08:00
|
|
|
**ruby:**
|
|
|
|
|
|
|
|
```sh
|
|
|
|
gem install solargraph
|
|
|
|
```
|
|
|
|
|
2019-10-31 18:28:09 +08:00
|
|
|
**Elm:**
|
|
|
|
|
|
|
|
```sh
|
|
|
|
npm install -g @elm-tooling/elm-language-server
|
|
|
|
npm install -g elm elm-test elm-format
|
|
|
|
```
|
|
|
|
|
2017-12-22 20:52:38 +08:00
|
|
|
## Configuration
|
|
|
|
|
2020-02-22 09:44:21 +08:00
|
|
|
To enable lsp support for a specified filetype, you may need to load this layer with `filetypes` option, for example:
|
2017-12-22 20:52:38 +08:00
|
|
|
|
2018-05-21 21:13:54 +08:00
|
|
|
```toml
|
|
|
|
[[layers]]
|
|
|
|
name = "lsp"
|
|
|
|
filetypes = [
|
|
|
|
"rust",
|
|
|
|
"javascript"
|
|
|
|
]
|
2017-12-22 20:52:38 +08:00
|
|
|
```
|
|
|
|
|
2017-12-22 21:50:03 +08:00
|
|
|
default language server commands:
|
|
|
|
|
2018-08-15 21:26:38 +08:00
|
|
|
| language | server command |
|
|
|
|
| ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
|
|
| `c` | `['clangd']` |
|
|
|
|
| `cpp` | `['clangd']` |
|
2019-10-02 22:06:11 +08:00
|
|
|
| `crystal` | `['scry']` |
|
2019-01-29 23:27:59 +08:00
|
|
|
| `css` | `['css-languageserver', '--stdio']` |
|
|
|
|
| `dart` | `['dart_language_server']` |
|
2019-10-31 18:28:09 +08:00
|
|
|
| `elm` | `['elm-language-server']` |
|
2019-01-29 23:27:59 +08:00
|
|
|
| `go` | `['go-langserver', '-mode', 'stdio']` |
|
|
|
|
| `haskell` | `['hie', '--lsp']` |
|
2018-08-15 21:26:38 +08:00
|
|
|
| `html` | `['html-languageserver', '--stdio']` |
|
2019-01-29 23:27:59 +08:00
|
|
|
| `javascript` | `['javascript-typescript-stdio']` |
|
|
|
|
| `julia` | `['julia', '--startup-file=no', '--history-file=no', '-e', 'using LanguageServer; server = LanguageServer.LanguageServerInstance(STDIN, STDOUT, false); server.runlinter = true; run(server);']` |
|
2018-08-15 21:26:38 +08:00
|
|
|
| `objc` | `['clangd']` |
|
|
|
|
| `objcpp` | `['clangd']` |
|
|
|
|
| `php` | `['php', 'path/to/bin/php-language-server.php']` |
|
2018-08-18 16:41:50 +08:00
|
|
|
| `purescript` | `['purescript-language-server', '--stdio']` |
|
2019-01-29 23:27:59 +08:00
|
|
|
| `python` | `['pyls']` |
|
2019-04-28 20:44:47 +08:00
|
|
|
| `ruby` | `['solargraph', 'stdio']` |
|
2019-01-29 23:27:59 +08:00
|
|
|
| `rust` | `['rustup', 'run', 'nightly', 'rls']` |
|
|
|
|
| `sh` | `['bash-language-server', 'start']` |
|
|
|
|
| `typescript` | `['typescript-language-server', '--stdio']` |
|
2018-09-09 13:13:55 +08:00
|
|
|
| `vue` | `['vls']` |
|
2017-12-22 21:50:03 +08:00
|
|
|
|
|
|
|
To override the server command, you may need to use `override_cmd` option:
|
|
|
|
|
2018-05-21 21:13:54 +08:00
|
|
|
```toml
|
|
|
|
[[layers]]
|
|
|
|
name = "lsp"
|
|
|
|
filetypes = [
|
|
|
|
"rust",
|
|
|
|
"javascript"
|
|
|
|
]
|
|
|
|
[layers.override_cmd]
|
|
|
|
rust = ["rustup", "run", "nightly", "rls"]
|
2017-12-22 21:50:03 +08:00
|
|
|
```
|
|
|
|
|
2017-12-22 20:52:38 +08:00
|
|
|
## Key bindings
|
|
|
|
|
2017-12-23 15:10:00 +08:00
|
|
|
| Key Binding | Description |
|
|
|
|
| --------------- | ------------- |
|
|
|
|
| `K` / `SPC l d` | show document |
|
|
|
|
| `SPC l e` | rename symbol |
|
2019-04-28 20:44:47 +08:00
|
|
|
|
|
|
|
if the checkers layer is not loaded, these key bindings will be added:
|
|
|
|
|
|
|
|
| Key | description |
|
|
|
|
| --------- | ------------------------------------------------------------ |
|
|
|
|
| `SPC e c` | clear errors |
|
|
|
|
| `SPC e n` | jump to the position of next error |
|
|
|
|
| `SPC e N` | jump to the position of previous error |
|
|
|
|
| `SPC e p` | jump to the position of previous error |
|
|
|
|
| `SPC e l` | display a list of all the errors |
|
|
|
|
| `SPC e L` | display a list of all the errors and focus the errors buffer |
|