mason-lspconfig.nvim

repository·main·Indexed 26 days ago

https://github.com/mason-org/mason-lspconfig.nvim

A bridge between mason.nvim and nvim-lspconfig that simplifies installing and automatically enabling LSP servers in Neovim. It provides configuration options for ensure_installed and automatic_enable, as well as convenience commands :LspInstall and :LspUninstall.

Tokens
1.2K
Snippets
5
Records
7
Agent score
37%

What's inside mason-lspconfig.nvim

  1. Recommended setup for lazy.nvim

    main

    If you use lazy.nvim, use the following configuration. This approach automatically handles the .setup() call for you.

    {
        "mason-org/mason-lspconfig.nvim",
        opts = {},
        dependencies = {
            { "mason-org/mason.nvim", opts = {} },
            "neovim/nvim-lspconfig",
        },
    }
  2. Install and setup mason-lspconfig.nvim

    main

    Install mason-lspconfig.nvim using your preferred plugin manager. You must ensure mason.nvim is set up and nvim-lspconfig is available in your runtime path before calling the mason-lspconfig setup function.

    For standard setup, call:

    require("mason-lspconfig").setup()
  3. Configure automatic_enable settings

    main

    You can control which installed servers are automatically enabled using the automatic_enable option in the .setup() function.

    • Disable all automatic enabling: Set to false.
    • Exclude specific servers: Pass a table with an exclude key containing a list of server names.
    • Only enable specific servers: Pass a list of server names directly.
    -- Disable automatic enabling
    require("mason-lspconfig").setup {
        automatic_enable = false
    }
    
    -- Exclude specific servers
    require("mason-lspconfig").setup {
        automatic_enable = {
            exclude = {
                "rust_analyzer",
                "ts_ls"
            }
        }
    }
    
    -- Only enable specific servers
    require("mason-lspconfig").setup {
        automatic_enable = {
            "lua_ls",
            "vimls"
        }
    }
  4. Reference: mason-lspconfig configuration options

    main

    The following settings are available in the .setup() function:

    OptionTypeDefaultDescription
    ensure_installedstring[]{}A list of servers to automatically install if they're not already installed.
    automatic_enableboolean | string[] | { exclude: string[] }trueWhether installed servers should automatically be enabled via vim.lsp.enable().
    local DEFAULT_SETTINGS = {
        -- A list of servers to automatically install if they're not already installed. Example: { "rust_analyzer@nightly", "lua_ls" }
        ---@type string[]
        ensure_installed = {},
    
        -- Whether installed servers should automatically be enabled via `:h vim.lsp.enable()`.
        --
        -- To exclude certain servers from being automatically enabled:
        -- ```lua
        --   automatic_enable = {
        --     exclude = { "rust_analyzer", "ts_ls" }
        --   }
        -- ```
        --
        -- To only enable certain servers to be automatically enabled:
        -- ```lua
        --   automatic_enable = {
        --     "lua_ls",
        --     "vimls"
        --   }
        -- ```
        ---@type boolean | string[] | { exclude: string[] }
        automatic_enable = true,
    }
  5. Use LspInstall and LspUninstall commands

    main

    mason-lspconfig.nvim provides convenience commands to manage LSP servers:

    • :LspInstall [<server> ...] : Installs the specified servers. If no server name is provided, you will be prompted to select one based on the current buffer's filetype.
    • :LspUninstall <server> ... : Uninstalls the specified servers.