From 7ec4515179db970bf5728143e4d92072a536179d Mon Sep 17 00:00:00 2001 From: siduck Date: Fri, 24 Mar 2023 04:35:54 +0530 Subject: [PATCH] boostrap mason packages properly print some message when nvchad is totally setup --- lua/core/bootstrap.lua | 37 ++++++++++++++++++++++------------- lua/core/init.lua | 11 +++++------ lua/plugins/configs/mason.lua | 2 +- lua/plugins/init.lua | 2 ++ 4 files changed, 31 insertions(+), 21 deletions(-) diff --git a/lua/core/bootstrap.lua b/lua/core/bootstrap.lua index 1ebcb81..dd0234f 100644 --- a/lua/core/bootstrap.lua +++ b/lua/core/bootstrap.lua @@ -16,12 +16,29 @@ M.lazy = function(install_path) -- install plugins + compile their configs require "plugins" - vim.api.nvim_buf_delete(0, { force = true }) -- close lazy window - vim.defer_fn(function() - vim.cmd "silent! MasonInstallAll" - end, 0) + -- install mason packages + vim.schedule(function() + vim.cmd "Mason" + local packages = {} + + for _, pkg_name in ipairs(vim.g.mason_binaries_list) do + packages[pkg_name] = true + vim.cmd("MasonInstall " .. pkg_name) + end + + require("mason-registry"):on("package:install:success", function(pkg) + packages[pkg.name] = nil + + if vim.tbl_count(packages) == 0 then + vim.schedule(function() + vim.api.nvim_buf_delete(0, { force = true }) + vim.notify("Now please read the docs at nvchad.com!") -- WIP, show a nice screen after it + end) + end + end) + end) end M.gen_chadrc_template = function() @@ -40,7 +57,7 @@ M.gen_chadrc_template = function() "https://github.com/NvChad/example_config", vim.fn.stdpath "config" .. "/lua/custom", } - print "dont forget to read docs from nvchad.com!" + vim.cmd "redraw|echo ''" -- delete .git from that repo @@ -51,16 +68,8 @@ M.gen_chadrc_template = function() local custom_dir = vim.fn.stdpath "config" .. "/lua/custom/" vim.fn.mkdir(custom_dir, "p") - local str = [[ - local M = {} - M.ui = { - theme = "onedark", - } - return M - ]] - local file = io.open(custom_dir .. "chadrc.lua", "w") - file:write(str) + file:write("local M = {} \n M.ui = { theme = 'onedark' } \n return M") file:close() end end diff --git a/lua/core/init.lua b/lua/core/init.lua index 4bb53a4..8fe26e2 100644 --- a/lua/core/init.lua +++ b/lua/core/init.lua @@ -73,18 +73,17 @@ autocmd("FileType", { -- reload some chadrc options on-save vim.api.nvim_create_autocmd("BufWritePost", { - pattern = vim.tbl_map(vim.fs.normalize, vim.fn.glob( - vim.fn.stdpath("config") .. "/lua/custom/**/*.lua", - true, - true, - true - )), + pattern = vim.tbl_map( + vim.fs.normalize, + vim.fn.glob(vim.fn.stdpath "config" .. "/lua/custom/**/*.lua", true, true, true) + ), group = vim.api.nvim_create_augroup("ReloadNvChad", {}), callback = function(opts) local fp = vim.fn.fnamemodify(vim.fs.normalize(vim.api.nvim_buf_get_name(opts.buf)), ":r") --[[@as string]] local app_name = vim.env.NVIM_APPNAME and vim.env.NVIM_APPNAME or "nvim" local module = string.gsub(fp, "^.*/" .. app_name .. "/lua/", ""):gsub("/", ".") + require("plenary.reload").reload_module "base46" require("plenary.reload").reload_module(module) require("plenary.reload").reload_module "custom.chadrc" diff --git a/lua/plugins/configs/mason.lua b/lua/plugins/configs/mason.lua index 8ccc313..bcc8a38 100644 --- a/lua/plugins/configs/mason.lua +++ b/lua/plugins/configs/mason.lua @@ -1,5 +1,5 @@ local options = { - ensure_installed = { "lua-language-server" }, -- not an option from mason.nvim + ensure_installed = { "lua-language-server", "stylua" }, -- not an option from mason.nvim PATH = "skip", diff --git a/lua/plugins/init.lua b/lua/plugins/init.lua index 70e14c0..60b528f 100644 --- a/lua/plugins/init.lua +++ b/lua/plugins/init.lua @@ -129,6 +129,8 @@ local default_plugins = { vim.api.nvim_create_user_command("MasonInstallAll", function() vim.cmd("MasonInstall " .. table.concat(opts.ensure_installed, " ")) end, {}) + + vim.g.mason_binaries_list = opts.ensure_installed end, },