refactor: re-order plugin and lz.n configs

lazy: make lzn-auto-require togglable
This commit is contained in:
Ching Pei Yang 2024-10-28 02:48:42 +01:00
parent eb95f77e75
commit 192340494b
No known key found for this signature in database
GPG key ID: B3841364253DC4C8
3 changed files with 34 additions and 10 deletions

View file

@ -76,7 +76,13 @@
then []
else [spec.keys];
notLazyConfig = concatStringsSep "\n" (mapAttrsToList specToNotLazyConfig cfg.plugins);
notLazyConfig =
concatStringsSep "\n"
(mapAttrsToList specToNotLazyConfig cfg.plugins);
beforeAllJoined =
concatStringsSep "\n"
(filter (x: x != null) (mapAttrsToList (_: spec: spec.beforeAll) cfg.plugins));
in {
config.vim = mkMerge [
(mkIf cfg.enable {
@ -84,17 +90,18 @@ in {
optPlugins = pluginPackages;
luaConfigRC.lzn-load = entryBefore ["pluginConfigs"] ''
lazy.builtLazyConfig = ''
require('lz.n').load(${toLuaObject lznSpecs})
${optionalString cfg.enableLznAutoRequire "require('lzn-auto-require').enable()"}
'';
})
(mkIf (!cfg.enable) {
startPlugins = pluginPackages;
luaConfigPre =
concatStringsSep "\n"
(filter (x: x != null) (mapAttrsToList (_: spec: spec.beforeAll) cfg.plugins));
luaConfigRC.unlazy = entryAfter ["pluginConfigs"] notLazyConfig;
lazy.builtLazyConfig = ''
${beforeAllJoined}
${notLazyConfig}
'';
keymaps = concatLists (mapAttrsToList specToKeymaps cfg.plugins);
})
];

View file

@ -181,7 +181,7 @@
};
in {
options.vim.lazy = {
enable = mkEnableOption "plugin lazy-loading" // {default = true;};
enable = mkEnableOption "plugin lazy-loading via lz.n and lzn-auto-require" // {default = true;};
loader = mkOption {
description = "Lazy loader to use";
type = enum ["lz.n"];
@ -215,5 +215,23 @@ in {
}
'';
};
enableLznAutoRequire = mkOption {
description = ''
Enable lzn-auto-require. Since builtin plugins rely on this, only turn
off for debugging.
'';
type = bool;
default = true;
};
builtLazyConfig = mkOption {
internal = true;
type = lines;
description = ''
The built config for lz.n, or if `vim.lazy.enable` is false, the
individual plugin configs.
'';
};
};
}

View file

@ -52,11 +52,10 @@ in {
optionsScript = entryAfter ["basic"] (concatLines optionsScript);
# Basic
pluginConfigs = entryAfter ["optionsScript"] pluginConfigs;
lazyConfigs = entryAfter ["optionsScript"] cfg.lazy.builtLazyConfig;
pluginConfigs = entryAfter ["lazyConfigs"] pluginConfigs;
extraPluginConfigs = entryAfter ["pluginConfigs"] extraPluginConfigs;
mappings = entryAfter ["extraPluginConfigs"] keymaps;
# FIXME: put this somewhere less stupid
footer = entryAfter ["mappings"] (optionalString config.vim.lazy.enable "require('lzn-auto-require').enable()");
};
builtLuaConfigRC = let