Due to network firewall restrictions at my company, I was unable to download the jdtls
plugin for Java LSP directly using mason.nvim. This prompted me to explore how mason.nvim operates, as I was able to download jdtls
locally. I now need to consider how to make manual setups function similarly to mason.nvimβs automatic process.
How mason.nvim Works
Mason.nvim is a Neovim plugin for managing external tools like language servers, formatters, and linters. Hereβs a breakdown of how it handles package installation and executable access:
1. Installation Location
By default, mason.nvim installs packages in Neovimβs data directory. To check where this directory is, you can run the following command in Neovim:
:echo stdpath('data')
For example, if the output is /home/rahul/.local/share/nvim
, the structure inside this folder might look like this:
/home/rahul/.local/share/nvim
βββ mason
β βββ bin
β βββ packages
β β βββ lua-language-server
β β βββ pyright
β β βββ eslint_d
β β βββ prettier
β βββ registry
mason/
: The main folder where mason.nvim installs all tools.bin/
: This contains symlinks or executables of installed tools. Neovim adds this folder to itsPATH
.packages/
: Each tool gets installed in its own subfolder (e.g.,lua-language-server
,pyright
, etc.).registry/
: Stores metadata and versioning information for installed tools.
2. Executable Linking
When a package is installed, its executable is linked to the bin/
directory. For example:
/home/rahul/.local/share/nvim/mason
βββ bin
β βββ lua-language-server -> ../packages/lua-language-server/bin/lua-language-server
β βββ pyright -> ../packages/pyright/bin/pyright
β βββ eslint_d -> ../packages/eslint_d/bin/eslint_d
β βββ prettier -> ../packages/prettier/bin/prettier
3.Adding to PATH
Mason.nvim automatically adds the mason/bin
directory to Neovimβs PATH
. This means tools installed by mason.nvim are accessible in:
- Neovimβs command-line (
:!
commands), - Neovimβs terminal emulator (
:term
), - and third-party plugins requiring these tools.
You can check Neovimβs
PATH
using:
:echo $PATH
You should see something like:
/home/rahul/.local/share/nvim/mason/bin:/usr/local/bin:/usr/bin:/bin
Folder Structure Summary
/home/rahul/.local/share/nvim
βββ mason
βββ bin # Executables or symlinks to tools
βββ packages # Tool directories
βββ registry # Metadata for packages
Manual Installation of Language Server
If youβve manually installed a language server (e.g., my-server
) by downloading it into the mason/packages/
folder, follow these steps to ensure it works similarly to a mason.nvim-managed tool.
Step 1: Ensure Executable Placement
Place the serverβs executable in the correct location within the packages
folder. For example:
/home/rahul/.local/share/nvim/mason/packages/my-server/bin/my-server
Step 2: Create a Symlink
Manually create a symlink in the mason/bin
directory so that Neovim can access it like other mason tools.
Run the following command in the terminal:
ln -s /home/rahul/.local/share/nvim/mason/packages/my-server/bin/my-server /home/rahul/.local/share/nvim/mason/bin/my-server
This will create a symbolic link in the bin
folder.
Your bin/
directory should now look like this:
/home/rahul/.local/share/nvim/mason/bin
βββ lua-language-server -> ../packages/lua-language-server/bin/lua-language-server
βββ pyright -> ../packages/pyright/bin/pyright
βββ eslint_d -> ../packages/eslint_d/bin/eslint_d
βββ my-server -> ../packages/my-server/bin/my-server
Step 3: Ensure PATH Includes mason/bin
Mason.nvim automatically adds the mason/bin
directory to Neovimβs PATH
. You can verify this by running: :echo $PATH
Ensure that the output includes:
/home/rahul/.local/share/nvim/mason/bin:/usr/local/bin:/usr/bin:/bin
Now, Neovim should be able to recognize and use the manually installed my-server
just like any tool installed via mason.nvim.
By following these steps, you can manually install and configure tools in a way that mimics mason.nvimβs automated process.