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 filetype
|
||||||
- [ ] on event
|
- [ ] on event
|
||||||
- [ ] on keybinding
|
- [ ] 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)
|
- [ ] Generate spell files on build (maybe)
|
||||||
|
|
||||||
## SemVer
|
## 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
|
> `src` as properties. The latter will be used to create a nix package of your
|
||||||
> plugin on the fly.
|
> 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,
|
> ⁴ `nix` handles the installation of your plugin, therefore, this list is
|
||||||
> therefore, this list is **NOT** to declare dependencies that the nix package
|
> **NOT** to declare dependencies that the nix package of the plugin doesn't
|
||||||
> of the plugin doesn't know. This will tell `sloth-flake` in what order your
|
> know. This will tell `sloth-flake` in what order your plugins should be
|
||||||
> plugins should be loaded... when `sloth-flake` will handle asynchronous
|
> loaded.
|
||||||
> loading... (Soon™).
|
|
||||||
|
|
||||||
> ⁵ Setting this property implicitly set `lazy` to `true`.
|
> ⁵ Setting this property implicitly set `lazy` to `true`.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -109,12 +109,12 @@
|
||||||
memo
|
memo
|
||||||
// {
|
// {
|
||||||
${name} =
|
${name} =
|
||||||
{name = pluginName plugin.plugin;}
|
{
|
||||||
|
name = pluginName plugin.plugin;
|
||||||
|
dependencies = map pluginName plugin.dependencies;
|
||||||
|
}
|
||||||
// (mkTypeFn "init")
|
// (mkTypeFn "init")
|
||||||
// (mkTypeFn "config")
|
// (mkTypeFn "config")
|
||||||
// (optionalAttrs (plugin.dependencies != []) {
|
|
||||||
dependencies = map pluginName plugin.dependencies;
|
|
||||||
})
|
|
||||||
// (optionalAttrs plugin.lazy {
|
// (optionalAttrs plugin.lazy {
|
||||||
lazy = true;
|
lazy = true;
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -33,16 +33,24 @@ function M.config_non_lazy()
|
||||||
end
|
end
|
||||||
|
|
||||||
function load_fn(type)
|
function load_fn(type)
|
||||||
return function(name)
|
local function fn(name)
|
||||||
local dep = M.get(name)
|
local dep = M.get(name)
|
||||||
|
if dep == nil then
|
||||||
|
-- TODO Handle missing deps
|
||||||
|
return
|
||||||
|
end
|
||||||
if priv.is[type][name] then
|
if priv.is[type][name] then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
priv.is[type][name] = true
|
priv.is[type][name] = true
|
||||||
if dep[type] ~= nil then
|
if dep[type] ~= nil then
|
||||||
|
for _, child in ipairs(dep.dependencies) do
|
||||||
|
fn(child)
|
||||||
|
end
|
||||||
dep[type]()
|
dep[type]()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
return fn
|
||||||
end
|
end
|
||||||
|
|
||||||
M.init = load_fn('init')
|
M.init = load_fn('init')
|
||||||
|
|
@ -53,8 +61,15 @@ function M.import(name)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local plugin = M.get(name)
|
local plugin = M.get(name)
|
||||||
|
if plugin == nil then
|
||||||
|
-- TODO Handle missing deps
|
||||||
|
return
|
||||||
|
end
|
||||||
priv.is.import[name] = true
|
priv.is.import[name] = true
|
||||||
if plugin.lazy then
|
if plugin.lazy then
|
||||||
|
for _, dep in ipairs(plugin.dependencies) do
|
||||||
|
M.import(dep)
|
||||||
|
end
|
||||||
vim.cmd("packadd " .. name)
|
vim.cmd("packadd " .. name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue