Skip to content

Commit

Permalink
feat(commands): :Lazy! load now skips cond checks when loading pl…
Browse files Browse the repository at this point in the history
…ugins. Fixes #330
  • Loading branch information
folke committed Jan 6, 2023
1 parent 2ef44e2 commit eed1ef3
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 20 deletions.
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,8 @@ return {
version = nil,
-- version = "*", -- enable this to try installing the latest stable versions of plugins
},
-- leave nil when passing the spec as the first argument to setup()
spec = nil, ---@type LazySpec
lockfile = vim.fn.stdpath("config") .. "/lazy-lock.json", -- lockfile generated after running update.
concurrency = nil, ---@type number limit the maximum amount of concurrent tasks
git = {
Expand Down Expand Up @@ -330,20 +332,21 @@ return {
-- The border to use for the UI window. Accepts same border values as |nvim_open_win()|.
border = "none",
icons = {
loaded = "",
not_loaded = "",
cmd = "",
config = "",
event = "",
ft = "",
init = "",
import = "",
keys = "",
lazy = "",
loaded = "",
not_loaded = "",
plugin = "",
runtime = "",
source = "",
start = "",
task = "",
lazy = "",
list = {
"",
"",
Expand All @@ -361,21 +364,15 @@ return {

-- open lazygit log
["<localleader>l"] = function(plugin)
require("lazy.util").open_cmd({ "lazygit", "log" }, {
require("lazy.util").float_term({ "lazygit", "log" }, {
cwd = plugin.dir,
terminal = true,
close_on_exit = true,
enter = true,
})
end,

-- open a terminal for the plugin dir
["<localleader>t"] = function(plugin)
require("lazy.util").open_cmd({ vim.go.shell }, {
require("lazy.util").float_term(nil, {
cwd = plugin.dir,
terminal = true,
close_on_exit = true,
enter = true,
})
end,
},
Expand Down Expand Up @@ -410,7 +407,7 @@ return {
-- The default is to disable on:
-- * VimEnter: not useful to cache anything else beyond startup
-- * BufReadPre: this will be triggered early when opening a file from the command line directly
disable_events = { "VimEnter", "BufReadPre" },
disable_events = { "UIEnter", "BufReadPre" },
ttl = 3600 * 24 * 5, -- keep unused modules for up to 5 days
},
reset_packpath = true, -- reset the package path to improve startup time
Expand Down Expand Up @@ -498,7 +495,7 @@ Any operation can be started from the UI, with a sub command or an API function:
| `:Lazy help` | `require("lazy").help()` | Toggle this help page |
| `:Lazy home` | `require("lazy").home()` | Go back to plugin list |
| `:Lazy install [plugins]` | `require("lazy").install(opts?)` | Install missing plugins |
| `:Lazy load {plugins}` | `require("lazy").load(opts)` | Load a plugin that has not been loaded yet. Similar to `:packadd`. Like `:Lazy load foo.nvim` |
| `:Lazy load {plugins}` | `require("lazy").load(opts)` | Load a plugin that has not been loaded yet. Similar to `:packadd`. Like `:Lazy load foo.nvim`. Use `:Lazy! load` to skip `cond` checks. |
| `:Lazy log [plugins]` | `require("lazy").log(opts?)` | Show recent updates |
| `:Lazy profile` | `require("lazy").profile()` | Show detailed profiling |
| `:Lazy restore [plugins]` | `require("lazy").restore(opts?)` | Updates all plugins to the state in the lockfile. For a single plugin: restore it to the state in the lockfile or to a given commit under the cursor |
Expand Down Expand Up @@ -532,9 +529,11 @@ Stats API (`require("lazy").stats()`):
-- when true, startuptime is the accurate cputime for the Neovim process. (Linux & Macos)
-- this is more accurate than `nvim --startuptime`, and as such will be slightly higher
-- when false, startuptime is calculated based on a delta with a timestamp when lazy started.
startuptime_cputime = false,
real_cputime = false,
count = 0, -- total number of plugins
loaded = 0, -- number of loaded plugins
---@type table<string, number>
times = {},
}
```

Expand Down Expand Up @@ -738,6 +737,7 @@ To uninstall **lazy.nvim**, you need to remove the following files and directori
| **LazyReasonCmd** | **_Operator_** | |
| **LazyReasonEvent** | **_Constant_** | |
| **LazyReasonFt** | **_Character_** | |
| **LazyReasonImport** | **_Identifier_** | |
| **LazyReasonKeys** | **_Statement_** | |
| **LazyReasonPlugin** | **_Special_** | |
| **LazyReasonRuntime** | **_@macro_** | |
Expand Down
10 changes: 6 additions & 4 deletions lua/lazy/core/loader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ end
---@class Loader
---@param plugins string|LazyPlugin|string[]|LazyPlugin[]
---@param reason {[string]:string}
function M.load(plugins, reason)
---@param opts? {force:boolean} when force is true, we skip the cond check
function M.load(plugins, reason, opts)
---@diagnostic disable-next-line: cast-local-type
plugins = (type(plugins) == "string" or plugins.name) and { plugins } or plugins
---@cast plugins (string|LazyPlugin)[]
Expand All @@ -174,19 +175,20 @@ function M.load(plugins, reason)
end
end
if plugin and not plugin._.loaded then
M._load(plugin, reason)
M._load(plugin, reason, opts)
end
end
end

---@param plugin LazyPlugin
---@param reason {[string]:string}
function M._load(plugin, reason)
---@param opts? {force:boolean} when force is true, we skip the cond check
function M._load(plugin, reason, opts)
if not plugin._.installed then
return Util.error("Plugin " .. plugin.name .. " is not installed")
end

if plugin.cond ~= nil then
if plugin.cond ~= nil and not (opts and opts.force) then
if plugin.cond == false or (type(plugin.cond) == "function" and not plugin.cond()) then
plugin._.cond = false
return
Expand Down
3 changes: 2 additions & 1 deletion lua/lazy/view/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ M.commands = {
end,
---@param opts ManagerOpts
load = function(opts)
require("lazy.core.loader").load(opts.plugins, { cmd = "LazyLoad" })
-- when a command is executed with a bang, wait will be set
require("lazy.core.loader").load(opts.plugins, { cmd = "Lazy load" }, { force = opts.wait })
end,
log = Manage.log,
build = Manage.build,
Expand Down
2 changes: 1 addition & 1 deletion lua/lazy/view/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ M.commands = {
id = 12,
},
load = {
desc = "Load a plugin that has not been loaded yet. Similar to `:packadd`. Like `:Lazy load foo.nvim`",
desc = "Load a plugin that has not been loaded yet. Similar to `:packadd`. Like `:Lazy load foo.nvim`. Use `:Lazy! load` to skip `cond` checks.",
id = 13,
plugins = true,
plugins_required = true,
Expand Down

0 comments on commit eed1ef3

Please sign in to comment.