1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
|
# Custom servers
You may create your own server installers by using the same APIs that nvim-lsp-installer itself uses.
Each installable LSP server is represented as an instance of the `Server` class. This class is responsible for
containing all information required to both 1) install the server, and 2) set up the server through `lspconfig`. Refer
to the [Lua docs](./lua/nvim-lsp-installer/server.lua) for more details.
# Installers
Each `Server` instance must provide an `installer` property. This _must_ be a function with the signature `function (server, callback)`, where `server` is the server instance that is being installed, and `callback` is a function that
_must_ be called upon completion (successful or not) by the installer implementation.
Most likely, nvim-lsp-installer already have the installer implementations you'd need. You may find the available installers below.
## Core installers
- ### Go
#### `go.packages(packages: table)`
Returns an installer that installs the provided list of `packages`.
Example:
```lua
local go = require "nvim-lsp-installer.installers.go"
local installer = go.packages { "golang.org/x/tools/gopls@latest" }
```
#### `go.executable(root_dir: string, executable: string)`
Returns the absolute path to an `executable` that was installed via `go.packages()`. `root_dir` should be the same as
the root_dir provided to the relevant server instance.
- ### npm
#### `npm3.packages(packages: table)`
Returns an installer that installs the provided list of `packages`.
Example:
```lua
local npm = require "nvim-lsp-installer.installers.npm"
local installer = npm.packages { "graphql-language-service-cli", "graphql" },
```
#### `npm.executable(root_dir: string, executable: string)`
Returns the absolute path to an `executable` that was installed via `npm.packages()`. `root_dir` should be the same as
the root_dir provided to the relevant server instance.
- ### pip3
#### `pip3.packages(packages: table)`
Returns an installer that installs the provided list of `packages`.
Example:
```lua
local pip3 = require "nvim-lsp-installer.installers.pip3"
local installer = pip3.packages { "python-lsp-server[all]" }
```
#### `pip3.executable(root_dir: string, executable: string)`
Returns the absolute path to an `executable` that was installed via `pip3.packages()`. `root_dir` should be the same as
the root_dir provided to the relevant server instance.
- ### Shell
#### `shell.raw(raw_script: string, opts?: table)`
Returns an installer that runs the provided `raw_script` in a new terminal window.
Runs as a bash script (`/bin/bash`).
`opts` is an optional table, with the following defaults:
- `prefix = "set -euo pipefail;"` - Prefix added to the beginning of the script.
- `env = nil` - A table (dict) with environment variables to be set in the shell.
Example:
```lua
local shell = require "nvim-lsp-installer.installers.shell"
shell.raw [[
curl -fLO https://github.com/fwcd/kotlin-language-server/releases/latest/download/server.zip;
unzip server.zip;
rm server.zip;
]]
```
#### `shell.remote(url: string, opts?: table)`
Returns an installer that downloads the content at `url` and executes its content by passing it to the `shell.raw()`
installer.
`opts` is an optional table, with the following defaults:
- `prefix = "set -euo pipefail;"` - Prefix added to the beginning of the script.
- `env = nil` - A table (dict) with environment variables to be set in the shell.
Example:
```lua
local shell = require "nvim-lsp-installer.installers.shell"
shell.remote("https://raw.githubusercontent.com/my_server/my_server_lsp/install.sh", {
env = {
MY_ENV = "true"
}
})
```
- ### zx
[zx](https://github.com/google/zx) is a tool for writing better scripts. It's a suitable install method for servers
that for example have many different steps or branches into different steps depending on some logic.
#### `zx.file(relpath: string)`
Returns an installer that executes the provided file as a `zx` script. `relpath` is the relative path (of the current
Lua file) to the script file.
Example:
```lua
local zx = require "nvim-lsp-installer.installers.zx"
local installer = zx.file("./install.mjs")
```
## Composing installers
You may compose multiple different installers into one. This allows you to break down your installers into smaller
units.
Example:
```lua
local installers = require "nvim-lsp-installer.installers"
local shell = require "nvim-lsp-installer.installers.shell"
installers.compose {
shell.raw [[ echo "I won't run at all because the previous installer failed." ]],
shell.raw [[ exit 1 ]],
pip3.packages { "another-package" },
npm.packages { "some-package" },
}
```
## Full Example
The following is a full example of setting up a completely custom server installer, which in this example we call `my_server`.
```lua
local lspconfig = require "lspconfig"
local configs = require "lspconfig/configs"
local lsp_installer = require "nvim-lsp-installer"
local server = require "nvim-lsp-installer.server"
local path = require "nvim-lsp-installer.path"
local server_name = "my_server"
-- 1. (optional, only if lspconfig doesn't already support the server)
-- Create server entry in lspconfig
configs[server_name] = {
default_config = {
filetypes = { "lua" },
root_dir = lspconfig.util.root_pattern ".git",
},
}
local root_dir = server.get_server_root_path(server_name)
-- You may also use one of the prebuilt installers (e.g., npm, pip3, go, shell, zx).
local my_installer = function(server, callback)
local is_success = code_that_installs_given_server(server)
if is_success then
callback(true, nil)
else
callback(false, "Error message here.")
end
end
-- 2. (mandatory) Create an nvim-lsp-installer Server instance
local my_server = server.Server:new {
name = server_name,
root_dir = root_dir,
installer = my_installer,
default_options = {
cmd = { path.concat { root_dir, "my_server_lsp" }, "--langserver" },
},
}
-- 3. (optional, recommended) Register your server with nvim-lsp-installer.
-- This makes it available via other APIs (e.g., :LspInstall, lsp_installer.get_available_servers()).
lsp_installer.register(my_server)
```
|