MasonInstallAll Command not found in headless
Title: Unable to exit Neovim headless mode after nvchad.mason.install_all() finishes
Description:
I am trying to automate installing all Mason packages defined in M.mason.ensure_installed as well as LSPs defined in .config/nvim/lua/configs/lspconfig.lua and formatters in .config/nvim/lua/configs/conform.lua.
When I run inside Neovim:
:MasonInstallAll
everything works fine.
However, I want to run this in headless mode for automation (as part of my setup script) and ran into two problems:
- Running the direct command:
nvim --headless -c "MasonInstallAll" -c "quitall"
fails with:
E492: Not an editor command: MasonInstallAll%
- Running the Lua method works:
nvim --headless +"lua require('nvchad.mason').install_all()" +"autocmd User MasonUpdateAllComplete qa"
This successfully installs all packages, but Neovim stays stuck in headless mode after installation finishes. I expected it to quit automatically.
Full script I am using:
#!/bin/bash
set -e
# Step 1: Bootstrap NvChad
nvim --headless -c 'qa'
# Step 2: Sync Lazy.nvim plugins
nvim --headless -c 'Lazy sync' -c 'qa'
# Step 3: Install Mason packages
nvim --headless +"lua require('nvchad.mason').install_all()" +"autocmd User MasonUpdateAllComplete qa"
echo -e "\nNvChad, plugins, and Mason packages installed successfully!"
Expected behavior: Neovim should quit automatically after Mason finishes installing all packages in headless mode.
Actual behavior: It installs everything but does not exit headless mode, leaving the process hanging.
Environment:
- OS: Arch Linux
- Neovim: v0.12.0-dev-893+g6190b6bc1d
- My NvChad Config : https://github.com/ahmad9059/nvim
If you want, I can also rewrite it so it includes the exact install list from lspconfig.lua and conform.lua for clarity before posting. This might help maintainers reproduce your case faster. Do you want me to do that?
ui plugin loads this module in vim.schedule so the autocmds are loaded after ui loads
nvim --headless +":lua require('nvchad.mason').install_all()" +"qall"
we could do this but we need to make that function calls mason functions which are async
Ok where to add this vim.schedule(function() require "nvchad.au" end)
in my main init.lua file, please help
or how to make MasonInstallAll work proper in headless
can you please provide complete solution where to make changes
Ok where to add this vim.schedule(function() require "nvchad.au" end)
in my main init.lua file, please help
I mean thats how nvchad's ui plugins loads its autocmds code which also includes that mason command. I need to check mason docs if it allows non async stuff . Wait until then! or you could do
Ok where to add this vim.schedule(function() require "nvchad.au" end) in my main init.lua file, please help
I mean thats how nvchad's ui plugins loads its autocmds code which also includes that mason command. I need to check mason docs if it allows non async stuff . Wait until then! or you could do
Ohh Sorry
also I found this on mason.nvim issues : https://github.com/mason-org/mason.nvim/issues/467