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