lib/mk-neovim-plugin: allow lazy-loading without luaConfig

This commit is contained in:
Heitor Augusto 2024-12-25 17:25:53 -03:00 committed by nix-infra-bot
parent f878289722
commit 1671f8618f

View file

@ -113,15 +113,6 @@ let
inherit extraConfig cfg opts; inherit extraConfig cfg opts;
} }
)) ))
]
# Lua configuration code generation
++ lib.optionals hasLuaConfig [
# Add the plugin setup code `require('foo').setup(...)` to the lua configuration
(lib.optionalAttrs callSetup (lib.setAttrByPath loc { luaConfig.content = setupCode; }))
# When NOT lazy loading, write `luaConfig.content` to `configLocation`
(lib.mkIf (!cfg.lazyLoad.enable) luaConfigAtLocation)
# When lazy loading is enabled for this plugin, route its configuration to the enabled provider # When lazy loading is enabled for this plugin, route its configuration to the enabled provider
(lib.mkIf cfg.lazyLoad.enable { (lib.mkIf cfg.lazyLoad.enable {
@ -131,6 +122,7 @@ let
message = "You have enabled lazy loading for ${packPathName} but have not provided any configuration."; message = "You have enabled lazy loading for ${packPathName} but have not provided any configuration.";
} }
]; ];
plugins.lz-n = { plugins.lz-n = {
plugins = [ plugins = [
( (
@ -140,7 +132,7 @@ let
after = after =
let let
after = cfg.lazyLoad.settings.after or null; after = cfg.lazyLoad.settings.after or null;
default = "function()\n " + cfg.luaConfig.content + " \nend"; default = if hasLuaConfig then "function()\n " + cfg.luaConfig.content + " \nend" else null;
in in
if (lib.isString after || lib.types.rawLua.check after) then after else default; if (lib.isString after || lib.types.rawLua.check after) then after else default;
colorscheme = lib.mkIf isColorscheme (cfg.lazyLoad.settings.colorscheme or colorscheme); colorscheme = lib.mkIf isColorscheme (cfg.lazyLoad.settings.colorscheme or colorscheme);
@ -154,6 +146,15 @@ let
}; };
}) })
] ]
# Lua configuration code generation
++ lib.optionals hasLuaConfig [
# Add the plugin setup code `require('foo').setup(...)` to the lua configuration
(lib.optionalAttrs callSetup (lib.setAttrByPath loc { luaConfig.content = setupCode; }))
# When NOT lazy loading, write `luaConfig.content` to `configLocation`
(lib.mkIf (!cfg.lazyLoad.enable) luaConfigAtLocation)
]
) )
); );
}; };