2024-09-30 19:56:31 +00:00
|
|
|
{
|
|
|
|
lib,
|
|
|
|
config,
|
|
|
|
...
|
|
|
|
}: let
|
2024-10-17 15:29:25 +00:00
|
|
|
inherit (builtins) toJSON typeOf head length filter concatLists concatStringsSep;
|
2024-10-17 14:53:36 +00:00
|
|
|
inherit (lib.attrsets) mapAttrsToList;
|
2024-10-06 17:15:39 +00:00
|
|
|
inherit (lib.modules) mkIf mkMerge;
|
2024-09-30 19:56:31 +00:00
|
|
|
inherit (lib.generators) mkLuaInline;
|
|
|
|
inherit (lib.strings) optionalString;
|
|
|
|
inherit (lib.nvim.lua) toLuaObject;
|
2024-10-06 17:15:39 +00:00
|
|
|
inherit (lib.nvim.dag) entryBefore entryAfter;
|
2024-09-30 19:56:31 +00:00
|
|
|
cfg = config.vim.lazy;
|
|
|
|
|
|
|
|
toLuaLznKeySpec = keySpec:
|
|
|
|
(removeAttrs keySpec ["key" "lua" "action"])
|
|
|
|
// {
|
|
|
|
"@1" = keySpec.key;
|
|
|
|
"@2" =
|
|
|
|
if keySpec.lua
|
|
|
|
then mkLuaInline keySpec.action
|
|
|
|
else keySpec.action;
|
|
|
|
};
|
|
|
|
|
2024-10-17 14:53:36 +00:00
|
|
|
toLuaLznSpec = name: spec:
|
2024-09-30 19:56:31 +00:00
|
|
|
(removeAttrs spec ["package" "setupModule" "setupOpts" "keys"])
|
|
|
|
// {
|
|
|
|
"@1" = name;
|
|
|
|
before =
|
|
|
|
if spec.before != null
|
|
|
|
then
|
|
|
|
mkLuaInline ''
|
|
|
|
function()
|
|
|
|
${spec.before}
|
|
|
|
end
|
|
|
|
''
|
|
|
|
else null;
|
|
|
|
|
|
|
|
after =
|
|
|
|
if spec.setupModule == null && spec.after == null
|
|
|
|
then null
|
|
|
|
else
|
|
|
|
mkLuaInline ''
|
|
|
|
function()
|
|
|
|
${
|
|
|
|
optionalString (spec.setupModule != null)
|
|
|
|
"require(${toJSON spec.setupModule}).setup(${toLuaObject spec.setupOpts})"
|
|
|
|
}
|
|
|
|
${optionalString (spec.after != null) spec.after}
|
|
|
|
end
|
|
|
|
'';
|
|
|
|
|
|
|
|
keys =
|
|
|
|
if typeOf spec.keys == "list" && length spec.keys > 0 && typeOf (head spec.keys) == "set"
|
|
|
|
then map toLuaLznKeySpec (filter (keySpec: keySpec.key != null) spec.keys)
|
|
|
|
# empty list or str or (listOf str)
|
|
|
|
else spec.keys;
|
|
|
|
};
|
2024-10-17 14:53:36 +00:00
|
|
|
lznSpecs = mapAttrsToList toLuaLznSpec cfg.plugins;
|
2024-10-06 17:15:39 +00:00
|
|
|
|
2024-10-17 14:53:36 +00:00
|
|
|
specToNotLazyConfig = _: spec: ''
|
2024-10-06 17:15:39 +00:00
|
|
|
do
|
|
|
|
${optionalString (spec.before != null) spec.before}
|
|
|
|
${optionalString (spec.setupModule != null)
|
|
|
|
"require(${toJSON spec.setupModule}).setup(${toLuaObject spec.setupOpts})"}
|
|
|
|
${optionalString (spec.after != null) spec.after}
|
|
|
|
end
|
|
|
|
'';
|
|
|
|
|
2024-10-17 14:53:36 +00:00
|
|
|
specToKeymaps = _: spec:
|
2024-10-06 17:15:39 +00:00
|
|
|
if typeOf spec.keys == "list"
|
|
|
|
then map (x: removeAttrs x ["ft"]) (filter (lznKey: lznKey.action != null && lznKey.ft == null) spec.keys)
|
|
|
|
else if spec.keys == null || typeOf spec.keys == "string"
|
|
|
|
then []
|
|
|
|
else [spec.keys];
|
|
|
|
|
2024-10-17 14:53:36 +00:00
|
|
|
notLazyConfig = concatStringsSep "\n" (mapAttrsToList specToNotLazyConfig cfg.plugins);
|
2024-09-30 19:56:31 +00:00
|
|
|
in {
|
2024-10-06 17:15:39 +00:00
|
|
|
config.vim = mkMerge [
|
|
|
|
(mkIf cfg.enable {
|
|
|
|
startPlugins = ["lz-n" "lzn-auto-require"];
|
2024-09-30 19:56:31 +00:00
|
|
|
|
2024-10-17 14:53:36 +00:00
|
|
|
optPlugins = mapAttrsToList (_: plugin: plugin.package) cfg.plugins;
|
2024-09-30 19:56:31 +00:00
|
|
|
|
2024-10-06 17:15:39 +00:00
|
|
|
luaConfigRC.lzn-load = entryBefore ["pluginConfigs"] ''
|
|
|
|
require('lz.n').load(${toLuaObject lznSpecs})
|
|
|
|
'';
|
|
|
|
})
|
2024-10-22 13:31:11 +00:00
|
|
|
|
2024-10-17 15:29:25 +00:00
|
|
|
(mkIf (!cfg.enable) {
|
|
|
|
startPlugins = mapAttrsToList (_: plugin: plugin.package) cfg.plugins;
|
|
|
|
luaConfigPre =
|
|
|
|
concatStringsSep "\n"
|
|
|
|
(filter (x: x != null) (mapAttrsToList (_: spec: spec.beforeAll) cfg.plugins));
|
|
|
|
luaConfigRC.unlazy = entryAfter ["pluginConfigs"] notLazyConfig;
|
|
|
|
keymaps = concatLists (mapAttrsToList specToKeymaps cfg.plugins);
|
|
|
|
})
|
2024-10-06 17:15:39 +00:00
|
|
|
];
|
2024-09-30 19:56:31 +00:00
|
|
|
}
|