ui icon indicating copy to clipboard operation
ui copied to clipboard

MasonInstallAll Command not found in headless

Open ahmad9059 opened this issue 7 months ago • 6 comments

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:

  1. Running the direct command:
nvim --headless -c "MasonInstallAll" -c "quitall"

fails with:

E492: Not an editor command: MasonInstallAll%
  1. 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?

ahmad9059 avatar Aug 15 '25 06:08 ahmad9059

ui plugin loads this module in vim.schedule so the autocmds are loaded after ui loads

Image

siduck avatar Aug 15 '25 06:08 siduck

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

siduck avatar Aug 15 '25 06:08 siduck

Ok where to add this vim.schedule(function() require "nvchad.au" end)

in my main init.lua file, please help

ahmad9059 avatar Aug 15 '25 07:08 ahmad9059

or how to make MasonInstallAll work proper in headless

can you please provide complete solution where to make changes

ahmad9059 avatar Aug 15 '25 07:08 ahmad9059

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

siduck avatar Aug 15 '25 08:08 siduck

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

ahmad9059 avatar Aug 15 '25 09:08 ahmad9059