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', 'lua vim.lsp.buf.declaration()', opts) buf_set_keymap('n', 'gd', 'Telescope lsp_definitions', opts) buf_set_keymap('n', 'K', 'lua vim.lsp.buf.hover()', opts) buf_set_keymap('n', 'gr', 'Telescope lsp_references', 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 'lua require("telescope.builtin").' .. builtin .. '(' .. cursor_style ..')' end buf_set_keymap('n', 'sa', telescope_builtin('lsp_code_actions', cursor_style), opts) buf_set_keymap('n', 'se', 'lua vim.diagnostic.open_float()', opts) buf_set_keymap('n', 'sE', 'Telescope diagnostics', opts) buf_set_keymap('n', 'sl', 'lua vim.diagnostic.setloclist()', opts) buf_set_keymap('n', 'sq', 'lua vim.diagnostic.setqflist()', opts) buf_set_keymap('n', 'sr', 'lua vim.lsp.buf.rename()', opts) buf_set_keymap('n', 'ss', 'Telescope lsp_document_symbols', opts) buf_set_keymap('n', 'sS', 'Telescope lsp_workspace_symbols', opts) buf_set_keymap('n', '[d', 'lua vim.diagnostic.goto_prev()', opts) buf_set_keymap('n', ']d', 'lua vim.diagnostic.goto_next()', opts) -- Capability specific -- print(vim.inspect(client.resolved_capabilities)) if client.resolved_capabilities.document_formatting then buf_set_keymap("n", "sf", "lua vim.lsp.buf.formatting()", opts) end if client.resolved_capabilities.document_range_formatting then buf_set_keymap("v", "sf", "lua vim.lsp.buf.range_formatting()", opts) end -- Rust specific buf_set_keymap("n", "sh", "RustToggleInlayHints", 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, })