mirror of https://github.com/folke/lazy.nvim.git
feat(plugin): added config.defaults.cond. Fixes #640
This commit is contained in:
parent
10f5844abf
commit
9afba388fa
|
@ -88,7 +88,7 @@ require("lazy").setup({
|
||||||
| **dev** | `boolean?` | When `true`, a local plugin directory will be used instead. See `config.dev` |
|
| **dev** | `boolean?` | When `true`, a local plugin directory will be used instead. See `config.dev` |
|
||||||
| **lazy** | `boolean?` | When `true`, the plugin will only be loaded when needed. Lazy-loaded plugins are automatically loaded when their Lua modules are `required`, or when one of the lazy-loading handlers triggers |
|
| **lazy** | `boolean?` | When `true`, the plugin will only be loaded when needed. Lazy-loaded plugins are automatically loaded when their Lua modules are `required`, or when one of the lazy-loading handlers triggers |
|
||||||
| **enabled** | `boolean?` or `fun():boolean` | When `false`, or if the `function` returns false, then this plugin will not be included in the spec |
|
| **enabled** | `boolean?` or `fun():boolean` | When `false`, or if the `function` returns false, then this plugin will not be included in the spec |
|
||||||
| **cond** | `boolean?` or `fun():boolean` | When `false`, or if the `function` returns false, then this plugin will not be loaded. Useful to disable some plugins in vscode, or firenvim for example. |
|
| **cond** | `boolean?` or `fun(LazyPlugin):boolean` | When `false`, or if the `function` returns false, then this plugin will not be loaded. Useful to disable some plugins in vscode, or firenvim for example. |
|
||||||
| **dependencies** | `LazySpec[]` | A list of plugin names or plugin specs that should be loaded when the plugin loads. Dependencies are always lazy-loaded unless specified otherwise. When specifying a name, make sure the plugin spec has been defined somewhere else. |
|
| **dependencies** | `LazySpec[]` | A list of plugin names or plugin specs that should be loaded when the plugin loads. Dependencies are always lazy-loaded unless specified otherwise. When specifying a name, make sure the plugin spec has been defined somewhere else. |
|
||||||
| **init** | `fun(LazyPlugin)` | `init` functions are always executed during startup |
|
| **init** | `fun(LazyPlugin)` | `init` functions are always executed during startup |
|
||||||
| **opts** | `table` or `fun(LazyPlugin, opts:table)` | `opts` should be a table (will be merged with parent specs), return a table (replaces parent specs) or should change a table. The table will be passed to the `Plugin.config()` function. Setting this value will imply `Plugin.config()` |
|
| **opts** | `table` or `fun(LazyPlugin, opts:table)` | `opts` should be a table (will be merged with parent specs), return a table (replaces parent specs) or should change a table. The table will be passed to the `Plugin.config()` function. Setting this value will imply `Plugin.config()` |
|
||||||
|
@ -303,6 +303,9 @@ return {
|
||||||
defaults = {
|
defaults = {
|
||||||
lazy = false, -- should plugins be lazy-loaded?
|
lazy = false, -- should plugins be lazy-loaded?
|
||||||
version = nil,
|
version = nil,
|
||||||
|
-- default `cond` you can use to globally disable a lot of plugins
|
||||||
|
-- when running inside vscode for example
|
||||||
|
cond = nil, ---@type boolean|fun(self:LazyPlugin):boolean|nil
|
||||||
-- version = "*", -- enable this to try installing the latest stable versions of plugins
|
-- version = "*", -- enable this to try installing the latest stable versions of plugins
|
||||||
},
|
},
|
||||||
-- leave nil when passing the spec as the first argument to setup()
|
-- leave nil when passing the spec as the first argument to setup()
|
||||||
|
|
|
@ -9,6 +9,9 @@ M.defaults = {
|
||||||
defaults = {
|
defaults = {
|
||||||
lazy = false, -- should plugins be lazy-loaded?
|
lazy = false, -- should plugins be lazy-loaded?
|
||||||
version = nil,
|
version = nil,
|
||||||
|
-- default `cond` you can use to globally disable a lot of plugins
|
||||||
|
-- when running inside vscode for example
|
||||||
|
cond = nil, ---@type boolean|fun(self:LazyPlugin):boolean|nil
|
||||||
-- version = "*", -- enable this to try installing the latest stable versions of plugins
|
-- version = "*", -- enable this to try installing the latest stable versions of plugins
|
||||||
},
|
},
|
||||||
-- leave nil when passing the spec as the first argument to setup()
|
-- leave nil when passing the spec as the first argument to setup()
|
||||||
|
|
|
@ -266,8 +266,12 @@ function M._load(plugin, reason, opts)
|
||||||
return Util.error("Plugin " .. plugin.name .. " is not installed")
|
return Util.error("Plugin " .. plugin.name .. " is not installed")
|
||||||
end
|
end
|
||||||
|
|
||||||
if plugin.cond ~= nil and not (opts and opts.force) then
|
local cond = plugin.cond
|
||||||
if plugin.cond == false or (type(plugin.cond) == "function" and not plugin.cond()) then
|
if cond == nil then
|
||||||
|
cond = Config.options.defaults.cond
|
||||||
|
end
|
||||||
|
if cond ~= nil and not (opts and opts.force) then
|
||||||
|
if cond == false or (type(cond) == "function" and not cond(plugin)) then
|
||||||
plugin._.cond = false
|
plugin._.cond = false
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue