Skip to content

Commit 3bcc1bd

Browse files
committed
lib/plugins/mkVimPlugin: Support lazyloading
Signed-off-by: saygo-png <saygo.mail@proton.me>
1 parent faf1fb4 commit 3bcc1bd

File tree

1 file changed

+52
-4
lines changed

1 file changed

+52
-4
lines changed

lib/plugins/mk-vim-plugin.nix

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,26 +59,74 @@ let
5959
options = lib.setAttrByPath loc (
6060
{
6161
enable = lib.mkEnableOption name;
62+
lazyLoad = lib.nixvim.mkLazyLoadOption name;
6263
autoLoad = lib.nixvim.mkAutoLoadOption cfg name;
6364
}
6465
// settingsOption
6566
// extraOptions
6667
);
6768

6869
config = lib.mkIf cfg.enable (
70+
let
71+
globalsConfig = lib.nixvim.applyPrefixToAttrs globalPrefix (cfg.settings or { });
72+
in
6973
lib.mkMerge [
70-
{
71-
inherit extraPackages extraPlugins;
72-
globals = lib.nixvim.applyPrefixToAttrs globalPrefix (cfg.settings or { });
73-
}
74+
{ inherit extraPackages extraPlugins; }
75+
76+
(lib.mkIf cfg.lazyLoad.enable {
77+
assertions = [
78+
{
79+
assertion = (isColorscheme && colorscheme != null) || cfg.lazyLoad.settings != { };
80+
message = "You have enabled lazy loading for ${name} but have not provided any configuration.";
81+
}
82+
];
83+
84+
plugins.lz-n = {
85+
plugins = [
86+
(
87+
{
88+
# The packpath name is always the derivation name
89+
__unkeyed-1 = lib.getName cfg.package;
90+
# Use provided before, otherwise fallback to normal function wrapped globals config
91+
before =
92+
let
93+
before = cfg.lazyLoad.settings.before or null;
94+
default = ''
95+
function()
96+
local globals = ${lib.nixvim.toLuaObject globalsConfig}
97+
98+
for k,v in pairs(globals) do
99+
vim.g[k] = v
100+
end
101+
end
102+
'';
103+
in
104+
if (lib.isString before || lib.types.rawLua.check before) then before else default;
105+
colorscheme = lib.mkIf isColorscheme (cfg.lazyLoad.settings.colorscheme or colorscheme);
106+
}
107+
// lib.removeAttrs cfg.lazyLoad.settings [
108+
"before"
109+
"colorscheme"
110+
]
111+
)
112+
];
113+
};
114+
})
115+
116+
(lib.mkIf (!cfg.lazyLoad.enable) {
117+
globals = globalsConfig;
118+
})
119+
74120
(lib.optionalAttrs (isColorscheme && colorscheme != null) {
75121
colorscheme = lib.mkDefault colorscheme;
76122
})
123+
77124
(lib.optionalAttrs (args ? extraConfig) (
78125
lib.nixvim.plugins.utils.applyExtraConfig {
79126
inherit extraConfig cfg opts;
80127
}
81128
))
129+
82130
(lib.nixvim.plugins.utils.enableDependencies dependencies)
83131
]
84132
);

0 commit comments

Comments
 (0)