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
|
local lspconfig = require("lspconfig")
local function on_attach(client, bufnr)
local function buf_set_keymap(...)
vim.api.nvim_buf_set_keymap(bufnr, ...)
end
local opts = { noremap = true, silent = true }
buf_set_keymap('n', 'gD', '<Cmd>lua vim.lsp.buf.declaration()<CR>', opts)
buf_set_keymap('n', 'gd', '<Cmd>Telescope lsp_definitions<CR>', opts)
buf_set_keymap('n', 'K', '<Cmd>lua vim.lsp.buf.hover()<CR>', opts)
buf_set_keymap('n', 'gr', '<cmd>Telescope lsp_references<CR>', opts)
-- TODO: replace these with vim.keymap.set once neovim 0.7 is out
local cursor_style = [[require("telescope.themes").get_dropdown()]]
local function telescope_builtin(builtin, style)
if not style then
style = ""
end
return '<cmd>lua require("telescope.builtin").' .. builtin .. '(' .. cursor_style ..')<CR>'
end
buf_set_keymap('n', '<leader>sa', telescope_builtin('lsp_code_actions', cursor_style), opts)
buf_set_keymap('n', '<leader>se', '<cmd>lua vim.diagnostic.open_float()<CR>', opts)
buf_set_keymap('n', '<leader>sE', '<cmd>Telescope diagnostics<CR>', opts)
buf_set_keymap('n', '<leader>sl', '<cmd>lua vim.diagnostic.setloclist()<CR>', opts)
buf_set_keymap('n', '<leader>sq', '<cmd>lua vim.diagnostic.setqflist()<CR>', opts)
buf_set_keymap('n', '<leader>sr', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
buf_set_keymap('n', '<leader>ss', '<cmd>Telescope lsp_document_symbols<CR>', opts)
buf_set_keymap('n', '<leader>sS', '<cmd>Telescope lsp_workspace_symbols<CR>', opts)
buf_set_keymap('n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<CR>', opts)
buf_set_keymap('n', ']d', '<cmd>lua vim.diagnostic.goto_next()<CR>', opts)
-- Capability specific
-- print(vim.inspect(client.resolved_capabilities))
if client.resolved_capabilities.document_formatting then
buf_set_keymap("n", "<leader>sf", "<cmd>lua vim.lsp.buf.formatting()<CR>", opts)
end
if client.resolved_capabilities.document_range_formatting then
buf_set_keymap("v", "<leader>sf", "<cmd>lua vim.lsp.buf.range_formatting()<CR>", opts)
end
-- Rust specific
buf_set_keymap("n", "<leader>sh", "<cmd>RustToggleInlayHints<CR>", opts)
require("lsp_signature").on_attach({
hint_prefix = "param: "
})
end
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities.textDocument.completion.completionItem.snippetSupport = true
capabilities.textDocument.completion.completionItem.resolveSupport = {
properties = {
'documentation',
'detail',
'additionalTextEdits',
}
}
require("rust-tools").setup {
server = {
cmd = { vim.g.rust_analyzer_path },
settings = {
["rust-analyzer"] = {
checkOnSave = {
command = "clippy",
},
experimental = {
procAttrMacros = true,
},
},
},
on_attach = on_attach,
}
}
require("nlua.lsp.nvim").setup(lspconfig, {
cmd = {
string.format("%s/bin/lua-language-server", vim.g.sumneko_lua_base_path),
"-E",
string.format("%s/share/lua-language-server/main.lua", vim.g.sumneko_lua_base_path),
},
on_attach = on_attach,
})
|