mirror of
https://github.com/NotAShelf/neovim-flake.git
synced 2024-12-19 05:19:48 +01:00
lazy: add assertions against common problems (#476)
* lazy: allow null package * lazy: add assertions for common pitfalls * lazy: pass plugin name to custom load function * lazy: format description Co-authored-by: raf <raf@notashelf.dev> --------- Co-authored-by: raf <raf@notashelf.dev>
This commit is contained in:
parent
52ad5ec34c
commit
fee1b46924
2 changed files with 38 additions and 8 deletions
|
@ -3,7 +3,7 @@
|
|||
config,
|
||||
...
|
||||
}: let
|
||||
inherit (builtins) toJSON typeOf head length filter concatLists concatStringsSep;
|
||||
inherit (builtins) toJSON typeOf head length filter concatLists concatStringsSep tryEval;
|
||||
inherit (lib.attrsets) mapAttrsToList;
|
||||
inherit (lib.modules) mkIf mkMerge;
|
||||
inherit (lib.generators) mkLuaInline;
|
||||
|
@ -21,10 +21,36 @@
|
|||
else keySpec.action;
|
||||
};
|
||||
|
||||
toLuaLznSpec = name: spec:
|
||||
toLuaLznSpec = name: spec: let
|
||||
packageName =
|
||||
if typeOf spec.package == "string"
|
||||
then spec.package
|
||||
else if (spec.package ? pname && (tryEval spec.package.pname).success)
|
||||
then spec.package.pname
|
||||
else spec.package.name;
|
||||
in
|
||||
(removeAttrs spec ["package" "setupModule" "setupOpts" "keys"])
|
||||
// {
|
||||
"@1" = name;
|
||||
"@1" =
|
||||
if spec.package != null && packageName != name && spec.load == null
|
||||
then
|
||||
abort ''
|
||||
vim.lazy.plugins.${name} does not match the package name ${packageName}.
|
||||
|
||||
Please either:
|
||||
- rename it to vim.lazy.plugins.${packageName}, or
|
||||
- if you intend to use a custom loader, specify a
|
||||
vim.lazy.plugins.${name}.load function.
|
||||
''
|
||||
else if spec.package == null && spec.load == null
|
||||
then
|
||||
abort ''
|
||||
vim.lazy.plugins.${name} has null package but no load function given.
|
||||
|
||||
Please either specify a package, or (if you know what you're doing) provide a
|
||||
custom load function.
|
||||
''
|
||||
else name;
|
||||
beforeAll =
|
||||
if spec.beforeAll != null
|
||||
then
|
||||
|
@ -62,7 +88,7 @@
|
|||
if spec.load != null
|
||||
then
|
||||
mkLuaInline ''
|
||||
funcion()
|
||||
function(name)
|
||||
${spec.load}
|
||||
end
|
||||
''
|
||||
|
@ -76,7 +102,7 @@
|
|||
};
|
||||
lznSpecs = mapAttrsToList toLuaLznSpec cfg.plugins;
|
||||
|
||||
pluginPackages = mapAttrsToList (_: plugin: plugin.package) cfg.plugins;
|
||||
pluginPackages = filter (x: x != null) (mapAttrsToList (_: plugin: plugin.package) cfg.plugins);
|
||||
|
||||
specToNotLazyConfig = _: spec: ''
|
||||
do
|
||||
|
|
|
@ -66,8 +66,12 @@
|
|||
lznPluginType = submodule {
|
||||
options = {
|
||||
package = mkOption {
|
||||
type = pluginType;
|
||||
description = "Plugin package";
|
||||
type = nullOr pluginType;
|
||||
description = ''
|
||||
Plugin package.
|
||||
|
||||
If null, a custom load function must be provided
|
||||
'';
|
||||
};
|
||||
|
||||
setupModule = mkOption {
|
||||
|
@ -173,7 +177,7 @@
|
|||
description = ''
|
||||
Lua code to override the `vim.g.lz_n.load()` function for a single plugin.
|
||||
|
||||
This will be wrapped in a function.
|
||||
This will be wrapped in a `function(name) ... end`.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue