mason-lspconfig.lua (5858B)
1 local mason_lspconfig = require 'mason-lspconfig' 2 -- Enable the following language servers 3 -- Feel free to add/remove any LSPs that you want here. They will automatically be installed. 4 -- https://github.com/williamboman/mason-lspconfig.nvim/blob/main/doc/server-mapping.md 5 -- Add any additional override configuration in the following tables. They will be passed to 6 -- the `settings` field of the server config. You must look up that documentation yourself. 7 local servers = { 8 ansiblels = {}, 9 lua_ls = { 10 ['Lua'] = { 11 runtime = { 12 -- Tell the language server which version of Lua you're using 13 -- (most likely LuaJIT in the case of Neovim) 14 version = 'LuaJIT', 15 }, 16 diagnostics = { 17 -- Get the language server to recognize the `vim` global 18 globals = { 19 'vim', 20 'require' 21 }, 22 }, 23 workspace = { 24 -- Make the server aware of Neovim runtime files 25 library = vim.api.nvim_get_runtime_file("", true), 26 }, 27 -- Do not send telemetry data containing a randomized but unique identifier 28 telemetry = { 29 enable = false, 30 }, 31 } 32 }, 33 docker_compose_language_service = {}, 34 rust_analyzer = { 35 ['rust-analyzer'] = { 36 cargo = { 37 allFeatures = true, 38 loadOutDirsFromCheck = true, 39 runBuildScripts = true, 40 -- extraEnv = { 41 -- RUSTFLAGS = "--cfg tokio_unstable", 42 -- }, 43 }, 44 -- Add clippy lints for Rust. 45 checkOnSave = { 46 allFeatures = true, 47 command = "clippy", 48 extraArgs = { 49 -- "--no-deps", 50 "--", 51 "-D", "clippy::pedantic", 52 "-D", "clippy::nursery", 53 "-D", "clippy::restriction", 54 "-A", "clippy::blanket_clippy_restriction_lints", 55 "-A", "clippy::missing_docs_in_private_items", 56 "-A", "clippy::implicit_return", 57 "-A", "clippy::question_mark_used", 58 "-A", "clippy::min_ident_chars", 59 "-A", "clippy::pattern_type_mismatch", 60 "-A", "clippy::single_call_fn", 61 "-A", "clippy::as_conversions", 62 "-A", "clippy::pub_with_shorthand", 63 "-A", "clippy::shadow_reuse", 64 "-A", "clippy::separated_literal_suffix", 65 "-A", "clippy::float_arithmetic", 66 "-A", "clippy::pub_use", 67 "-A", "clippy::single_char_lifetime_names", 68 "-A", "clippy::missing_trait_methods", 69 "-A", "clippy::multiple_unsafe_ops_per_block", -- broken on 0.1.74 70 "-A", "clippy::mod_module_files", 71 "-A", "clippy::std_instead_of_alloc", 72 "-A", "clippy::integer_division_remainder_used", 73 "-D", "rust_2018_idioms", 74 "-D", "missing_docs", 75 "-D", "warnings", 76 "-A", "clippy::too_many_lines" 77 }, 78 --[[ 79 command = "check", 80 ]] 81 -- extraArgs = { "--no-deps" }, 82 }, 83 procMacro = { 84 enable = true, 85 ignored = { 86 ["async-trait"] = { "async_trait" }, 87 ["napi-derive"] = { "napi" }, 88 ["async-recursion"] = { "async_recursion" }, 89 }, 90 }, 91 }, 92 }, 93 pyright = {}, 94 rubocop = {}, 95 -- solargraph = {}, 96 -- bashls = {}, 97 -- jdtls = {}, 98 -- jsonls = {}, 99 -- texlab = {}, 100 -- clangd = {}, 101 -- perlnavigator = {}, 102 } 103 104 105 mason_lspconfig.setup { 106 ensure_installed = vim.tbl_keys(servers), 107 } 108 109 -- LSP settings. 110 -- This function gets run when an LSP connects to a particular buffer. 111 local on_attach = function(_, bufnr) 112 -- NOTE: Remember that lua is a real programming language, and as such it is possible 113 -- to define small helper and utility functions so you don't have to repeat yourself 114 -- many times. 115 -- 116 -- In this case, we create a function that lets us more easily define mappings specific 117 -- for LSP related items. It sets the mode, buffer and description for us each time. 118 local nmap = function(keys, func, desc) 119 if desc then 120 desc = 'LSP: ' .. desc 121 end 122 123 vim.keymap.set('n', keys, func, { buffer = bufnr, desc = desc }) 124 end 125 126 nmap('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame') 127 nmap('<leader>ra', vim.lsp.buf.code_action, '[C]ode [A]ction') 128 vim.keymap.set('v', '<leader>ra', vim.lsp.buf.code_action, { buffer = bufnr, desc = '[C]ode [A]ction' }) 129 130 nmap('gd', vim.lsp.buf.definition, '[G]oto [D]efinition') 131 nmap('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences') 132 nmap('gI', vim.lsp.buf.implementation, '[G]oto [I]mplementation') 133 nmap('<leader>D', vim.lsp.buf.type_definition, 'Type [D]efinition') 134 nmap('<leader>ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols') 135 nmap('<leader>ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols') 136 137 -- See `:help K` for why this keymap 138 nmap('K', vim.lsp.buf.hover, 'Hover Documentation') 139 nmap('<leader>K', vim.lsp.buf.signature_help, 'Signature Documentation') 140 141 -- Lesser used LSP functionality 142 nmap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration') 143 nmap('<leader>wa', vim.lsp.buf.add_workspace_folder, '[W]orkspace [A]dd Folder') 144 nmap('<leader>wr', vim.lsp.buf.remove_workspace_folder, '[W]orkspace [R]emove Folder') 145 nmap('<leader>wl', function() 146 print(vim.inspect(vim.lsp.buf.list_workspace_folders())) 147 end, '[W]orkspace [L]ist Folders') 148 149 -- Create a command `:Format` local to the LSP buffer 150 vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_) 151 vim.lsp.buf.format() 152 end, { desc = 'Format current buffer with LSP' }) 153 end 154 155 mason_lspconfig.setup_handlers { 156 function(server_name) 157 require('lspconfig')[server_name].setup { 158 capabilities = require('cmp_nvim_lsp').default_capabilities(vim.lsp.protocol.make_client_capabilities()), 159 on_attach = on_attach, 160 settings = servers[server_name], 161 } 162 end, 163 }