-
Notifications
You must be signed in to change notification settings - Fork 54
/
lsp.lua
316 lines (283 loc) · 10.1 KB
/
lsp.lua
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
local ms = vim.lsp.protocol.Methods
local handlers = require 'misc.handlers'
return {
{
-- for lsp features in code cells / embedded code
'jmbuhr/otter.nvim',
dev = false,
dependencies = {
{
'neovim/nvim-lspconfig',
'nvim-treesitter/nvim-treesitter',
},
},
opts = {},
},
{
'neovim/nvim-lspconfig',
dependencies = {
{ 'williamboman/mason.nvim' },
{ 'williamboman/mason-lspconfig.nvim' },
{ 'WhoIsSethDaniel/mason-tool-installer.nvim' },
{ -- nice loading notifications
-- PERF: but can slow down startup
'j-hui/fidget.nvim',
enabled = false,
opts = {},
},
{
{
'folke/lazydev.nvim',
ft = 'lua', -- only load on lua files
opts = {
library = {
-- See the configuration section for more details
-- Load luvit types when the `vim.uv` word is found
{ path = 'luvit-meta/library', words = { 'vim%.uv' } },
},
},
},
{ 'Bilal2453/luvit-meta', lazy = true }, -- optional `vim.uv` typings
{ -- optional completion source for require statements and module annotations
'hrsh7th/nvim-cmp',
opts = function(_, opts)
opts.sources = opts.sources or {}
table.insert(opts.sources, {
name = 'lazydev',
group_index = 0, -- set group index to 0 to skip loading LuaLS completions
})
end,
},
-- { "folke/neodev.nvim", enabled = false }, -- make sure to uninstall or disable neodev.nvim
},
{ 'folke/neoconf.nvim', opts = {}, enabled = false },
},
config = function()
local lspconfig = require 'lspconfig'
local util = require 'lspconfig.util'
require('mason').setup()
require('mason-lspconfig').setup {
automatic_installation = true,
}
require('mason-tool-installer').setup {
ensure_installed = {
'black',
'stylua',
'shfmt',
'isort',
'tree-sitter-cli',
'jupytext',
},
}
vim.api.nvim_create_autocmd('LspAttach', {
group = vim.api.nvim_create_augroup('kickstart-lsp-attach', { clear = true }),
callback = function(event)
local function map(keys, func, desc)
vim.keymap.set('n', keys, func, { buffer = event.buf, desc = 'LSP: ' .. desc })
end
local function vmap(keys, func, desc)
vim.keymap.set('v', keys, func, { buffer = event.buf, desc = 'LSP: ' .. desc })
end
local client = vim.lsp.get_client_by_id(event.data.client_id)
assert(client, 'LSP client not found')
---@diagnostic disable-next-line: inject-field
client.server_capabilities.document_formatting = true
map('gS', vim.lsp.buf.document_symbol, '[g]o so [S]ymbols')
map('gD', vim.lsp.buf.type_definition, '[g]o to type [D]efinition')
map('gd', vim.lsp.buf.definition, '[g]o to [d]efinition')
map('K', vim.lsp.buf.hover, '[K] hover documentation')
map('gh', vim.lsp.buf.signature_help, '[g]o to signature [h]elp')
map('gI', vim.lsp.buf.implementation, '[g]o to [I]mplementation')
map('gr', vim.lsp.buf.references, '[g]o to [r]eferences')
map('[d', vim.diagnostic.goto_prev, 'previous [d]iagnostic ')
map(']d', vim.diagnostic.goto_next, 'next [d]iagnostic ')
map('<leader>ll', vim.lsp.codelens.run, '[l]ens run')
map('<leader>lR', vim.lsp.buf.rename, '[l]sp [R]ename')
map('<leader>lf', vim.lsp.buf.format, '[l]sp [f]ormat')
vmap('<leader>lf', vim.lsp.buf.format, '[l]sp [f]ormat')
map('<leader>lq', vim.diagnostic.setqflist, '[l]sp diagnostic [q]uickfix')
end,
})
local lsp_flags = {
allow_incremental_sync = true,
debounce_text_changes = 150,
}
vim.lsp.handlers['textDocument/hover'] = vim.lsp.with(vim.lsp.handlers.hover, { border = require('misc.style').border })
vim.lsp.handlers['textDocument/signatureHelp'] = vim.lsp.with(vim.lsp.handlers.signature_help, { border = require('misc.style').border })
vim.lsp.handlers[ms.textDocument_definition] = handlers.telescope_handler_factory(ms.textDocument_definition, "Definition")
vim.lsp.handlers[ms.textDocument_typeDefinition] = handlers.telescope_handler_factory(ms.textDocument_typeDefinition, "Type Definition")
vim.lsp.handlers[ms.textDocument_references] = handlers.telescope_handler_factory(ms.textDocument_references, "References")
vim.lsp.handlers[ms.textDocument_implementation] = handlers.telescope_handler_factory(ms.textDocument_implementation, "Implementations")
vim.lsp.handlers[ms.textDocument_documentSymbol] = handlers.telescope_handler_factory(ms.textDocument_documentSymbol, "Document Symbols")
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = vim.tbl_deep_extend('force', capabilities, require('cmp_nvim_lsp').default_capabilities())
capabilities.textDocument.completion.completionItem.snippetSupport = true
-- also needs:
-- $home/.config/marksman/config.toml :
-- [core]
-- markdown.file_extensions = ["md", "markdown", "qmd"]
lspconfig.marksman.setup {
capabilities = capabilities,
filetypes = { 'markdown', 'quarto' },
root_dir = util.root_pattern('.git', '.marksman.toml', '_quarto.yml'),
}
lspconfig.r_language_server.setup {
capabilities = capabilities,
flags = lsp_flags,
settings = {
r = {
lsp = {
rich_documentation = false,
},
},
},
}
lspconfig.cssls.setup {
capabilities = capabilities,
flags = lsp_flags,
}
lspconfig.html.setup {
capabilities = capabilities,
flags = lsp_flags,
}
lspconfig.emmet_language_server.setup {
capabilities = capabilities,
flags = lsp_flags,
}
lspconfig.yamlls.setup {
capabilities = capabilities,
flags = lsp_flags,
settings = {
yaml = {
schemaStore = {
enable = true,
url = '',
},
},
},
}
lspconfig.jsonls.setup {
capabilities = capabilities,
flags = lsp_flags,
}
lspconfig.dotls.setup {
capabilities = capabilities,
flags = lsp_flags,
}
lspconfig.tsserver.setup {
capabilities = capabilities,
flags = lsp_flags,
filetypes = { 'js', 'javascript', 'typescript', 'ojs' },
}
local function get_quarto_resource_path()
local function strsplit(s, delimiter)
local result = {}
for match in (s .. delimiter):gmatch('(.-)' .. delimiter) do
table.insert(result, match)
end
return result
end
local f = assert(io.popen('quarto --paths', 'r'))
local s = assert(f:read '*a')
f:close()
return strsplit(s, '\n')[2]
end
local lua_library_files = vim.api.nvim_get_runtime_file('', true)
local lua_plugin_paths = {}
local resource_path = get_quarto_resource_path()
if resource_path == nil then
vim.notify_once 'quarto not found, lua library files not loaded'
else
table.insert(lua_library_files, resource_path .. '/lua-types')
table.insert(lua_plugin_paths, resource_path .. '/lua-plugin/plugin.lua')
end
lspconfig.lua_ls.setup {
capabilities = capabilities,
flags = lsp_flags,
settings = {
Lua = {
completion = {
callSnippet = 'Replace',
},
runtime = {
version = 'LuaJIT',
-- plugin = lua_plugin_paths,
},
diagnostics = {
disable = { 'trailing-space' },
},
workspace = {
-- library = lua_library_files,
checkThirdParty = false,
},
doc = {
privateName = { '^_' },
},
telemetry = {
enable = false,
},
},
},
}
lspconfig.julials.setup {
capabilities = capabilities,
flags = lsp_flags,
}
lspconfig.bashls.setup {
capabilities = capabilities,
flags = lsp_flags,
filetypes = { 'sh', 'bash' },
}
-- Add additional languages here.
-- See `:h lspconfig-all` for the configuration.
-- Like e.g. Haskell:
-- lspconfig.hls.setup {
-- capabilities = capabilities,
-- flags = lsp_flags
-- }
-- lspconfig.clangd.setup {
-- capabilities = capabilities,
-- flags = lsp_flags,
-- }
-- lspconfig.rust_analyzer.setup{
-- capabilities = capabilities,
-- settings = {
-- ['rust-analyzer'] = {
-- diagnostics = {
-- enable = false;
-- }
-- }
-- }
-- }
-- lspconfig.ruff_lsp.setup {
-- capabilities = capabilities,
-- flags = lsp_flags,
-- }
-- See https://github.com/neovim/neovim/issues/23291
-- disable lsp watcher.
-- Too lags on linux for python projects
-- because pyright and nvim both create too many watchers otherwise
if capabilities.workspace == nil then
capabilities.workspace = {}
capabilities.workspace.didChangeWatchedFiles = {}
end
capabilities.workspace.didChangeWatchedFiles.dynamicRegistration = false
lspconfig.pyright.setup {
capabilities = capabilities,
flags = lsp_flags,
settings = {
python = {
analysis = {
autoSearchPaths = true,
useLibraryCodeForTypes = true,
diagnosticMode = 'workspace',
},
},
},
root_dir = function(fname)
return util.root_pattern('.git', 'setup.py', 'setup.cfg', 'pyproject.toml', 'requirements.txt')(fname) or util.path.dirname(fname)
end,
}
end,
},
}