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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
|
-- lspconfig + nvim-cmp + lspsaga
-- Dependencies
-- nvim-lspconfig
-- nvim-cmp
-- cmp-buffer
-- cmp-path
-- cmp_luasnip
-- cmp-nvim-lsp
-- LuaSnip
-- friendly-snippets
local fn = vim.fn
local api = vim.api
local keymap = vim.keymap
local lsp = vim.lsp
local utils = require("utils")
local custom_attach = function(client, bufnr)
-- Mappings.
local map = function(mode, l, r, opts)
opts = opts or {}
opts.silent = true
opts.buffer = bufnr
keymap.set(mode, l, r, opts)
end
local lsp_defaults = {
flags = {
debounce_text_changes = 150, -- Amount of miliseconds neovim will wait to send the next document update notification.
},
-- The data on this option is send to the server, to announce what features the editor can support.
capabilities = require("cmp_nvim_lsp").update_capabilities(vim.lsp.protocol.make_client_capabilities()),
on_attach = function(client, bufnr)
vim.api.nvim_exec_autocmds("User", { pattern = "LspAttached" })
end,
}
local lspconfig = require('lspconfig')
lspconfig.util.default_config = vim.tbl_deep_extend(
'force',
lspconfig.util.default_config,
lsp_defaults
)
---
-- LSP Servers
---
if utils.executable("pylsp") then
lspconfig.pylsp.setup {
on_attach = custom_attach,
settings = {
pylsp = {
plugins = {
pylint = { enabled = true, executable = "pylint" },
pyflakes = { enabled = false },
pycodestyle = { enabled = false },
jedi_completion = { fuzzy = true },
pyls_isort = { enabled = true },
pylsp_mypy = { enabled = true },
},
},
},
flags = {
debounce_text_changes = 200,
},
capabilities = capabilities,
}
else
vim.notify("pylsp not found!", vim.log.levels.WARN, { title = "Nvim-config" })
end
-- if utils.executable('pyright') then
-- lspconfig.pyright.setup{
-- on_attach = custom_attach,
-- capabilities = capabilities
-- }
-- else
-- vim.notify("pyright not found!", vim.log.levels.WARN, {title = 'Nvim-config'})
-- end
if utils.executable("clangd") then
lspconfig.clangd.setup {
on_attach = custom_attach,
capabilities = capabilities,
filetypes = { "c", "cpp", "cc" },
flags = {
debounce_text_changes = 500,
},
}
else
vim.notify("clangd not found!", vim.log.levels.WARN, { title = "Nvim-config" })
end
-- set up vim-language-server
if utils.executable("vim-language-server") then
lspconfig.vimls.setup {
on_attach = custom_attach,
flags = {
debounce_text_changes = 500,
},
capabilities = capabilities,
}
else
vim.notify("vim-language-server not found!", vim.log.levels.WARN, { title = "Nvim-config" })
end
-- set up bash-language-server
if utils.executable("bash-language-server") then
lspconfig.bashls.setup {
on_attach = custom_attach,
capabilities = capabilities,
}
end
if utils.executable("lua-language-server") then
-- settings for lua-language-server can be found on https://github.com/sumneko/lua-language-server/wiki/Settings .
lspconfig.sumneko_lua.setup {
on_attach = custom_attach,
settings = {
Lua = {
runtime = {
-- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
version = "LuaJIT",
},
diagnostics = {
-- Get the language server to recognize the `vim` global
globals = { "vim" },
},
workspace = {
-- Make the server aware of Neovim runtime files,
-- see also https://github.com/sumneko/lua-language-server/wiki/Libraries#link-to-workspace .
-- Lua-dev.nvim also has similar settings for sumneko lua, https://github.com/folke/lua-dev.nvim/blob/main/lua/lua-dev/sumneko.lua .
library = {
fn.stdpath("data") .. "/site/pack/packer/opt/emmylua-nvim",
fn.stdpath("config"),
},
maxPreload = 2000,
preloadFileSize = 50000,
},
},
},
capabilities = capabilities,
}
end
-- Lua
lspconfig.sumneko_lua.setup({
settings = {
Lua = {
runtime = {
-- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
version = 'LuaJIT',
},
diagnostics = {
-- Get the language server to recognize the `vim` global
globals = {'vim'},
},
workspace = {
-- Make the server aware of Neovim runtime files
library = vim.api.nvim_get_runtime_file("", true),
},
-- Do not send telemetry data containing a randomized but unique identifier
telemetry = {
enable = false,
},
},
},
single_file_support = true,
on_attach = function(client, bufnr)
print('hello')
lspconfig.util.default_config.on_attach(client, bufnr)
end
})
lspconfig.sumneko_lua.setup({
on_attach = custom_attach,
settings = {
Lua = {
runtime = {
-- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
version = "LuaJIT",
-- Setup your lua path
path = runtime_path,
},
diagnostics = {
-- Get the language server to recognize the `vim` global
globals = { "vim" },
},
workspace = {
-- Make the server aware of Neovim runtime files
library = api.nvim_get_runtime_file("", true),
},
-- Do not send telemetry data containing a randomized but unique identifier
telemetry = {
enable = false,
},
},
},
})
lspconfig.sumneko_lua.setup {
on_attach = custom_attach,
settings = {
Lua = {
runtime = {
-- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
version = "LuaJIT",
},
diagnostics = {
-- Get the language server to recognize the `vim` global
globals = { "vim" },
},
workspace = {
-- Make the server aware of Neovim runtime files,
-- see also https://github.com/sumneko/lua-language-server/wiki/Libraries#link-to-workspace .
-- Lua-dev.nvim also has similar settings for sumneko lua, https://github.com/folke/lua-dev.nvim/blob/main/lua/lua-dev/sumneko.lua .
library = {
fn.stdpath("data") .. "/site/pack/packer/opt/emmylua-nvim",
fn.stdpath("config"),
},
maxPreload = 2000,
preloadFileSize = 50000,
},
},
},
capabilities = capabilities,
}
require'lspconfig'.sumneko_lua.setup {
settings = {
Lua = {
runtime = {
-- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
version = 'LuaJIT',
},
diagnostics = {
-- Get the language server to recognize the `vim` global
globals = {'vim'},
},
workspace = {
-- Make the server aware of Neovim runtime files
library = vim.api.nvim_get_runtime_file("", true),
},
-- Do not send telemetry data containing a randomized but unique identifier
telemetry = {
enable = false,
},
},
},
}
require'lspconfig'.sumneko_lua.setup{}
**Default values:**
- `cmd` :
{ "lua-language-server" }
- `filetypes` :
- `log_level` :
```lua
2
```
- `root_dir` :
```lua
root_pattern(".luarc.json", ".luacheckrc", ".stylua.toml", "stylua.toml", "selene.toml", ".git")
```
- `settings` :
```lua
{
Lua = {
telemetry = {
enable = false
}
}
}
- `single_file_support` :
true
**Snippet to enable the language server:**
```lua
require'lspconfig'.ccls.setup{}
```
**Default values:**
- `cmd` :
```lua
{ "ccls" }
```
- `filetypes` :
```lua
{ "c", "cpp", "objc", "objcpp" }
```
- `offset_encoding` :
```lua
"utf-32"
```
- `root_dir` :
```lua
root_pattern('compile_commands.json', '.ccls', '.git')
```
- `single_file_support` :
```lua
false
```
**Snippet to enable the language server:**
```lua
require'lspconfig'.clangd.setup{}
```
**Commands:**
- ClangdSwitchSourceHeader: Switch between source/header
**Default values:**
- `capabilities` :
```lua
default capabilities, with offsetEncoding utf-8
```
- `cmd` :
```lua
{ "clangd" }
```
- `filetypes` :
```lua
{ "c", "cpp", "objc", "objcpp", "cuda", "proto" }
```
- `root_dir` :
```lua
root_pattern(
'.clangd',
'.clang-tidy',
'.clang-format',
'compile_commands.json',
'compile_flags.txt',
'configure.ac',
'.git'
)
```
- `single_file_support` :
```lua
true
```
**Snippet to enable the language server:**
```lua
require'lspconfig'.pyright.setup{}
```
**Commands:**
- PyrightOrganizeImports: Organize Imports
**Default values:**
- `cmd` :
```lua
{ "pyright-langserver", "--stdio" }
```
- `filetypes` :
```lua
{ "python" }
```
- `root_dir` :
```lua
see source file
```
- `settings` :
```lua
{
python = {
analysis = {
autoSearchPaths = true,
diagnosticMode = "workspace",
useLibraryCodeForTypes = true
}
}
}
```
- `single_file_support` :
```lua
true
```
## rls
https://github.com/rust-lang/rls
rls, a language server for Rust
See https://github.com/rust-lang/rls#setup to setup rls itself.
See https://github.com/rust-lang/rls#configuration for rls-specific settings.
All settings listed on the rls configuration section of the readme
must be set under settings.rust as follows:
```lua
nvim_lsp.rls.setup {
settings = {
rust = {
unstable_features = true,
build_on_save = false,
all_features = true,
},
},
}
```
If you want to use rls for a particular build, eg nightly, set cmd as follows:
```lua
cmd = {"rustup", "run", "nightly", "rls"}
```
**Snippet to enable the language server:**
```lua
require'lspconfig'.rls.setup{}
```
**Default values:**
- `cmd` :
```lua
{ "rls" }
```
- `filetypes` :
```lua
{ "rust" }
```
- `root_dir` :
```lua
root_pattern("Cargo.toml")
```
## rust_analyzer
https://github.com/rust-analyzer/rust-analyzer
rust-analyzer (aka rls 2.0), a language server for Rust
See [docs](https://github.com/rust-analyzer/rust-analyzer/tree/master/docs/user#settings) for extra settings.
**Snippet to enable the language server:**
```lua
require'lspconfig'.rust_analyzer.setup{}
```
**Commands:**
- CargoReload: Reload current cargo workspace
**Default values:**
- `cmd` :
```lua
{ "rust-analyzer" }
```
- `filetypes` :
```lua
{ "rust" }
```
- `root_dir` :
```lua
root_pattern("Cargo.toml", "rust-project.json")
```
- `settings` :
```lua
{
["rust-analyzer"] = {}
}
```
## rust_analyzer
https://github.com/rust-analyzer/rust-analyzer
rust-analyzer (aka rls 2.0), a language server for Rust
See [docs](https://github.com/rust-analyzer/rust-analyzer/tree/master/docs/user#settings) for extra settings.
**Snippet to enable the language server:**
```lua
require'lspconfig'.rust_analyzer.setup{}
```
**Commands:**
- CargoReload: Reload current cargo workspace
**Default values:**
- `cmd` :
```lua
{ "rust-analyzer" }
```
- `filetypes` :
```lua
{ "rust" }
```
- `root_dir` :
```lua
root_pattern("Cargo.toml", "rust-project.json")
```
- `settings` :
```lua
{
["rust-analyzer"] = {}
}
```
|