feat: can load lazy plugins via placeholder `cmd`s
parent
5291529e6f
commit
81d82e05a2
13
README.md
13
README.md
|
|
@ -38,7 +38,7 @@ A [neovim] plugin and configuration management plugin, highly inspired by [lazy]
|
||||||
- [X] Generate default `init.lua`
|
- [X] Generate default `init.lua`
|
||||||
- [X] Accepts your own `init.lua`
|
- [X] Accepts your own `init.lua`
|
||||||
- [ ] Lazy load your plugins
|
- [ ] Lazy load your plugins
|
||||||
- [ ] on command
|
- [X] on command
|
||||||
- [ ] on filetype
|
- [ ] on filetype
|
||||||
- [ ] on event
|
- [ ] on event
|
||||||
- [ ] on keybinding
|
- [ ] on keybinding
|
||||||
|
|
@ -149,10 +149,11 @@ The Plugin configuration object accepts the following properties:
|
||||||
| name | default | description |
|
| name | default | description |
|
||||||
|----------------|---------|-----------------------------------------------------------------|
|
|----------------|---------|-----------------------------------------------------------------|
|
||||||
| `plugin` | N/A | The plugin to load² **REQUIRED** |
|
| `plugin` | N/A | The plugin to load² **REQUIRED** |
|
||||||
| `init` | `null` | lua code (as string of path) to call before loading the plugin³ |
|
| `init` | `null` | Lua code (as string of path) to call before loading the plugin³ |
|
||||||
| `config` | `null` | lua code (as string of path) to call after loading the plugin |
|
| `config` | `null` | Lua code (as string of path) to call after loading the plugin |
|
||||||
| `dependencies` | [] | The plugin dependencies⁴ |
|
| `dependencies` | `[]` | The plugin dependencies⁴ |
|
||||||
| `lazy` | `false` | should the plugin be loaded lazily |
|
| `lazy` | `false` | Should the plugin be loaded lazily |
|
||||||
|
| `cmd` | `[]` | Command to put as place_holder to lazy load the plugin⁵ |
|
||||||
|
|
||||||
> ² The plugin can be either a nix package or an object with only `name` and
|
> ² The plugin can be either a nix package or an object with only `name` and
|
||||||
> `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
|
||||||
|
|
@ -166,6 +167,8 @@ The Plugin configuration object accepts the following properties:
|
||||||
> plugins should be loaded... when `sloth-flake` will handle asynchronous
|
> plugins should be loaded... when `sloth-flake` will handle asynchronous
|
||||||
> loading... (Soon™).
|
> loading... (Soon™).
|
||||||
|
|
||||||
|
> ⁵ Setting this property implicitly set `lazy` to `true`.
|
||||||
|
|
||||||
### neovim (lua)
|
### neovim (lua)
|
||||||
|
|
||||||
#### Using default `init.lua`
|
#### Using default `init.lua`
|
||||||
|
|
|
||||||
|
|
@ -97,7 +97,8 @@
|
||||||
then plugin.pname
|
then plugin.pname
|
||||||
else plugin.name;
|
else plugin.name;
|
||||||
hasDeps = plugin ? dependencies && plugin.dependencies != [];
|
hasDeps = plugin ? dependencies && plugin.dependencies != [];
|
||||||
isLazy = plugin ? lazy && plugin.lazy;
|
isLazy = plugin ? lazy && plugin.lazy || hasCommands;
|
||||||
|
hasCommands = plugin ? cmd;
|
||||||
name = pluginName plugin.plugin;
|
name = pluginName plugin.plugin;
|
||||||
in
|
in
|
||||||
memo
|
memo
|
||||||
|
|
@ -108,9 +109,12 @@
|
||||||
// (mkTypeFn "config")
|
// (mkTypeFn "config")
|
||||||
// (optionalAttrs hasDeps {
|
// (optionalAttrs hasDeps {
|
||||||
dependencies = map pluginName plugin.dependencies;
|
dependencies = map pluginName plugin.dependencies;
|
||||||
})
|
}
|
||||||
// (optionalAttrs isLazy {
|
// (optionalAttrs isLazy {
|
||||||
lazy = true;
|
lazy = true;
|
||||||
|
}))
|
||||||
|
// (optionalAttrs hasCommands {
|
||||||
|
inherit (plugin) cmd;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
pluginsLuaDef = plugins: lua.nix2lua (foldl' pluginLuaDef {} plugins);
|
pluginsLuaDef = plugins: lua.nix2lua (foldl' pluginLuaDef {} plugins);
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@
|
||||||
|
|
||||||
extractPlugin = p: {
|
extractPlugin = p: {
|
||||||
inherit (p) plugin;
|
inherit (p) plugin;
|
||||||
optional = p ? lazy && p.lazy;
|
optional = p ? lazy && p.lazy || p ? cmd;
|
||||||
};
|
};
|
||||||
extractPlugins = map extractPlugin;
|
extractPlugins = map extractPlugin;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,9 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
# The plugin type of dependencies
|
# The plugin type of dependencies
|
||||||
pluginType = with yants;
|
pluginType = with yants; let
|
||||||
# let stringList = list string in
|
stringList = list string;
|
||||||
|
in
|
||||||
struct "plugin" {
|
struct "plugin" {
|
||||||
# Whether this plugin should be enabled. This option allows specific
|
# Whether this plugin should be enabled. This option allows specific
|
||||||
# plugins to be disabled.
|
# plugins to be disabled.
|
||||||
|
|
@ -51,7 +52,7 @@
|
||||||
# events = option stringList;
|
# events = option stringList;
|
||||||
|
|
||||||
# List of commands on which the plugin should be loaded
|
# List of commands on which the plugin should be loaded
|
||||||
# commands = option stringList;
|
cmd = option stringList;
|
||||||
|
|
||||||
# List of filetypes on which the plugin should be loaded
|
# List of filetypes on which the plugin should be loaded
|
||||||
# filetypes = option stringList;
|
# filetypes = option stringList;
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ local priv = {
|
||||||
init = {},
|
init = {},
|
||||||
import = {},
|
import = {},
|
||||||
config = {},
|
config = {},
|
||||||
|
shim = {},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -62,7 +63,12 @@ function M.is_imported(name)
|
||||||
return priv.is.import[name] or false
|
return priv.is.import[name] or false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function M.is_loaded(name)
|
||||||
|
return priv.is.config[name] or false
|
||||||
|
end
|
||||||
|
|
||||||
function M.load(name)
|
function M.load(name)
|
||||||
|
unshim_plugin(name)
|
||||||
M.init(name)
|
M.init(name)
|
||||||
M.import(name)
|
M.import(name)
|
||||||
M.config(name)
|
M.config(name)
|
||||||
|
|
@ -86,6 +92,49 @@ function M.non_lazy_deps()
|
||||||
end):totable()
|
end):totable()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function M.lazy_deps()
|
||||||
|
return M.deps_iter_by(function(dep)
|
||||||
|
return dep.lazy
|
||||||
|
end):totable()
|
||||||
|
end
|
||||||
|
|
||||||
|
function lazy_load_dep(dep, cmd)
|
||||||
|
return function(param)
|
||||||
|
M.load(dep.name)
|
||||||
|
local bang = param.bang and '!' or ''
|
||||||
|
vim.cmd(cmd .. bang .. ' ' .. param.args)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function shim_plugin(dep)
|
||||||
|
if priv.is.shim[dep.name] then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
priv.is.shim[dep.name] = true
|
||||||
|
if dep.cmd then
|
||||||
|
for _, cmd in ipairs(dep.cmd) do
|
||||||
|
vim.api.nvim_create_user_command(cmd, lazy_load_dep(dep, cmd), {
|
||||||
|
desc = "Sloth-flake placeholder for plugin " .. dep.name,
|
||||||
|
nargs = '*',
|
||||||
|
bang = true,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function unshim_plugin(name)
|
||||||
|
local dep = M.get(name)
|
||||||
|
if not priv.is.shim[name] then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
priv.is.shim[name] = nil
|
||||||
|
if dep.cmd then
|
||||||
|
for _, cmd in ipairs(dep.cmd) do
|
||||||
|
vim.api.nvim_del_user_command(cmd)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function M.setup(config)
|
function M.setup(config)
|
||||||
local post_init = config and config.post_init or function() end
|
local post_init = config and config.post_init or function() end
|
||||||
|
|
||||||
|
|
@ -93,6 +142,11 @@ function M.setup(config)
|
||||||
post_init()
|
post_init()
|
||||||
M.import_non_lazy()
|
M.import_non_lazy()
|
||||||
M.config_non_lazy()
|
M.config_non_lazy()
|
||||||
|
|
||||||
|
local lazy_deps = M.lazy_deps()
|
||||||
|
for _, dep in ipairs(lazy_deps) do
|
||||||
|
shim_plugin(dep)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue