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
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
| Server | Language/Framework | Description |
|---|
ts_ls | TypeScript/JavaScript | TypeScript language server |
html | HTML | HTML language server |
cssls | CSS | CSS language server |
tailwindcss | Tailwind CSS | Tailwind CSS IntelliSense |
svelte | Svelte | Svelte language server |
lua_ls | Lua | Lua language server |
graphql | GraphQL | GraphQL language server |
emmet_ls | Emmet | Emmet support for HTML/CSS |
prismals | Prisma | Prisma ORM language server |
pyright | Python | Python type checker |
eslint | JavaScript/TypeScript | ESLint language server |
| Tool | Type | Purpose |
|---|
prettier | Formatter | Formats JavaScript, TypeScript, CSS, HTML, JSON, and more |
stylua | Formatter | Formats Lua code |
isort | Formatter | Sorts Python imports |
black | Formatter | Python code formatter |
pylint | Linter | Python linter |
eslint_d | Linter | Fast ESLint daemon |
Usage
Opening Mason UI
Access the Mason interface using the Which-key menu:
- Press
<leader>m to open the Mason menu
- 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
| Key | Action | Group |
|---|
<leader>m | Open Mason menu | Mason |
The <leader>m keybinding is registered through the which-key configuration.
Automatic Installation
When you first launch Neovim with Magictt config:
- Mason will automatically install all servers listed in
ensure_installed
- Mason-tool-installer will automatically install all formatters and linters
- Installation happens in the background on the first startup
- You can continue working while packages install
Tips and Tricks
Adding New LSP Servers
To add a new LSP server:
- Find the server name from mason-lspconfig server mappings
- Add it to the
ensure_installed list in lua/magictt/plugins/lsp/mason.lua
- Restart Neovim or run
:Lazy sync
To add a new tool:
- Find the tool name from Mason registry
- Add it to
ensure_installed in the mason-tool-installer section
- Restart Neovim or run
:Lazy sync
Checking Installation Status
To verify what’s installed:
This opens the Mason UI where you can see all packages and their status.
Updating All Packages
To update all installed packages:
- Open Mason with
:Mason
- Press
U (capital U) to update all packages
Troubleshooting Installation Issues
If a package fails to install:
- Open Mason UI with
:Mason
- Navigate to the failed package
- Press
X to uninstall it
- Press
i to reinstall it
- 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