mason.nvim

repository·main·Indexed 27 days ago

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

A portable package manager for Neovim that allows users to install and manage LSP servers, DAP servers, linters, and formatters through a single interface. It provides commands for package management, such as :Mason, :MasonInstall, and :MasonUninstall, and supports configuration via a setup function or lazy.nvim opts.

Tokens
2.5K
Snippets
6
Records
9
Agent score
45%

What's inside mason.nvim

  1. Configure mason.nvim via setup()

    main

    You can customize the behavior of mason.nvim by passing an options table to the .setup() function. This allows you to modify UI elements like icons, or adjust core settings like installation directories and PATH management.

    require("mason").setup({
        ui = {
            icons = {
                package_installed = "✓",
                package_pending = "➜",
                package_uninstalled = "✗"
            }
        }
    })
  2. Install and setup mason.nvim

    main

    Install mason.nvim using your preferred plugin manager. After installation, you must call the setup function to initialize the plugin.

    Note: It is not recommended to lazy-load or defer the setup of mason.nvim as it is optimized to load as little as possible during the initial setup phase.

    require("mason").setup()
  3. Configure mason.nvim using lazy.nvim

    main

    If you are using lazy.nvim as your plugin manager, you can provide configuration using the opts key in your plugin specification.

    {
        "mason-org/mason.nvim",
        opts = {
            ui = {
                icons = {
                    package_installed = "✓",
                    package_pending = "➜",
                    package_uninstalled = "✗"
                }
            }
        }
    }
  4. Enable Socket.dev firewall

    main

    To protect against supply chain attacks, you can enable the Socket.dev firewall in your mason.nvim configuration. By default, Mason will automatically install and update the Socket Firewall client.

    If you prefer to manage the sfw binary manually (ensuring it is in your PATH), set auto_managed = false.

    -- Standard automatic management
    require("mason").setup {
      firewall = {
        enabled = true
      }
    }
    
    -- Manual management of the sfw binary
    require("mason").setup {
      firewall = {
        enabled = true,
        auto_managed = false
      }
    }
  5. Reference: MasonSettings configuration options

    main

    The following table lists the available configuration keys for mason.nvim. Refer to :h mason-settings for detailed documentation.

    ---@class MasonSettings
    local DEFAULT_SETTINGS = {
        -- The directory in which to install packages.
        install_root_dir = path.concat { vim.fn.stdpath "data", "mason" },
    
        -- Where Mason should put its bin location in your PATH.
        -- "prepend" (default), "append", or "skip"
        PATH = "prepend",
    
        -- Controls to which degree logs are written to the log file.
        log_level = vim.log.levels.INFO,
    
        -- Limit for the maximum amount of packages to be installed at the same time.
        max_concurrent_installers = 4,
    
        -- The registries to source packages from.
        registries = {
            "github:mason-org/mason-registry",
        },
    
        -- The registries to source system packages from.
        system_registries = {
            "github:mason-org/mason-system-registry",
        },
    
        registry_cache = {
            -- Whether Mason should automatically refresh the registry when needed.
            refresh = true,
            -- Amount of seconds before the local registry cache is considered stale.
            duration = 24 * 60 * 60, -- 24 hours
        },
    
        firewall = {
            -- Whether to enable the socket.dev firewall (sfw) for supported package sources.
            enabled = false,
            -- Whether mason.nvim should automatically install and update the Socket Firewall client.
            auto_managed = true,
        },
    
        -- The provider implementations to use for resolving supplementary package metadata.
        -- Builtin: "mason.providers.registry-api", "mason.providers.client"
        providers = {
            "mason.providers.registry-api",
            "mason.providers.client",
        },
    
        github = {
            -- The template URL to use when downloading assets from GitHub.
            download_url_template = "https://github.com/%s/releases/download/%s/%s",
        },
    
        pip = {
            -- Whether to upgrade pip to the latest version before installing packages.
            upgrade_pip = false,
            -- Args added to `pip install` calls.
            install_args = {},
        },
    
        npm = {
            -- Args added to `npm install` calls.
            install_args = {},
        },
    
        ui = {
            -- Whether to automatically check for new versions when opening the :Mason window.
            check_outdated_packages_on_open = true,
            -- The border to use for the UI window.
            border = nil,
            -- The backdrop opacity (0 is fully opaque, 100 is fully transparent).
            backdrop = 60,
            -- Width of the window (Integer > 1 or Float 0-1).
            width = 0.8,
            -- Height of the window (Integer > 1 or Float 0-1).
            height = 0.9,
    
            icons = {
                package_installed = "◍",
                package_pending = "◍",
                package_uninstalled = "◍",
            },
    
            keymaps = {
                toggle_package_expand = "<CR>",
                install_package = "i",
                update_package = "u",
                check_package_version = "c",
                update_all_packages = "U",
                check_outdated_packages = "C",
                uninstall_package = "X",
                cancel_installation = "<C-c>",
                apply_language_filter = "<C-f>",
                toggle_package_install_log = "<CR>",
                toggle_help = "g?",
            },
        },
    }
  6. Use mason.nvim commands

    main

    Use the following commands to manage your packages and the Mason interface:

    • :Mason: Opens the graphical status window.
    • :MasonUpdate: Updates all managed registries.
    • :MasonInstall <package> ...: Installs or re-installs the specified packages.
    • :MasonUninstall <package> ...: Uninstalls the specified packages.
    • :MasonUninstallAll: Uninstalls all currently installed packages.
    • :MasonLog: Opens the mason.nvim log file in a new tab window.
  7. Check mason.nvim requirements

    main

    Ensure your system meets the minimum requirements for mason.nvim to function correctly. You can verify your current environment by running :checkhealth mason inside Neovim.

    Minimum Requirements

    • Neovim >= 0.10.0
    • Unix systems: git(1), curl(1) or GNU wget(1), unzip(1), GNU tar (tar(1) or gtar(1)), and gzip(1).
    • Windows systems: pwsh or powershell, git, GNU tar, and one of the following: 7zip, peazip, archiver, winzip, or WinRAR.