update:restructure
This commit is contained in:
32
nvim/lua/commands/mason.lua
Normal file
32
nvim/lua/commands/mason.lua
Normal file
@@ -0,0 +1,32 @@
|
||||
-- custom mason commands
|
||||
local M = {}
|
||||
|
||||
function M.setup_install_defaults_command(tools)
|
||||
pcall(vim.api.nvim_del_user_command, "MasonInstallDefaults")
|
||||
vim.api.nvim_create_user_command("MasonInstallDefaults", function()
|
||||
local registry = require("mason-registry")
|
||||
registry.refresh(function()
|
||||
local seen, to_install = {}, {}
|
||||
for _, tool in ipairs(tools) do
|
||||
if tool.mason and not seen[tool.mason] then
|
||||
seen[tool.mason] = true
|
||||
local ok, pkg = pcall(registry.get_package, tool.mason)
|
||||
if ok and not pkg:is_installed() then
|
||||
table.insert(to_install, pkg)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if #to_install == 0 then
|
||||
vim.notify("MasonInstallDefaults: all tools already installed", vim.log.levels.INFO)
|
||||
return
|
||||
end
|
||||
for _, pkg in ipairs(to_install) do
|
||||
pkg:install()
|
||||
end
|
||||
vim.notify(("MasonInstallDefaults: installing %d tool(s)"):format(#to_install), vim.log.levels.INFO)
|
||||
end)
|
||||
end, { desc = "Install missing Mason tools from tool registry" })
|
||||
end
|
||||
|
||||
return M
|
||||
81
nvim/lua/commands/pack.lua
Normal file
81
nvim/lua/commands/pack.lua
Normal file
@@ -0,0 +1,81 @@
|
||||
local M = {}
|
||||
|
||||
local pack = require("utils.pack")
|
||||
|
||||
M.registry = pack.registry
|
||||
M.add = pack.add
|
||||
M.names = pack.names
|
||||
|
||||
function M.setup()
|
||||
local group = vim.api.nvim_create_augroup("UserPackHooks", { clear = true })
|
||||
|
||||
vim.api.nvim_create_autocmd("PackChanged", {
|
||||
group = group,
|
||||
callback = function(ev)
|
||||
local plugin_name, kind = ev.data.spec.name, ev.data.kind
|
||||
if plugin_name == "nvim-treesitter" and kind == "update" then
|
||||
if not ev.data.active then
|
||||
vim.cmd.packadd("nvim-treesitter")
|
||||
end
|
||||
pcall(vim.cmd, "TSUpdate")
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
vim.api.nvim_create_user_command("PackInstall", function()
|
||||
M.add(M.names(), {
|
||||
confirm = false,
|
||||
load = function() end,
|
||||
})
|
||||
vim.notify("PackInstall: ensured all configured plugins are installed", vim.log.levels.INFO)
|
||||
end, { desc = "Install all configured vim.pack plugins without loading" })
|
||||
|
||||
vim.api.nvim_create_user_command("PackUpdate", function(opts)
|
||||
local names = (#opts.fargs > 0) and opts.fargs or nil
|
||||
vim.pack.update(names)
|
||||
end, {
|
||||
nargs = "*",
|
||||
complete = function(arglead)
|
||||
local out = {}
|
||||
for _, name in ipairs(M.names()) do
|
||||
if name:find("^" .. vim.pesc(arglead)) then
|
||||
table.insert(out, name)
|
||||
end
|
||||
end
|
||||
return out
|
||||
end,
|
||||
desc = "Update vim.pack plugins (optionally pass plugin names)",
|
||||
})
|
||||
|
||||
vim.api.nvim_create_user_command("PackSync", function()
|
||||
vim.pack.update(nil, { target = "lockfile" })
|
||||
end, { desc = "Sync installed plugins to nvim-pack-lock.json" })
|
||||
|
||||
vim.api.nvim_create_user_command("PackClean", function()
|
||||
local stale = vim.iter(vim.pack.get())
|
||||
:filter(function(plugin)
|
||||
return not plugin.active
|
||||
end)
|
||||
:map(function(plugin)
|
||||
return plugin.spec.name
|
||||
end)
|
||||
:totable()
|
||||
|
||||
if #stale == 0 then
|
||||
vim.notify("PackClean: nothing to clean", vim.log.levels.INFO)
|
||||
return
|
||||
end
|
||||
|
||||
local msg = "PackClean will remove:\n - " .. table.concat(stale, "\n - ")
|
||||
local choice = vim.fn.confirm(msg, "&Yes\n&No", 2)
|
||||
if choice ~= 1 then
|
||||
vim.notify("PackClean: cancelled", vim.log.levels.INFO)
|
||||
return
|
||||
end
|
||||
|
||||
vim.pack.del(stale)
|
||||
vim.notify("PackClean: removed " .. #stale .. " plugin(s)", vim.log.levels.INFO)
|
||||
end, { desc = "Delete inactive vim.pack plugins from disk" })
|
||||
end
|
||||
|
||||
return M
|
||||
Reference in New Issue
Block a user