Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- return {
- {
- "williamboman/mason.nvim",
- config = function()
- require("mason").setup()
- end,
- },
- {
- "williamboman/mason-lspconfig.nvim",
- dependencies = { "williamboman/mason.nvim", "neovim/nvim-lspconfig" },
- config = function()
- require("mason-lspconfig").setup({
- ensure_installed = {
- "lua_ls",
- "rust_analyzer",
- },
- automatic_installation = true,
- })
- end,
- },
- {
- "neovim/nvim-lspconfig",
- dependencies = { "williamboman/mason-lspconfig.nvim" },
- config = function()
- local servers = {
- "lua_ls",
- "rust_analyzer",
- }
- local capabilities = require("cmp_nvim_lsp").default_capabilities()
- -- Add encoding support for servers like rust_analyzer
- capabilities.offsetEncoding = { "utf-16", "utf-8" }
- local on_attach = function(client, bufnr)
- local opts = { noremap = true, silent = true, buffer = bufnr }
- local builtin = require("telescope.builtin")
- vim.keymap.set("n", "gd", builtin.lsp_definitions, opts)
- vim.keymap.set("n", "gr", builtin.lsp_references, opts)
- vim.keymap.set({ "n", "v" }, "<leader>ca", vim.lsp.buf.code_action, opts)
- vim.keymap.set("n", "<leader>gf", vim.lsp.buf.format, opts)
- end
- -- setup
- local lspconfig = require("lspconfig")
- for _, server_name in ipairs(servers) do
- -- This is the base configuration that applies to all servers
- local opts = {
- on_attach = on_attach,
- capabilities = capabilities,
- }
- -- Per-server customization
- if server_name == "rust_analyzer" then
- local rust_settings = {
- settings = {
- ["rust-analyzer"] = {
- check = { command = "clippy" },
- cargo = {
- extraEnv = { RUSTUP_TOOLCHAIN = "nightly" },
- features = "all",
- },
- procMacro = { enable = true },
- },
- },
- }
- opts = vim.tbl_deep_extend("force", opts, rust_settings)
- end
- if server_name == "lua_ls" then
- local lua_settings = {
- settings = {
- Lua = {
- diagnostics = {
- -- Make the server aware of Neovim runtime globals
- globals = { "vim" },
- },
- },
- },
- }
- opts = vim.tbl_deep_extend("force", opts, lua_settings)
- end
- lspconfig[server_name].setup(opts)
- end
- end,
- },
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement