Advertisement
baconmanthelegend

Untitled

Jun 28th, 2025
463
0
6 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.28 KB | None | 0 0
  1. return {
  2.     {
  3.         "williamboman/mason.nvim",
  4.         config = function()
  5.             require("mason").setup()
  6.         end,
  7.     },
  8.  
  9.     {
  10.         "williamboman/mason-lspconfig.nvim",
  11.         dependencies = { "williamboman/mason.nvim", "neovim/nvim-lspconfig" },
  12.         config = function()
  13.             require("mason-lspconfig").setup({
  14.                 ensure_installed = {
  15.                     "lua_ls",
  16.                     "rust_analyzer",
  17.                 },
  18.                 automatic_installation = true,
  19.             })
  20.         end,
  21.     },
  22.     {
  23.         "neovim/nvim-lspconfig",
  24.         dependencies = { "williamboman/mason-lspconfig.nvim" },
  25.         config = function()
  26.             local servers = {
  27.                 "lua_ls",
  28.                 "rust_analyzer",
  29.             }
  30.             local capabilities = require("cmp_nvim_lsp").default_capabilities()
  31.             -- Add encoding support for servers like rust_analyzer
  32.             capabilities.offsetEncoding = { "utf-16", "utf-8" }
  33.  
  34.             local on_attach = function(client, bufnr)
  35.                 local opts = { noremap = true, silent = true, buffer = bufnr }
  36.                 local builtin = require("telescope.builtin")
  37.                 vim.keymap.set("n", "gd", builtin.lsp_definitions, opts)
  38.                 vim.keymap.set("n", "gr", builtin.lsp_references, opts)
  39.                 vim.keymap.set({ "n", "v" }, "<leader>ca", vim.lsp.buf.code_action, opts)
  40.                 vim.keymap.set("n", "<leader>gf", vim.lsp.buf.format, opts)
  41.             end
  42.             -- setup
  43.             local lspconfig = require("lspconfig")
  44.             for _, server_name in ipairs(servers) do
  45.                 -- This is the base configuration that applies to all servers
  46.                 local opts = {
  47.                     on_attach = on_attach,
  48.                     capabilities = capabilities,
  49.                 }
  50.  
  51.                 -- Per-server customization
  52.                 if server_name == "rust_analyzer" then
  53.                     local rust_settings = {
  54.                         settings = {
  55.                             ["rust-analyzer"] = {
  56.                                 check = { command = "clippy" },
  57.                                 cargo = {
  58.                                     extraEnv = { RUSTUP_TOOLCHAIN = "nightly" },
  59.                                     features = "all",
  60.                                 },
  61.                                 procMacro = { enable = true },
  62.                             },
  63.                         },
  64.                     }
  65.                     opts = vim.tbl_deep_extend("force", opts, rust_settings)
  66.                 end
  67.  
  68.                 if server_name == "lua_ls" then
  69.                     local lua_settings = {
  70.                         settings = {
  71.                             Lua = {
  72.                                 diagnostics = {
  73.                                     -- Make the server aware of Neovim runtime globals
  74.                                     globals = { "vim" },
  75.                                 },
  76.                             },
  77.                         },
  78.                     }
  79.                     opts = vim.tbl_deep_extend("force", opts, lua_settings)
  80.                 end
  81.                 lspconfig[server_name].setup(opts)
  82.             end
  83.         end,
  84.     },
  85. }
  86.  
Tags: nvim
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement