diff --git a/lib/neovim-plugin.nix b/lib/neovim-plugin.nix index e15856d4d..121298e96 100644 --- a/lib/neovim-plugin.nix +++ b/lib/neovim-plugin.nix @@ -194,6 +194,22 @@ ) ]; }; + plugins.lazy = lib.mkIf config.plugins.lazy.enable { + plugins = [ + ( + { + name = originalName; + main = luaName; + pkg = cfg.package; + # Use provided opts, otherwise fallback to settings + opts = cfg.lazyLoad.settings.opts or cfg.settings; + } + // (lib.removeAttrs cfg.lazyLoad.settings [ + "opts" + ]) + ) + ]; + }; }) ]) ) diff --git a/modules/lazyload.nix b/modules/lazyload.nix index 832d42579..f8cd75d00 100644 --- a/modules/lazyload.nix +++ b/modules/lazyload.nix @@ -45,13 +45,14 @@ in ) (builtins.attrNames config.plugins); count = builtins.length pluginsWithLazyLoad; in - lib.optionals (count > 0 && !config.plugins.lz-n.enable) [ + lib.optionals (count > 0 && !config.plugins.lz-n.enable && !config.plugins.lazy.enable) [ '' You have enabled lazy loading support for the following plugins but have not enabled a lazy loading provider. ${lib.concatImapStringsSep "\n" (i: x: "${toString i}. plugins.${x}") pluginsWithLazyLoad} Currently supported lazy providers: - lz-n + - lazy '' ]; }; diff --git a/tests/test-sources/plugins/lazyloading/lazy.nix b/tests/test-sources/plugins/lazyloading/lazy.nix new file mode 100644 index 000000000..a1d807253 --- /dev/null +++ b/tests/test-sources/plugins/lazyloading/lazy.nix @@ -0,0 +1,109 @@ +let + getFirstLazyPlugin = + config: + let + inherit (config.plugins.lazy) plugins; + in + if plugins == [ ] then null else builtins.head plugins; + + getPluginKeys = plugin: if plugin != null && builtins.isList plugin.keys then plugin.keys else [ ]; + getPluginCmd = plugin: if plugin != null && builtins.isList plugin.cmd then plugin.cmd else [ ]; +in +{ + lazy-load-neovim-plugin-configured = + { config, lib, ... }: + { + plugins = { + lazy = { + enable = true; + }; + + neotest = { + enable = true; + lazyLoad = { + enable = true; + settings = { + cmd = [ "Neotest" ]; + }; + }; + }; + }; + + assertions = + let + plugin = getFirstLazyPlugin config; + cmd = getPluginCmd plugin; + in + [ + { + assertion = (builtins.length config.plugins.lazy.plugins) == 1; + message = "`lazy.plugins` should have contained a single plugin configuration, but contained ${builtins.toJSON config.plugins.lz-n.plugins}"; + } + { + assertion = (builtins.length cmd) == 1; + message = "`lazy.plugins[0].cmd` should have contained a configuration."; + } + { + assertion = plugin != null && config.plugins.neotest.settings == plugin.opts; + message = "`lazy.plugins[0].opts` should have contained `neotest` settings."; + } + ]; + }; + + dont-lazy-load-unconfigured = + { config, ... }: + { + plugins = { + neotest = { + enable = true; + # Empty attrset shouldn't trigger lazy loading + lazyLoad = { }; + }; + lazy = { + enable = true; + }; + }; + + assertions = [ + { + assertion = (builtins.length config.plugins.lazy.plugins) == 0; + message = "`lazy.plugins` should have contained no plugin configuration, but contained ${builtins.toJSON config.plugins.lz-n.plugins}"; + } + ]; + }; + + lazy-load-enabled-automatically = + { config, ... }: + { + plugins = { + lazy = { + enable = true; + }; + neotest = { + enable = true; + lazyLoad = { + # Not setting lazyLoad.enable with configuration should enable + settings = { + cmd = [ "Neotest" ]; + }; + }; + }; + }; + + assertions = + let + plugin = getFirstLazyPlugin config; + cmd = getPluginCmd plugin; + in + [ + { + assertion = (builtins.length config.plugins.lazy.plugins) == 1; + message = "`lazy.plugins` should have contained a single plugin configuration, but contained ${builtins.toJSON config.plugins.lz-n.plugins}"; + } + { + assertion = (builtins.length cmd) == 1; + message = "`lazy.plugins[0].cmd` should have contained a configuration."; + } + ]; + }; +}