diff --git a/README.md b/README.md index ea93722a..fb04ca6c 100644 --- a/README.md +++ b/README.md @@ -489,6 +489,7 @@ Any operation can be started from the UI, with a sub command or an API function: | Command | Lua | Description | | ------------------------- | -------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | +| `:Lazy build {plugins}` | `require("lazy").build(opts)` | Rebuild a plugin | | `:Lazy check [plugins]` | `require("lazy").check(opts?)` | Check for updates and show the log (git fetch) | | `:Lazy clean [plugins]` | `require("lazy").clean(opts?)` | Clean plugins that are no longer needed | | `:Lazy clear` | `require("lazy").clear()` | Clear finished tasks | diff --git a/lua/lazy/manage/init.lua b/lua/lazy/manage/init.lua index 83dd18c4..375f4453 100644 --- a/lua/lazy/manage/init.lua +++ b/lua/lazy/manage/init.lua @@ -144,6 +144,17 @@ function M.log(opts) }, opts) end +---@param opts? ManagerOpts +function M.build(opts) + opts = M.opts(opts, { mode = "build" }) + return M.run({ + pipeline = { { "plugin.build", force = true } }, + plugins = function() + return false + end, + }, opts) +end + ---@param opts? ManagerOpts function M.sync(opts) opts = M.opts(opts) diff --git a/lua/lazy/manage/task/plugin.lua b/lua/lazy/manage/task/plugin.lua index 05424b80..9b32b515 100644 --- a/lua/lazy/manage/task/plugin.lua +++ b/lua/lazy/manage/task/plugin.lua @@ -5,7 +5,11 @@ local Loader = require("lazy.core.loader") local M = {} M.build = { - skip = function(plugin) + ---@param opts? {force:boolean} + skip = function(plugin, opts) + if opts and opts.force then + return false + end return not (plugin._.dirty and plugin.build) end, run = function(self) diff --git a/lua/lazy/view/commands.lua b/lua/lazy/view/commands.lua index c6ee5f39..39bd3f83 100644 --- a/lua/lazy/view/commands.lua +++ b/lua/lazy/view/commands.lua @@ -13,6 +13,12 @@ function M.cmd(cmd, opts) local command = M.commands[cmd] --[[@as fun(opts)]] if command == nil then Util.error("Invalid lazy command '" .. cmd .. "'") + elseif + ViewConfig.commands[cmd] + and ViewConfig.commands[cmd].plugins_required + and not (opts and vim.tbl_count(opts.plugins or {}) > 0) + then + return Util.error("`Lazy " .. cmd .. "` requires at least one plugin") else command(opts) end @@ -44,12 +50,10 @@ M.commands = { end, ---@param opts ManagerOpts load = function(opts) - if not (opts and opts.plugins and #opts.plugins > 0) then - return Util.error("`Lazy load` requires at least one plugin name to load") - end require("lazy.core.loader").load(opts.plugins, { cmd = "LazyLoad" }) end, log = Manage.log, + build = Manage.build, clean = Manage.clean, install = Manage.install, sync = Manage.sync, diff --git a/lua/lazy/view/config.lua b/lua/lazy/view/config.lua index b6f5bc27..e229352a 100644 --- a/lua/lazy/view/config.lua +++ b/lua/lazy/view/config.lua @@ -139,6 +139,13 @@ M.commands = { desc = "Run `:checkhealth lazy`", id = 14, }, + build = { + desc = "Rebuild a plugin", + id = 13, + plugins = true, + plugins_required = true, + key_plugin = "b", + }, } return M