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