mirror of
https://github.com/zoriya/lz.n.git
synced 2026-06-03 03:01:25 +00:00
feat: automatically increase priority if colorscheme is set
This commit is contained in:
@@ -114,7 +114,7 @@ require("lz.n").load(plugins)
|
||||
| **ft** | `string?` or `string[]` | Lazy-load on filetype. | `ft` |
|
||||
| **keys** | `string?` or `string[]` or `lz.n.KeysSpec[]` | Lazy-load on key mapping. | `keys` |
|
||||
| **colorscheme** | `string?` or `string[]` | Lazy-load on colorscheme. | None. `lazy.nvim` lazy-loads colorschemes automatically[^2]. |
|
||||
| **priority** | `number?` | Only useful for **start** plugins (not lazy-loaded) to force loading certain plugins first. Default priority is `50`. It's recommended to set this to a high number for colorschemes. | `priority` |
|
||||
| **priority** | `number?` | Only useful for **start** plugins (not lazy-loaded) to force loading certain plugins first. Default priority is `50` (or `1000` if `colorscheme` is set). | `priority` |
|
||||
<!-- markdownlint-enable MD013 -->
|
||||
|
||||
[^1]: In contrast to `lazy.nvim`'s `name` field, `lz.n`'s `name` *is not optional*.
|
||||
@@ -147,7 +147,6 @@ require("lz.n").load {
|
||||
"sweetie.nvim",
|
||||
-- lazy-load when setting the `sweetie` colorscheme
|
||||
colorscheme = "sweetie",
|
||||
priority = 1000,
|
||||
},
|
||||
{
|
||||
"vim-startuptime",
|
||||
|
||||
+8
-1
@@ -6,6 +6,8 @@ local M = {}
|
||||
|
||||
local DEFAULT_PRIORITY = 50
|
||||
|
||||
local DEFAULT_COLORSCHEME_PRIORITY = 1000
|
||||
|
||||
---@package
|
||||
---@param plugin lz.n.Plugin
|
||||
function M._load(plugin)
|
||||
@@ -40,6 +42,11 @@ local function run_before_all(plugins)
|
||||
end
|
||||
end
|
||||
|
||||
---@param plugin lz.n.Plugin
|
||||
local function get_priority(plugin)
|
||||
return plugin.priority or (plugin.colorscheme and DEFAULT_COLORSCHEME_PRIORITY) or DEFAULT_PRIORITY
|
||||
end
|
||||
|
||||
---@param plugins table<string, lz.n.Plugin>
|
||||
---@return lz.n.Plugin[]
|
||||
local function get_eager_plugins(plugins)
|
||||
@@ -52,7 +59,7 @@ local function get_eager_plugins(plugins)
|
||||
table.sort(result, function(a, b)
|
||||
---@cast a lz.n.Plugin
|
||||
---@cast b lz.n.Plugin
|
||||
return (a.priority or DEFAULT_PRIORITY) > (b.priority or DEFAULT_PRIORITY)
|
||||
return get_priority(a) > get_priority(b)
|
||||
end)
|
||||
return result
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user