Skip to main content

Overview

Mason is a package manager for Neovim that provides an easy way to install and manage LSP servers, DAP servers, linters, and formatters. The Magictt config uses Mason to automatically install and configure essential development tools.

What Mason Does

  • Automatic Installation: Ensures critical LSP servers and tools are installed
  • Unified Interface: Provides a consistent UI for managing all development tools
  • Cross-Platform: Works across different operating systems with minimal configuration
  • Integration: Seamlessly integrates with nvim-lspconfig and other plugins

Configuration

The Mason configuration is split into two plugins:

mason-lspconfig.nvim

Manages LSP server installation:
{
  "williamboman/mason-lspconfig.nvim",
  opts = {
    -- list of servers for mason to install
    ensure_installed = {
      "ts_ls",
      "html",
      "cssls",
      "tailwindcss",
      "svelte",
      "lua_ls",
      "graphql",
      "emmet_ls",
      "prismals",
      "pyright",
      "eslint",
    },
  },
  dependencies = {
    {
      "williamboman/mason.nvim",
      opts = {
        ui = {
          icons = {
            package_installed = "✓",
            package_pending = "➜",
            package_uninstalled = "✗",
          },
        },
      },
    },
    "neovim/nvim-lspconfig",
  },
}
Source: lua/magictt/plugins/lsp/mason.lua:2-35

mason-tool-installer.nvim

Manages formatters and linters:
{
  "WhoIsSethDaniel/mason-tool-installer.nvim",
  opts = {
    ensure_installed = {
      "prettier", -- prettier formatter
      "stylua", -- lua formatter
      "isort", -- python formatter
      "black", -- python formatter
      "pylint",
      "eslint_d",
    },
  },
  dependencies = {
    "williamboman/mason.nvim",
  },
}
Source: lua/magictt/plugins/lsp/mason.lua:36-51

Installed LSP Servers

ServerLanguage/FrameworkDescription
ts_lsTypeScript/JavaScriptTypeScript language server
htmlHTMLHTML language server
csslsCSSCSS language server
tailwindcssTailwind CSSTailwind CSS IntelliSense
svelteSvelteSvelte language server
lua_lsLuaLua language server
graphqlGraphQLGraphQL language server
emmet_lsEmmetEmmet support for HTML/CSS
prismalsPrismaPrisma ORM language server
pyrightPythonPython type checker
eslintJavaScript/TypeScriptESLint language server

Installed Tools

ToolTypePurpose
prettierFormatterFormats JavaScript, TypeScript, CSS, HTML, JSON, and more
styluaFormatterFormats Lua code
isortFormatterSorts Python imports
blackFormatterPython code formatter
pylintLinterPython linter
eslint_dLinterFast ESLint daemon

Usage

Opening Mason UI

Access the Mason interface using the Which-key menu:
  1. Press <leader>m to open the Mason menu
  2. The Mason UI will display all available packages

Mason UI Interface

In the Mason UI, you’ll see packages with status icons:
  • Package is installed
  • Package installation is pending
  • Package is not installed

Managing Packages

Within the Mason UI:
  • Install: Press i on a highlighted package
  • Update: Press u on an installed package
  • Uninstall: Press X on an installed package
  • Search: Start typing to filter packages
  • Help: Press g? to see all keybindings

Keybindings

KeyActionGroup
<leader>mOpen Mason menuMason
The <leader>m keybinding is registered through the which-key configuration.

Automatic Installation

When you first launch Neovim with Magictt config:
  1. Mason will automatically install all servers listed in ensure_installed
  2. Mason-tool-installer will automatically install all formatters and linters
  3. Installation happens in the background on the first startup
  4. You can continue working while packages install

Tips and Tricks

Adding New LSP Servers

To add a new LSP server:
  1. Find the server name from mason-lspconfig server mappings
  2. Add it to the ensure_installed list in lua/magictt/plugins/lsp/mason.lua
  3. Restart Neovim or run :Lazy sync

Adding New Formatters or Linters

To add a new tool:
  1. Find the tool name from Mason registry
  2. Add it to ensure_installed in the mason-tool-installer section
  3. Restart Neovim or run :Lazy sync

Checking Installation Status

To verify what’s installed:
:Mason
This opens the Mason UI where you can see all packages and their status.

Updating All Packages

To update all installed packages:
  1. Open Mason with :Mason
  2. Press U (capital U) to update all packages

Troubleshooting Installation Issues

If a package fails to install:
  1. Open Mason UI with :Mason
  2. Navigate to the failed package
  3. Press X to uninstall it
  4. Press i to reinstall it
  5. Check the log output for error messages

Manual Installation

If automatic installation is disabled or fails:
:MasonInstall <package-name>
For example:
:MasonInstall lua_ls prettier

External Resources

Build docs developers (and LLMs) love