feat: loading plugins respect dependencies option
parent
b087119333
commit
cece8f6464
14
README.md
14
README.md
|
|
@ -42,7 +42,7 @@ A [neovim] plugin and configuration management plugin, highly inspired by [lazy]
|
|||
- [ ] on filetype
|
||||
- [ ] on event
|
||||
- [ ] on keybinding
|
||||
- [ ] load plugins in order (via plugin `dependencies` property)
|
||||
- [X] load plugins in order (via plugin `dependencies` property)
|
||||
- [ ] Generate spell files on build (maybe)
|
||||
|
||||
## SemVer
|
||||
|
|
@ -159,13 +159,13 @@ The Plugin configuration object accepts the following properties:
|
|||
> `src` as properties. The latter will be used to create a nix package of your
|
||||
> plugin on the fly.
|
||||
|
||||
> ³ Not yet implemented. The function is called, but the plugin is already loaded.
|
||||
> ³ When the plugin is not lazy, the `init` function is called after the plugin
|
||||
> is loaded as all non lazy plugin are loaded automatically.
|
||||
|
||||
> ⁴ Not yet implemented. `nix` handles the installation of your plugin,
|
||||
> therefore, this list is **NOT** to declare dependencies that the nix package
|
||||
> of the plugin doesn't know. This will tell `sloth-flake` in what order your
|
||||
> plugins should be loaded... when `sloth-flake` will handle asynchronous
|
||||
> loading... (Soon™).
|
||||
> ⁴ `nix` handles the installation of your plugin, therefore, this list is
|
||||
> **NOT** to declare dependencies that the nix package of the plugin doesn't
|
||||
> know. This will tell `sloth-flake` in what order your plugins should be
|
||||
> loaded.
|
||||
|
||||
> ⁵ Setting this property implicitly set `lazy` to `true`.
|
||||
|
||||
|
|
|
|||
|
|
@ -109,12 +109,12 @@
|
|||
memo
|
||||
// {
|
||||
${name} =
|
||||
{name = pluginName plugin.plugin;}
|
||||
{
|
||||
name = pluginName plugin.plugin;
|
||||
dependencies = map pluginName plugin.dependencies;
|
||||
}
|
||||
// (mkTypeFn "init")
|
||||
// (mkTypeFn "config")
|
||||
// (optionalAttrs (plugin.dependencies != []) {
|
||||
dependencies = map pluginName plugin.dependencies;
|
||||
})
|
||||
// (optionalAttrs plugin.lazy {
|
||||
lazy = true;
|
||||
})
|
||||
|
|
|
|||
|
|
@ -33,16 +33,24 @@ function M.config_non_lazy()
|
|||
end
|
||||
|
||||
function load_fn(type)
|
||||
return function(name)
|
||||
local function fn(name)
|
||||
local dep = M.get(name)
|
||||
if dep == nil then
|
||||
-- TODO Handle missing deps
|
||||
return
|
||||
end
|
||||
if priv.is[type][name] then
|
||||
return
|
||||
end
|
||||
priv.is[type][name] = true
|
||||
if dep[type] ~= nil then
|
||||
for _, child in ipairs(dep.dependencies) do
|
||||
fn(child)
|
||||
end
|
||||
dep[type]()
|
||||
end
|
||||
end
|
||||
return fn
|
||||
end
|
||||
|
||||
M.init = load_fn('init')
|
||||
|
|
@ -53,8 +61,15 @@ function M.import(name)
|
|||
return
|
||||
end
|
||||
local plugin = M.get(name)
|
||||
if plugin == nil then
|
||||
-- TODO Handle missing deps
|
||||
return
|
||||
end
|
||||
priv.is.import[name] = true
|
||||
if plugin.lazy then
|
||||
for _, dep in ipairs(plugin.dependencies) do
|
||||
M.import(dep)
|
||||
end
|
||||
vim.cmd("packadd " .. name)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in New Issue