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
|
local lspconf = {
{
pattern = {"*.rs"},
options = {
name = 'rust-analyzer',
cmd = {'rustup', 'run', 'stable', 'rust-analyzer'},
root_dir = vim.fs.dirname(vim.fs.find({'Cargo.toml'}, { upward = true })[1]),
},
format = true,
}
}
for _, config in pairs(lspconf) do
vim.api.nvim_create_autocmd("BufEnter", {
pattern = config.pattern,
callback = function()
local client = vim.lsp.start(config.options)
vim.lsp.buf_attach_client(0, client)
end
})
if config.format then
vim.api.nvim_create_autocmd("BufWritePre", {
pattern = config.pattern,
callback = function()
vim.lsp.buf.format({ async = false })
end
})
end
end
vim.api.nvim_create_autocmd('LspAttach', {
callback = function(args)
vim.keymap.set('n', '<leader>ld', vim.lsp.buf.definition)
vim.keymap.set('n', '<leader>lr', vim.lsp.buf.references)
vim.keymap.set('n', '<leader>li', vim.lsp.buf.implementation)
vim.keymap.set('n', '<leader>lh', vim.lsp.buf.hover)
vim.keymap.set('n', '<leader>ls', vim.lsp.buf.signature_help)
vim.keymap.set('n', '<leader>lrn', vim.lsp.buf.rename)
end,
})
vim.opt.completeopt = {"menu"}
|