2024-06-25 17:16:49 +02:00
|
|
|
{
|
|
|
|
lib,
|
|
|
|
config,
|
|
|
|
...
|
|
|
|
}: let
|
2024-08-03 18:01:34 +02:00
|
|
|
inherit (builtins) toJSON typeOf head length;
|
2024-06-25 17:16:49 +02:00
|
|
|
inherit (lib.modules) mkIf;
|
2024-07-10 00:28:18 +02:00
|
|
|
inherit (lib.attrsets) mapAttrsToList;
|
2024-07-24 12:52:47 +02:00
|
|
|
inherit (lib.generators) mkLuaInline;
|
|
|
|
inherit (lib.strings) optionalString;
|
2024-07-10 00:28:18 +02:00
|
|
|
inherit (lib.nvim.lua) toLuaObject;
|
2024-08-03 16:59:41 +02:00
|
|
|
inherit (lib.nvim.dag) entryBefore;
|
2024-06-25 17:16:49 +02:00
|
|
|
cfg = config.vim.lazy;
|
2024-07-10 00:28:18 +02:00
|
|
|
|
2024-08-03 14:45:48 +02:00
|
|
|
toLuzLznKeySpec = {
|
|
|
|
desc,
|
|
|
|
noremap,
|
|
|
|
expr,
|
|
|
|
nowait,
|
|
|
|
ft,
|
|
|
|
lhs,
|
|
|
|
rhs,
|
|
|
|
mode,
|
|
|
|
}: {
|
|
|
|
"@1" = lhs;
|
|
|
|
"@2" = rhs;
|
|
|
|
inherit desc noremap expr nowait ft mode;
|
|
|
|
};
|
|
|
|
|
2024-07-24 12:52:47 +02:00
|
|
|
toLuaLznSpec = name: spec:
|
2024-08-03 14:45:48 +02:00
|
|
|
(removeAttrs spec ["package" "setupModule" "setupOpts" "keys"])
|
2024-07-24 12:52:47 +02:00
|
|
|
// {
|
|
|
|
"@1" = name;
|
|
|
|
after = mkLuaInline ''
|
|
|
|
function()
|
|
|
|
${
|
|
|
|
optionalString (spec.setupModule != null)
|
|
|
|
"require(${toJSON spec.setupModule}).setup(${toLuaObject spec.setupOpts})"
|
|
|
|
}
|
|
|
|
${optionalString (spec.after != null) spec.after}
|
|
|
|
end
|
|
|
|
'';
|
2024-08-03 18:01:34 +02:00
|
|
|
keys =
|
|
|
|
if typeOf spec.keys == "list" && length spec.keys > 0 && typeOf (head spec.keys) == "set"
|
|
|
|
then map toLuzLznKeySpec spec.keys
|
|
|
|
else spec.keys;
|
2024-07-24 12:52:47 +02:00
|
|
|
};
|
2024-07-10 13:00:41 +02:00
|
|
|
lznSpecs = mapAttrsToList toLuaLznSpec cfg.plugins;
|
2024-06-25 17:16:49 +02:00
|
|
|
in {
|
|
|
|
config.vim = mkIf cfg.enable {
|
|
|
|
startPlugins = ["lz-n"];
|
|
|
|
|
2024-07-10 00:28:18 +02:00
|
|
|
optPlugins = mapAttrsToList (_: plugin: plugin.package) cfg.plugins;
|
|
|
|
|
2024-08-03 16:59:41 +02:00
|
|
|
luaConfigRC.lzn-load = entryBefore ["pluginConfigs"] ''
|
2024-07-10 00:28:18 +02:00
|
|
|
require('lz.n').load(${toLuaObject lznSpecs})
|
|
|
|
'';
|
2024-06-25 17:16:49 +02:00
|
|
|
};
|
|
|
|
}
|