dotfiles

My personal shell configs and stuff
git clone git://git.alex.balgavy.eu/dotfiles.git
Log | Files | Refs | Submodules | README | LICENSE

mason-lspconfig.lua (5842B)


      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   -- solargraph = {},
     95   -- bashls = {},
     96   -- jdtls = {},
     97   -- jsonls = {},
     98   -- texlab = {},
     99   -- clangd = {},
    100   -- perlnavigator = {},
    101 }
    102 
    103 
    104 mason_lspconfig.setup {
    105   ensure_installed = vim.tbl_keys(servers),
    106 }
    107 
    108 -- LSP settings.
    109 --  This function gets run when an LSP connects to a particular buffer.
    110 local on_attach = function(_, bufnr)
    111   -- NOTE: Remember that lua is a real programming language, and as such it is possible
    112   -- to define small helper and utility functions so you don't have to repeat yourself
    113   -- many times.
    114   --
    115   -- In this case, we create a function that lets us more easily define mappings specific
    116   -- for LSP related items. It sets the mode, buffer and description for us each time.
    117   local nmap = function(keys, func, desc)
    118     if desc then
    119       desc = 'LSP: ' .. desc
    120     end
    121 
    122     vim.keymap.set('n', keys, func, { buffer = bufnr, desc = desc })
    123   end
    124 
    125   nmap('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame')
    126   nmap('<leader>ra', vim.lsp.buf.code_action, '[C]ode [A]ction')
    127   vim.keymap.set('v', '<leader>ra', vim.lsp.buf.code_action, { buffer = bufnr, desc = '[C]ode [A]ction' })
    128 
    129   nmap('gd', vim.lsp.buf.definition, '[G]oto [D]efinition')
    130   nmap('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences')
    131   nmap('gI', vim.lsp.buf.implementation, '[G]oto [I]mplementation')
    132   nmap('<leader>D', vim.lsp.buf.type_definition, 'Type [D]efinition')
    133   nmap('<leader>ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols')
    134   nmap('<leader>ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols')
    135 
    136   -- See `:help K` for why this keymap
    137   nmap('K', vim.lsp.buf.hover, 'Hover Documentation')
    138   nmap('<leader>K', vim.lsp.buf.signature_help, 'Signature Documentation')
    139 
    140   -- Lesser used LSP functionality
    141   nmap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')
    142   nmap('<leader>wa', vim.lsp.buf.add_workspace_folder, '[W]orkspace [A]dd Folder')
    143   nmap('<leader>wr', vim.lsp.buf.remove_workspace_folder, '[W]orkspace [R]emove Folder')
    144   nmap('<leader>wl', function()
    145     print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
    146   end, '[W]orkspace [L]ist Folders')
    147 
    148   -- Create a command `:Format` local to the LSP buffer
    149   vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_)
    150     vim.lsp.buf.format()
    151   end, { desc = 'Format current buffer with LSP' })
    152 end
    153 
    154 mason_lspconfig.setup_handlers {
    155   function(server_name)
    156     require('lspconfig')[server_name].setup {
    157       capabilities = require('cmp_nvim_lsp').default_capabilities(vim.lsp.protocol.make_client_capabilities()),
    158       on_attach = on_attach,
    159       settings = servers[server_name],
    160     }
    161   end,
    162 }