From 301868d380d267a313a4a7aa6344e03ab8f16074 Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Fri, 11 Oct 2024 21:34:28 -0500 Subject: [PATCH 01/11] lib/neovim-plugin: support lazy loading luaConfig.content --- lib/neovim-plugin.nix | 26 +++++++++++++++++- tests/test-sources/plugins/lazy-load.nix | 34 ++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 tests/test-sources/plugins/lazy-load.nix diff --git a/lib/neovim-plugin.nix b/lib/neovim-plugin.nix index 4fafb436ff..0f40fd416f 100644 --- a/lib/neovim-plugin.nix +++ b/lib/neovim-plugin.nix @@ -113,6 +113,30 @@ ''; internal = true; }; + + lazyLoad = lib.mkOption { + default = { + enable = false; + }; + description = '' + Lazy load configuration settings. + ''; + type = lib.types.submodule { + options = { + enable = lib.mkOption { + default = false; + type = lib.types.bool; + description = '' + Whether to lazy load the plugin. + + If you enable this, the plugin's lua configuration will need to be manually loaded by other means. + + A usage would be passing the plugin's luaConfig to the `plugins.lz-n.plugins` configuration. + ''; + }; + }; + }; + }; } // lib.optionalAttrs hasSettings { settings = lib.nixvim.mkSettingsOption { @@ -162,7 +186,7 @@ (lib.optionalAttrs callSetup { ${namespace}.${name}.luaConfig.content = setupCode; }) # Write the lua configuration `luaConfig.content` to the config file - (setLuaConfig cfg.luaConfig.content) + (lib.mkIf (!cfg.lazyLoad.enable) (setLuaConfig cfg.luaConfig.content)) ]) ) ); diff --git a/tests/test-sources/plugins/lazy-load.nix b/tests/test-sources/plugins/lazy-load.nix new file mode 100644 index 0000000000..24dc614071 --- /dev/null +++ b/tests/test-sources/plugins/lazy-load.nix @@ -0,0 +1,34 @@ +{ + lazy-load-plugin = + { config, ... }: + { + plugins = { + lz-n = { + enable = true; + plugins = [ + { + __unkeyed-1 = "neotest"; + after.__raw = '' + function() + ${config.plugins.neotest.luaConfig.content} + end + ''; + keys = [ + { + __unkeyed-1 = "nt"; + __unkeyed-3 = "Neotest summary"; + desc = "Summary toggle"; + } + ]; + + } + ]; + }; + + neotest = { + enable = true; + lazyLoad.enable = true; + }; + }; + }; +} From 6ed719dba8a5ed821ae525311669e7195422cf6f Mon Sep 17 00:00:00 2001 From: psfloyd Date: Fri, 9 Aug 2024 02:07:00 -0300 Subject: [PATCH 02/11] lib/options: added mkLazyLoadOption --- lib/default.nix | 1 + lib/options.nix | 108 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+) diff --git a/lib/default.nix b/lib/default.nix index 3d357d7c66..d7534078aa 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -66,6 +66,7 @@ lib.fix ( defaultNullOpts mkCompositeOption mkCompositeOption' + mkLazyLoadOption mkNullOrLua mkNullOrLua' mkNullOrLuaFn diff --git a/lib/options.nix b/lib/options.nix index 02ce903acf..822abb8a13 100644 --- a/lib/options.nix +++ b/lib/options.nix @@ -333,5 +333,113 @@ rec { else example; }; + + mkLazyLoadOption = + { + originalName, + lazyLoadDefaults ? { }, + }: + lib.mkOption { + description = '' + Lazy-load settings for ${originalName}. + ''; + type = + let + triggerType = + with types; + oneOf [ + rawLua + str + (listOf str) + ]; + in + types.submodule { + options = with defaultNullOpts; { + + enable = lib.mkEnableOption '' + lazy-loading for ${originalName} + ''; + + # Spec loading: + enabled = mkStrLuaFnOr types.bool (lazyLoadDefaults.enabledInSpec or null) '' + When false, or if the function returns false, then ${originalName} will not be included in the spec. + + Equivalence: lz.n => enabled; lazy.nvim => enabled + ''; + + priority = mkNullable types.number (lazyLoadDefaults.priority or null) '' + Only useful for start plugins (not lazy-loaded) to force loading certain plugins first. + + Equivalence: lz.n => priority; lazy.nvim => priority + ''; + + # Spec setup + # Actions + beforeAll = mkLuaFn (lazyLoadDefaults.beforeAll or null) '' + Always executed before any plugins are loaded. + + Equivalence: lz.n => beforeAll; lazy.nvim => init + ''; + + before = mkLuaFn (lazyLoadDefaults.before or null) '' + Executed before ${originalName} is loaded. + + Equivalence: lz.n => before; lazy.nvim => None + ''; + + after = mkLuaFn (lazyLoadDefaults.after or null) '' + Executed after ${originalName} is loaded. + + Equivalence: lz.n => after; lazy.nvim => config + ''; + + # Triggers + event = mkNullable triggerType (lazyLoadDefaults.event or null) '' + Lazy-load on event. Events can be specified as `BufEnter` or with a pattern like `BufEnter *.lua` + + Equivalence: lz.n => event; lazy.nvim => event + ''; + + cmd = mkNullable triggerType (lazyLoadDefaults.cmd or null) '' + Lazy-load on command. + + Equivalence: lz.n => cmd; lazy.nvim => cmd + ''; + + ft = mkNullable triggerType (lazyLoadDefaults.ft or null) '' + Lazy-load on filetype. + + Equivalence: lz.n => ft; lazy.nvim => ft + ''; + + keys = + mkNullable (types.listOf lib.nixvim.keymaps.mapOptionSubmodule) (lazyLoadDefaults.keys or null) + '' + Lazy-load on key mapping. Use the same format as `config.keymaps`. + + Equivalence: lz.n => keys; lazy.nvim => keys + ''; + + colorscheme = mkNullable triggerType (lazyLoadDefaults.colorscheme or null) '' + Lazy-load on colorscheme. + + Equivalence: lz.n => colorscheme; lazy.nvim => None + ''; + + extraSettings = mkSettingsOption { + description = '' + Extra settings to pass to the lazy loader backend. + ''; + example = { + dependencies = { + __unkeyed-1 = "nvim-lua/plenary.nvim"; + lazy = true; + }; + }; + }; + }; + }; + default = lazyLoadDefaults; + }; } // removed From da30527de18ea14971d176e81eb4e39037035838 Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Mon, 2 Dec 2024 11:01:00 -0600 Subject: [PATCH 03/11] lib/neovim-plugin: use mkLazyLoadOption --- lib/neovim-plugin.nix | 27 +++++---------------------- lib/options.nix | 10 ++++------ 2 files changed, 9 insertions(+), 28 deletions(-) diff --git a/lib/neovim-plugin.nix b/lib/neovim-plugin.nix index 0f40fd416f..be5c7bc49d 100644 --- a/lib/neovim-plugin.nix +++ b/lib/neovim-plugin.nix @@ -114,28 +114,11 @@ internal = true; }; - lazyLoad = lib.mkOption { - default = { - enable = false; - }; - description = '' - Lazy load configuration settings. - ''; - type = lib.types.submodule { - options = { - enable = lib.mkOption { - default = false; - type = lib.types.bool; - description = '' - Whether to lazy load the plugin. - - If you enable this, the plugin's lua configuration will need to be manually loaded by other means. - - A usage would be passing the plugin's luaConfig to the `plugins.lz-n.plugins` configuration. - ''; - }; - }; - }; + lazyLoad = lib.nixvim.mkLazyLoadOption { + inherit originalName; + lazyLoadDefaults = ( + lib.optionalAttrs (isColorscheme && colorscheme != null) { inherit colorscheme; } + ); }; } // lib.optionalAttrs hasSettings { diff --git a/lib/options.nix b/lib/options.nix index 822abb8a13..1e4cafe578 100644 --- a/lib/options.nix +++ b/lib/options.nix @@ -412,13 +412,11 @@ rec { Equivalence: lz.n => ft; lazy.nvim => ft ''; - keys = - mkNullable (types.listOf lib.nixvim.keymaps.mapOptionSubmodule) (lazyLoadDefaults.keys or null) - '' - Lazy-load on key mapping. Use the same format as `config.keymaps`. + keys = mkListOf (types.attrsOf types.anything) (lazyLoadDefaults.keys or null) '' + Lazy-load on key mapping. - Equivalence: lz.n => keys; lazy.nvim => keys - ''; + Equivalence: lz.n => keys; lazy.nvim => keys + ''; colorscheme = mkNullable triggerType (lazyLoadDefaults.colorscheme or null) '' Lazy-load on colorscheme. From 3cfde1554c3aff3a3652a2779fec0170cf3c6f34 Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Mon, 2 Dec 2024 12:23:45 -0600 Subject: [PATCH 04/11] lib/neovim-plugin: support lz-n lazy config --- lib/neovim-plugin.nix | 34 ++++++- lib/options.nix | 9 ++ tests/test-sources/plugins/lazy-load.nix | 119 ++++++++++++++++++++--- 3 files changed, 147 insertions(+), 15 deletions(-) diff --git a/lib/neovim-plugin.nix b/lib/neovim-plugin.nix index be5c7bc49d..250692a5e7 100644 --- a/lib/neovim-plugin.nix +++ b/lib/neovim-plugin.nix @@ -116,9 +116,9 @@ lazyLoad = lib.nixvim.mkLazyLoadOption { inherit originalName; - lazyLoadDefaults = ( - lib.optionalAttrs (isColorscheme && colorscheme != null) { inherit colorscheme; } - ); + lazyLoadDefaults = lib.optionalAttrs (isColorscheme && colorscheme != null) { + inherit colorscheme; + }; }; } // lib.optionalAttrs hasSettings { @@ -171,6 +171,34 @@ # Write the lua configuration `luaConfig.content` to the config file (lib.mkIf (!cfg.lazyLoad.enable) (setLuaConfig cfg.luaConfig.content)) ]) + ++ (lib.optionals hasConfigAttrs [ + (lib.mkIf (cfg.lazyLoad.backend == "lz.n") { + plugins.lz-n = { + # infinite recursion? + # enable = true; + plugins = [ + { + # TODO: handle this for every plugin properly + __unkeyed-1 = originalName; + # Use provided after, otherwise fallback to normal lua content + after = if cfg.lazyLoad.after != null then cfg.lazyLoad.after else cfg.luaConfig.content; + inherit (cfg.lazyLoad) + enabled + priority + before + beforeAll + event + cmd + ft + keys + colorscheme + extraSettings + ; + } + ]; + }; + }) + ]) ) ); }; diff --git a/lib/options.nix b/lib/options.nix index 1e4cafe578..2ee3e1949d 100644 --- a/lib/options.nix +++ b/lib/options.nix @@ -360,6 +360,15 @@ rec { lazy-loading for ${originalName} ''; + backend = + mkEnumFirstDefault + [ + "lz.n" + ] + '' + The lazy-loading backend to use. + ''; + # Spec loading: enabled = mkStrLuaFnOr types.bool (lazyLoadDefaults.enabledInSpec or null) '' When false, or if the function returns false, then ${originalName} will not be included in the spec. diff --git a/tests/test-sources/plugins/lazy-load.nix b/tests/test-sources/plugins/lazy-load.nix index 24dc614071..0044a5c701 100644 --- a/tests/test-sources/plugins/lazy-load.nix +++ b/tests/test-sources/plugins/lazy-load.nix @@ -1,34 +1,129 @@ { - lazy-load-plugin = + lazy-load-neovim-plugin = { config, ... }: { plugins = { + lz-n = { + enable = true; + }; + + neotest = { + enable = true; + lazyLoad = { + enable = true; + keys = [ + { + __unkeyed-1 = "nt"; + __unkeyed-3 = "Neotest summary"; + desc = "Summary toggle"; + } + ]; + }; + }; + }; + + assertions = [ + { + assertion = (builtins.length config.plugins.lz-n.plugins) == 1; + message = "`lz-n.plugins` should have contained a single plugin configuration, but contained ${builtins.toJSON config.plugins.lz-n.plugins}"; + } + { + assertion = + let + plugin = builtins.head config.plugins.lz-n.plugins; + keys = if builtins.isList plugin.keys then plugin.keys else [ ]; + in + (builtins.length keys) == 1; + message = "`lz-n.plugins[0].keys` should have contained a configuration."; + } + ]; + }; + + lazy-load-lz-n = + { config, ... }: + { + plugins = { + codesnap = { + enable = true; + lazyLoad.enable = true; + }; lz-n = { enable = true; plugins = [ { - __unkeyed-1 = "neotest"; + __unkeyed-1 = "codesnap"; after.__raw = '' function() - ${config.plugins.neotest.luaConfig.content} + ${config.plugins.codesnap.luaConfig.content} end ''; + cmd = [ + "CodeSnap" + "CodeSnapSave" + "CodeSnapHighlight" + "CodeSnapSaveHighlight" + ]; keys = [ { - __unkeyed-1 = "nt"; - __unkeyed-3 = "Neotest summary"; - desc = "Summary toggle"; + __unkeyed-1 = "cc"; + __unkeyed-3 = "CodeSnap"; + desc = "Copy"; + mode = "v"; + } + { + __unkeyed-1 = "cs"; + __unkeyed-3 = "CodeSnapSave"; + desc = "Save"; + mode = "v"; + } + { + __unkeyed-1 = "ch"; + __unkeyed-3 = "CodeSnapHighlight"; + desc = "Highlight"; + mode = "v"; + } + { + __unkeyed-1 = "cH"; + __unkeyed-3 = "CodeSnapSaveHighlight"; + desc = "Save Highlight"; + mode = "v"; } ]; - } ]; }; - - neotest = { - enable = true; - lazyLoad.enable = true; - }; }; + assertions = [ + { + assertion = (builtins.length config.plugins.lz-n.plugins) == 1; + message = "`lz-n.plugins` should have contained a single plugin configuration, but contained ${builtins.toJSON config.plugins.lz-n.plugins}"; + } + { + assertion = + let + plugin = builtins.head config.plugins.lz-n.plugins; + keys = if builtins.isList plugin.keys then plugin.keys else [ ]; + in + (builtins.length keys) == 4; + message = + let + plugin = builtins.head config.plugins.lz-n.plugins; + in + "`lz-n.plugins[0].keys` should have contained 4 key configurations, but contained ${builtins.toJSON (plugin.keys)}"; + } + { + assertion = + let + plugin = builtins.head config.plugins.lz-n.plugins; + cmd = if builtins.isList plugin.cmd then plugin.cmd else [ ]; + in + (builtins.length cmd) == 4; + message = + let + plugin = builtins.head config.plugins.lz-n.plugins; + in + "`lz-n.plugins[0].cmd` should have contained 4 cmd configurations, but contained ${builtins.toJSON (plugin.cmd)}"; + } + ]; }; } From c3f9cb721c7d920c281139b90254732870679401 Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Mon, 2 Dec 2024 13:50:48 -0600 Subject: [PATCH 05/11] lib/neovim-plugin: refactor mkLazyLoadOption --- lib/neovim-plugin.nix | 65 +++---- lib/options.nix | 144 ++++++++-------- tests/test-sources/plugins/lazy-load.nix | 207 +++++++++++++++++++++-- 3 files changed, 294 insertions(+), 122 deletions(-) diff --git a/lib/neovim-plugin.nix b/lib/neovim-plugin.nix index 250692a5e7..1f1b05d28f 100644 --- a/lib/neovim-plugin.nix +++ b/lib/neovim-plugin.nix @@ -89,6 +89,7 @@ options.${namespace}.${name} = { enable = lib.mkEnableOption originalName; + lazyLoad = lib.nixvim.mkLazyLoadOption originalName; package = if lib.isOption package then package @@ -113,13 +114,6 @@ ''; internal = true; }; - - lazyLoad = lib.nixvim.mkLazyLoadOption { - inherit originalName; - lazyLoadDefaults = lib.optionalAttrs (isColorscheme && colorscheme != null) { - inherit colorscheme; - }; - }; } // lib.optionalAttrs hasSettings { settings = lib.nixvim.mkSettingsOption { @@ -168,33 +162,42 @@ # Add the plugin setup code `require('foo').setup(...)` to the lua configuration (lib.optionalAttrs callSetup { ${namespace}.${name}.luaConfig.content = setupCode; }) - # Write the lua configuration `luaConfig.content` to the config file + # Write the lua configuration `luaConfig.content` to the config file when lazy loading is not enabled (lib.mkIf (!cfg.lazyLoad.enable) (setLuaConfig cfg.luaConfig.content)) - ]) - ++ (lib.optionals hasConfigAttrs [ - (lib.mkIf (cfg.lazyLoad.backend == "lz.n") { + + # When lazy loading is enabled for this plugin, route its configuration to the enabled provider + (lib.mkIf cfg.lazyLoad.enable { + assertions = [ + { + assertion = (isColorscheme && colorscheme != null) || cfg.lazyLoad.settings != { }; + message = "You have enabled lazy loading for ${originalName} but have not provided any configuration."; + } + ]; plugins.lz-n = { - # infinite recursion? - # enable = true; plugins = [ - { - # TODO: handle this for every plugin properly - __unkeyed-1 = originalName; - # Use provided after, otherwise fallback to normal lua content - after = if cfg.lazyLoad.after != null then cfg.lazyLoad.after else cfg.luaConfig.content; - inherit (cfg.lazyLoad) - enabled - priority - before - beforeAll - event - cmd - ft - keys - colorscheme - extraSettings - ; - } + ( + { + __unkeyed-1 = originalName; + # Use provided after, otherwise fallback to normal lua content + after = + if cfg.lazyLoad.settings.after != null then + cfg.lazyLoad.settings.after + else + # We need to wrap it in a function so it doesn't execute immediately + "function()\n " + cfg.luaConfig.content + " \nend"; + colorscheme = + if cfg.lazyLoad.settings.colorscheme != null then + cfg.lazyLoad.settings.colorscheme + else if (isColorscheme && colorscheme != null) then + colorscheme + else + null; + } + // lib.removeAttrs cfg.lazyLoad.settings [ + "after" + "colorscheme" + ] + ) ]; }; }) diff --git a/lib/options.nix b/lib/options.nix index 2ee3e1949d..050ad1abc0 100644 --- a/lib/options.nix +++ b/lib/options.nix @@ -335,14 +335,14 @@ rec { }; mkLazyLoadOption = - { - originalName, - lazyLoadDefaults ? { }, - }: + originalName: lib.mkOption { description = '' Lazy-load settings for ${originalName}. ''; + default = { + enable = false; + }; type = let triggerType = @@ -353,100 +353,94 @@ rec { (listOf str) ]; in - types.submodule { - options = with defaultNullOpts; { - - enable = lib.mkEnableOption '' - lazy-loading for ${originalName} - ''; - - backend = - mkEnumFirstDefault - [ - "lz.n" - ] - '' - The lazy-loading backend to use. + types.submodule ( + { config, ... }: + { + options = with defaultNullOpts; { + enable = lib.mkOption { + default = lib.any (x: x != null) (builtins.attrValues config.settings); + description = '' + lazy-loading for ${originalName} ''; + }; - # Spec loading: - enabled = mkStrLuaFnOr types.bool (lazyLoadDefaults.enabledInSpec or null) '' - When false, or if the function returns false, then ${originalName} will not be included in the spec. + settings = lib.mkOption { + description = ''''; + default = { }; + type = + with types; + submodule { + freeformType = attrsOf anything; + options = { + # Spec loading: + enabled = mkStrLuaFnOr types.bool null '' + When false, or if the function returns false, then ${originalName} will not be included in the spec. - Equivalence: lz.n => enabled; lazy.nvim => enabled - ''; + Equivalence: lz.n => enabled; lazy.nvim => enabled + ''; - priority = mkNullable types.number (lazyLoadDefaults.priority or null) '' - Only useful for start plugins (not lazy-loaded) to force loading certain plugins first. + priority = mkNullable types.number null '' + Only useful for start plugins (not lazy-loaded) to force loading certain plugins first. - Equivalence: lz.n => priority; lazy.nvim => priority - ''; + Equivalence: lz.n => priority; lazy.nvim => priority + ''; - # Spec setup - # Actions - beforeAll = mkLuaFn (lazyLoadDefaults.beforeAll or null) '' - Always executed before any plugins are loaded. + # Spec setup + # Actions + beforeAll = mkLuaFn null '' + Always executed before any plugins are loaded. - Equivalence: lz.n => beforeAll; lazy.nvim => init - ''; + Equivalence: lz.n => beforeAll; lazy.nvim => init + ''; - before = mkLuaFn (lazyLoadDefaults.before or null) '' - Executed before ${originalName} is loaded. + before = mkLuaFn null '' + Executed before ${originalName} is loaded. - Equivalence: lz.n => before; lazy.nvim => None - ''; + Equivalence: lz.n => before; lazy.nvim => None + ''; - after = mkLuaFn (lazyLoadDefaults.after or null) '' - Executed after ${originalName} is loaded. + after = mkLuaFn null '' + Executed after ${originalName} is loaded. - Equivalence: lz.n => after; lazy.nvim => config - ''; + Equivalence: lz.n => after; lazy.nvim => config + ''; - # Triggers - event = mkNullable triggerType (lazyLoadDefaults.event or null) '' - Lazy-load on event. Events can be specified as `BufEnter` or with a pattern like `BufEnter *.lua` + # Triggers + event = mkNullable triggerType null '' + Lazy-load on event. Events can be specified as `BufEnter` or with a pattern like `BufEnter *.lua` - Equivalence: lz.n => event; lazy.nvim => event - ''; + Equivalence: lz.n => event; lazy.nvim => event + ''; - cmd = mkNullable triggerType (lazyLoadDefaults.cmd or null) '' - Lazy-load on command. + cmd = mkNullable triggerType null '' + Lazy-load on command. - Equivalence: lz.n => cmd; lazy.nvim => cmd - ''; + Equivalence: lz.n => cmd; lazy.nvim => cmd + ''; - ft = mkNullable triggerType (lazyLoadDefaults.ft or null) '' - Lazy-load on filetype. - - Equivalence: lz.n => ft; lazy.nvim => ft - ''; + ft = mkNullable triggerType null '' + Lazy-load on filetype. - keys = mkListOf (types.attrsOf types.anything) (lazyLoadDefaults.keys or null) '' - Lazy-load on key mapping. + Equivalence: lz.n => ft; lazy.nvim => ft + ''; - Equivalence: lz.n => keys; lazy.nvim => keys - ''; + keys = mkListOf (types.attrsOf types.anything) null '' + Lazy-load on key mapping. - colorscheme = mkNullable triggerType (lazyLoadDefaults.colorscheme or null) '' - Lazy-load on colorscheme. + Equivalence: lz.n => keys; lazy.nvim => keys + ''; - Equivalence: lz.n => colorscheme; lazy.nvim => None - ''; + colorscheme = mkNullable triggerType null '' + Lazy-load on colorscheme. - extraSettings = mkSettingsOption { - description = '' - Extra settings to pass to the lazy loader backend. - ''; - example = { - dependencies = { - __unkeyed-1 = "nvim-lua/plenary.nvim"; - lazy = true; - }; + Equivalence: lz.n => colorscheme; lazy.nvim => None + ''; + }; + }; }; }; - }; - }; - default = lazyLoadDefaults; + } + ); }; } // removed diff --git a/tests/test-sources/plugins/lazy-load.nix b/tests/test-sources/plugins/lazy-load.nix index 0044a5c701..98cfb7bd22 100644 --- a/tests/test-sources/plugins/lazy-load.nix +++ b/tests/test-sources/plugins/lazy-load.nix @@ -1,6 +1,6 @@ { - lazy-load-neovim-plugin = - { config, ... }: + lazy-load-neovim-plugin-configured = + { config, lib, ... }: { plugins = { lz-n = { @@ -11,13 +11,15 @@ enable = true; lazyLoad = { enable = true; - keys = [ - { - __unkeyed-1 = "nt"; - __unkeyed-3 = "Neotest summary"; - desc = "Summary toggle"; - } - ]; + settings = { + keys = [ + { + __unkeyed-1 = "nt"; + __unkeyed-3 = "Neotest summary"; + desc = "Summary toggle"; + } + ]; + }; }; }; }; @@ -30,22 +32,31 @@ { assertion = let - plugin = builtins.head config.plugins.lz-n.plugins; - keys = if builtins.isList plugin.keys then plugin.keys else [ ]; + plugins = config.plugins.lz-n.plugins or [ ]; + plugin = if builtins.length plugins > 0 then builtins.head plugins else null; + keys = if plugin != null && builtins.isList plugin.keys then plugin.keys else [ ]; in (builtins.length keys) == 1; message = "`lz-n.plugins[0].keys` should have contained a configuration."; } + { + assertion = + let + plugins = config.plugins.lz-n.plugins or [ ]; + plugin = if builtins.length plugins > 0 then builtins.head plugins else null; + in + plugin != null && lib.hasInfix config.plugins.neotest.luaConfig.content plugin.after.__raw; + message = "`lz-n.plugins[0].after` should have contained `neotest` lua content."; + } ]; }; - lazy-load-lz-n = - { config, ... }: + lazy-load-lz-n-configured = + { config, lib, ... }: { plugins = { codesnap = { enable = true; - lazyLoad.enable = true; }; lz-n = { enable = true; @@ -109,7 +120,7 @@ let plugin = builtins.head config.plugins.lz-n.plugins; in - "`lz-n.plugins[0].keys` should have contained 4 key configurations, but contained ${builtins.toJSON (plugin.keys)}"; + "`lz-n.plugins[0].keys` should have contained 4 key configurations, but contained ${builtins.toJSON plugin.keys}"; } { assertion = @@ -122,7 +133,171 @@ let plugin = builtins.head config.plugins.lz-n.plugins; in - "`lz-n.plugins[0].cmd` should have contained 4 cmd configurations, but contained ${builtins.toJSON (plugin.cmd)}"; + "`lz-n.plugins[0].cmd` should have contained 4 cmd configurations, but contained ${builtins.toJSON plugin.cmd}"; + } + { + assertion = + let + plugin = builtins.head config.plugins.lz-n.plugins; + in + lib.hasInfix config.plugins.codesnap.luaConfig.content plugin.after.__raw; + message = "`lz-n.plugins[0].after` should have contained `codesnap` lua content."; + } + ]; + }; + + dont-lazy-load-colorscheme-automatically = + { config, ... }: + { + colorschemes.catppuccin.enable = true; + plugins = { + lz-n = { + enable = true; + }; + }; + + assertions = [ + { + assertion = (builtins.length config.plugins.lz-n.plugins) == 0; + message = "`lz-n.plugins` should have contained no plugin configuration, but contained ${builtins.toJSON config.plugins.lz-n.plugins}"; + } + ]; + }; + + dont-lazy-load-unconfigured = + { config, ... }: + { + plugins = { + neotest = { + enable = true; + # Empty attrset shouldn't trigger lazy loading + lazyLoad = { }; + }; + lz-n = { + enable = true; + }; + }; + + assertions = [ + { + assertion = (builtins.length config.plugins.lz-n.plugins) == 0; + message = "`lz-n.plugins` should have contained no plugin configuration, but contained ${builtins.toJSON config.plugins.lz-n.plugins}"; + } + ]; + }; + + lazy-load-colorscheme-properly = + { config, lib, ... }: + { + colorschemes.catppuccin = { + enable = true; + lazyLoad.enable = true; + }; + + plugins = { + lz-n = { + enable = true; + }; + }; + + assertions = [ + { + assertion = (builtins.length config.plugins.lz-n.plugins) == 1; + message = "`lz-n.plugins` should have contained no plugin configuration, but contained ${builtins.toJSON config.plugins.lz-n.plugins}"; + } + { + assertion = + let + plugin = builtins.head config.plugins.lz-n.plugins; + in + plugin.colorscheme == "catppuccin"; + message = + let + plugin = builtins.head config.plugins.lz-n.plugins; + in + "`lz-n.plugins[0].colorscheme` should have been `catppuccin`, but contained ${builtins.toJSON plugin.colorscheme}"; + } + { + assertion = + let + plugin = builtins.head config.plugins.lz-n.plugins; + in + lib.hasInfix config.colorschemes.catppuccin.luaConfig.content plugin.after.__raw; + message = "`lz-n.plugins[0].after` should have contained `catppuccin` lua content."; + } + ]; + }; + + lazy-load-enabled-automatically = + { config, ... }: + { + plugins = { + lz-n = { + enable = true; + }; + neotest = { + enable = true; + lazyLoad = { + # Not setting lazyLoad.enable with configuration should enable + settings = { + keys = [ + { + __unkeyed-1 = "nt"; + __unkeyed-3 = "Neotest summary"; + desc = "Summary toggle"; + } + ]; + }; + }; + }; + }; + + assertions = [ + { + assertion = (builtins.length config.plugins.lz-n.plugins) == 1; + message = "`lz-n.plugins` should have contained a single plugin configuration, but contained ${builtins.toJSON config.plugins.lz-n.plugins}"; + } + { + assertion = + let + plugins = config.plugins.lz-n.plugins or [ ]; + plugin = if builtins.length plugins > 0 then builtins.head plugins else null; + keys = if plugin != null && builtins.isList plugin.keys then plugin.keys else [ ]; + in + (builtins.length keys) == 1; + message = "`lz-n.plugins[0].keys` should have contained a configuration."; + } + ]; + }; + + wrap-functionless-luaConfig = + { config, ... }: + { + plugins = { + lz-n = { + enable = true; + }; + web-devicons.enable = false; + telescope = { + enable = true; + lazyLoad = { + enable = true; + }; + }; + }; + + assertions = [ + { + assertion = (builtins.length config.plugins.lz-n.plugins) == 1; + message = "`lz-n.plugins` should have contained a single plugin configuration, but contained ${builtins.toJSON config.plugins.lz-n.plugins}"; + } + { + assertion = + let + plugin = builtins.head config.plugins.lz-n.plugins; + in + plugin.after.__raw == "function()\n " + config.plugins.telescope.luaConfig.content + " \nend"; + message = "`lz-n.plugins[0].after` should have contained a function wrapped `telescope` lua content."; } ]; }; From 277b2658a9e7ab82f948be8f7b73aee1d9f0a4c0 Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Thu, 5 Dec 2024 09:44:03 -0600 Subject: [PATCH 06/11] plugins/typescript-tools: todo about lazy loading --- plugins/by-name/typescript-tools/default.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/by-name/typescript-tools/default.nix b/plugins/by-name/typescript-tools/default.nix index ec1d861ba3..1c905603fe 100644 --- a/plugins/by-name/typescript-tools/default.nix +++ b/plugins/by-name/typescript-tools/default.nix @@ -221,6 +221,7 @@ lib.nixvim.neovim-plugin.mkNeovimPlugin { ]; in { + # TODO: handle lazy loading properly plugins.lsp.postConfig = let # TODO:: introduced 10-22-2024: remove after 24.11 From d24dd313cfb5212aaec9e8cb15c273d869bf6e4b Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Thu, 5 Dec 2024 19:09:59 -0600 Subject: [PATCH 07/11] tests/lazyloading: lazy-load -> lz-n We will support more, might as well properly organize them. --- .../test-sources/plugins/{lazy-load.nix => lazyloading/lz-n.nix} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/test-sources/plugins/{lazy-load.nix => lazyloading/lz-n.nix} (100%) diff --git a/tests/test-sources/plugins/lazy-load.nix b/tests/test-sources/plugins/lazyloading/lz-n.nix similarity index 100% rename from tests/test-sources/plugins/lazy-load.nix rename to tests/test-sources/plugins/lazyloading/lz-n.nix From 0997b371c784e9f623c8666ec006e8970ed76166 Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Thu, 5 Dec 2024 21:58:33 -0600 Subject: [PATCH 08/11] lib/neovim-plugin: freeform lazy settings Instead of trying to manage upstream configuration options, just keep using our freeform options so we can do less finicky logic and workarounds. --- lib/neovim-plugin.nix | 20 +-- lib/options.nix | 135 +++++------------- .../test-sources/plugins/lazyloading/lz-n.nix | 68 +++++++-- 3 files changed, 104 insertions(+), 119 deletions(-) diff --git a/lib/neovim-plugin.nix b/lib/neovim-plugin.nix index 1f1b05d28f..e15856d4dc 100644 --- a/lib/neovim-plugin.nix +++ b/lib/neovim-plugin.nix @@ -178,20 +178,14 @@ ( { __unkeyed-1 = originalName; - # Use provided after, otherwise fallback to normal lua content + # Use provided after, otherwise fallback to normal function wrapped lua content after = - if cfg.lazyLoad.settings.after != null then - cfg.lazyLoad.settings.after - else - # We need to wrap it in a function so it doesn't execute immediately - "function()\n " + cfg.luaConfig.content + " \nend"; - colorscheme = - if cfg.lazyLoad.settings.colorscheme != null then - cfg.lazyLoad.settings.colorscheme - else if (isColorscheme && colorscheme != null) then - colorscheme - else - null; + let + after = cfg.lazyLoad.settings.after or null; + default = "function()\n " + cfg.luaConfig.content + " \nend"; + in + if (lib.isString after || lib.types.rawLua.check after) then after else default; + colorscheme = lib.mkIf isColorscheme (cfg.lazyLoad.settings.colorscheme or colorscheme); } // lib.removeAttrs cfg.lazyLoad.settings [ "after" diff --git a/lib/options.nix b/lib/options.nix index 050ad1abc0..a004087486 100644 --- a/lib/options.nix +++ b/lib/options.nix @@ -339,108 +339,47 @@ rec { lib.mkOption { description = '' Lazy-load settings for ${originalName}. - ''; - default = { - enable = false; - }; - type = - let - triggerType = - with types; - oneOf [ - rawLua - str - (listOf str) - ]; - in - types.submodule ( - { config, ... }: - { - options = with defaultNullOpts; { - enable = lib.mkOption { - default = lib.any (x: x != null) (builtins.attrValues config.settings); - description = '' - lazy-loading for ${originalName} - ''; - }; - - settings = lib.mkOption { - description = ''''; - default = { }; - type = - with types; - submodule { - freeformType = attrsOf anything; - options = { - # Spec loading: - enabled = mkStrLuaFnOr types.bool null '' - When false, or if the function returns false, then ${originalName} will not be included in the spec. - - Equivalence: lz.n => enabled; lazy.nvim => enabled - ''; - - priority = mkNullable types.number null '' - Only useful for start plugins (not lazy-loaded) to force loading certain plugins first. - - Equivalence: lz.n => priority; lazy.nvim => priority - ''; - - # Spec setup - # Actions - beforeAll = mkLuaFn null '' - Always executed before any plugins are loaded. - - Equivalence: lz.n => beforeAll; lazy.nvim => init - ''; - - before = mkLuaFn null '' - Executed before ${originalName} is loaded. - - Equivalence: lz.n => before; lazy.nvim => None - ''; - - after = mkLuaFn null '' - Executed after ${originalName} is loaded. - Equivalence: lz.n => after; lazy.nvim => config - ''; - - # Triggers - event = mkNullable triggerType null '' - Lazy-load on event. Events can be specified as `BufEnter` or with a pattern like `BufEnter *.lua` - - Equivalence: lz.n => event; lazy.nvim => event - ''; - - cmd = mkNullable triggerType null '' - Lazy-load on command. - - Equivalence: lz.n => cmd; lazy.nvim => cmd - ''; - - ft = mkNullable triggerType null '' - Lazy-load on filetype. - - Equivalence: lz.n => ft; lazy.nvim => ft - ''; - - keys = mkListOf (types.attrsOf types.anything) null '' - Lazy-load on key mapping. - - Equivalence: lz.n => keys; lazy.nvim => keys - ''; - - colorscheme = mkNullable triggerType null '' - Lazy-load on colorscheme. + > [!WARNING] + > This is an experimental option and may not work as expected with all plugins. + > The API may change without notice. + > Please report any issues you encounter. + ''; + default = { }; + type = types.submodule ( + { config, ... }: + { + options = { + enable = lib.mkOption { + default = lib.any (x: x != null) (builtins.attrValues config.settings); + defaultText = lib.literalMD '' + `true` when `settings` has a non-null attribute + ''; + description = '' + lazy-loading for ${originalName} + ''; + }; - Equivalence: lz.n => colorscheme; lazy.nvim => None - ''; - }; - }; + settings = lib.nixvim.mkSettingsOption { + description = '' + Lazy provider configuration settings. + + Check your lazy loading provider's documentation on settings to configure. + ''; + example = { + cmd = "Neotest"; + keys = [ + { + __unkeyed-1 = "nt"; + __unkeyed-3 = "Neotest summary"; + desc = "Summary toggle"; + } + ]; }; }; - } - ); + }; + } + ); }; } // removed diff --git a/tests/test-sources/plugins/lazyloading/lz-n.nix b/tests/test-sources/plugins/lazyloading/lz-n.nix index 98cfb7bd22..4c714fca15 100644 --- a/tests/test-sources/plugins/lazyloading/lz-n.nix +++ b/tests/test-sources/plugins/lazyloading/lz-n.nix @@ -32,8 +32,8 @@ { assertion = let - plugins = config.plugins.lz-n.plugins or [ ]; - plugin = if builtins.length plugins > 0 then builtins.head plugins else null; + inherit (config.plugins.lz-n) plugins; + plugin = if plugins == [ ] then null else builtins.head plugins; keys = if plugin != null && builtins.isList plugin.keys then plugin.keys else [ ]; in (builtins.length keys) == 1; @@ -42,8 +42,8 @@ { assertion = let - plugins = config.plugins.lz-n.plugins or [ ]; - plugin = if builtins.length plugins > 0 then builtins.head plugins else null; + inherit (config.plugins.lz-n) plugins; + plugin = if plugins == [ ] then null else builtins.head plugins; in plugin != null && lib.hasInfix config.plugins.neotest.luaConfig.content plugin.after.__raw; message = "`lz-n.plugins[0].after` should have contained `neotest` lua content."; @@ -126,9 +126,10 @@ assertion = let plugin = builtins.head config.plugins.lz-n.plugins; - cmd = if builtins.isList plugin.cmd then plugin.cmd else [ ]; + cmd = plugin.cmd or null; + cmd' = lib.optionals (builtins.isList cmd) cmd; in - (builtins.length cmd) == 4; + (builtins.length cmd') == 4; message = let plugin = builtins.head config.plugins.lz-n.plugins; @@ -260,8 +261,8 @@ { assertion = let - plugins = config.plugins.lz-n.plugins or [ ]; - plugin = if builtins.length plugins > 0 then builtins.head plugins else null; + inherit (config.plugins.lz-n) plugins; + plugin = if plugins == [ ] then null else builtins.head plugins; keys = if plugin != null && builtins.isList plugin.keys then plugin.keys else [ ]; in (builtins.length keys) == 1; @@ -282,6 +283,9 @@ enable = true; lazyLoad = { enable = true; + settings = { + cmd = [ "Telescope" ]; + }; }; }; }; @@ -301,4 +305,52 @@ } ]; }; + + use-provided-raw-after = + { config, ... }: + { + plugins = { + lz-n = { + enable = true; + }; + web-devicons.enable = false; + telescope = { + enable = true; + lazyLoad = { + enable = true; + settings = { + after.__raw = '' + function() + -- test string + ${config.plugins.telescope.luaConfig.content} + end + ''; + cmd = [ "Telescope" ]; + }; + }; + }; + }; + + assertions = + let + plugin = getFirstLznPlugin config; + in + [ + { + assertion = (builtins.length config.plugins.lz-n.plugins) == 1; + message = "`lz-n.plugins` should have contained a single plugin configuration, but contained ${builtins.toJSON config.plugins.lz-n.plugins}"; + } + { + assertion = + plugin.after.__raw == '' + function() + -- test string + ${config.plugins.telescope.luaConfig.content} + end + ''; + message = "`lz-n.plugins[0].after` should have contained a function wrapped `telescope` lua content."; + } + ]; + }; + } From 76b567b43c9d1587f25884d745d08f5034b2c541 Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Sat, 7 Dec 2024 16:45:18 -0600 Subject: [PATCH 09/11] modules/lazyload: warn enabling a lazy loading provider --- modules/lazyload.nix | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/modules/lazyload.nix b/modules/lazyload.nix index 17bb325f9a..832d425796 100644 --- a/modules/lazyload.nix +++ b/modules/lazyload.nix @@ -26,5 +26,33 @@ in ''; } ]; + warnings = + let + ignoredPackages = [ + # removed + "treesitter-playground" + # renamed + "surround" + "null-ls" + "wilder-nvim" + ]; + + pluginsWithLazyLoad = builtins.filter ( + x: + !(lib.elem x ignoredPackages) + && lib.hasAttr "lazyLoad" config.plugins.${x} + && config.plugins.${x}.lazyLoad.enable + ) (builtins.attrNames config.plugins); + count = builtins.length pluginsWithLazyLoad; + in + lib.optionals (count > 0 && !config.plugins.lz-n.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 + '' + ]; }; } From 26f1daa47e0ca89ebea09efe1d6db99fada04caf Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Sun, 8 Dec 2024 14:03:16 -0600 Subject: [PATCH 10/11] tests/lazyloading/lz-n: reduce repetition --- .../test-sources/plugins/lazyloading/lz-n.nix | 225 ++++++++---------- 1 file changed, 103 insertions(+), 122 deletions(-) diff --git a/tests/test-sources/plugins/lazyloading/lz-n.nix b/tests/test-sources/plugins/lazyloading/lz-n.nix index 4c714fca15..53b2831835 100644 --- a/tests/test-sources/plugins/lazyloading/lz-n.nix +++ b/tests/test-sources/plugins/lazyloading/lz-n.nix @@ -1,3 +1,13 @@ +let + getFirstLznPlugin = + config: + let + inherit (config.plugins.lz-n) plugins; + in + if plugins == [ ] then null else builtins.head plugins; + + getPluginKeys = plugin: if plugin != null && builtins.isList plugin.keys then plugin.keys else [ ]; +in { lazy-load-neovim-plugin-configured = { config, lib, ... }: @@ -24,31 +34,26 @@ }; }; - assertions = [ - { - assertion = (builtins.length config.plugins.lz-n.plugins) == 1; - message = "`lz-n.plugins` should have contained a single plugin configuration, but contained ${builtins.toJSON config.plugins.lz-n.plugins}"; - } - { - assertion = - let - inherit (config.plugins.lz-n) plugins; - plugin = if plugins == [ ] then null else builtins.head plugins; - keys = if plugin != null && builtins.isList plugin.keys then plugin.keys else [ ]; - in - (builtins.length keys) == 1; - message = "`lz-n.plugins[0].keys` should have contained a configuration."; - } - { - assertion = - let - inherit (config.plugins.lz-n) plugins; - plugin = if plugins == [ ] then null else builtins.head plugins; - in - plugin != null && lib.hasInfix config.plugins.neotest.luaConfig.content plugin.after.__raw; - message = "`lz-n.plugins[0].after` should have contained `neotest` lua content."; - } - ]; + assertions = + let + plugin = getFirstLznPlugin config; + keys = getPluginKeys plugin; + in + [ + { + assertion = (builtins.length config.plugins.lz-n.plugins) == 1; + message = "`lz-n.plugins` should have contained a single plugin configuration, but contained ${builtins.toJSON config.plugins.lz-n.plugins}"; + } + { + assertion = (builtins.length keys) == 1; + message = "`lz-n.plugins[0].keys` should have contained a configuration."; + } + { + assertion = + plugin != null && lib.hasInfix config.plugins.neotest.luaConfig.content plugin.after.__raw; + message = "`lz-n.plugins[0].after` should have contained `neotest` lua content."; + } + ]; }; lazy-load-lz-n-configured = @@ -104,47 +109,31 @@ ]; }; }; - assertions = [ - { - assertion = (builtins.length config.plugins.lz-n.plugins) == 1; - message = "`lz-n.plugins` should have contained a single plugin configuration, but contained ${builtins.toJSON config.plugins.lz-n.plugins}"; - } - { - assertion = - let - plugin = builtins.head config.plugins.lz-n.plugins; - keys = if builtins.isList plugin.keys then plugin.keys else [ ]; - in - (builtins.length keys) == 4; - message = - let - plugin = builtins.head config.plugins.lz-n.plugins; - in - "`lz-n.plugins[0].keys` should have contained 4 key configurations, but contained ${builtins.toJSON plugin.keys}"; - } - { - assertion = - let - plugin = builtins.head config.plugins.lz-n.plugins; - cmd = plugin.cmd or null; - cmd' = lib.optionals (builtins.isList cmd) cmd; - in - (builtins.length cmd') == 4; - message = - let - plugin = builtins.head config.plugins.lz-n.plugins; - in - "`lz-n.plugins[0].cmd` should have contained 4 cmd configurations, but contained ${builtins.toJSON plugin.cmd}"; - } - { - assertion = - let - plugin = builtins.head config.plugins.lz-n.plugins; - in - lib.hasInfix config.plugins.codesnap.luaConfig.content plugin.after.__raw; - message = "`lz-n.plugins[0].after` should have contained `codesnap` lua content."; - } - ]; + assertions = + let + plugin = getFirstLznPlugin config; + keys = getPluginKeys plugin; + cmd = plugin.cmd or null; + cmd' = lib.optionals (builtins.isList cmd) cmd; + in + [ + { + assertion = (builtins.length config.plugins.lz-n.plugins) == 1; + message = "`lz-n.plugins` should have contained a single plugin configuration, but contained ${builtins.toJSON config.plugins.lz-n.plugins}"; + } + { + assertion = (builtins.length keys) == 4; + message = "`lz-n.plugins[0].keys` should have contained 4 key configurations, but contained ${builtins.toJSON plugin.keys}"; + } + { + assertion = (builtins.length cmd') == 4; + message = "`lz-n.plugins[0].cmd` should have contained 4 cmd configurations, but contained ${builtins.toJSON plugin.cmd}"; + } + { + assertion = lib.hasInfix config.plugins.codesnap.luaConfig.content plugin.after.__raw; + message = "`lz-n.plugins[0].after` should have contained `codesnap` lua content."; + } + ]; }; dont-lazy-load-colorscheme-automatically = @@ -201,32 +190,24 @@ }; }; - assertions = [ - { - assertion = (builtins.length config.plugins.lz-n.plugins) == 1; - message = "`lz-n.plugins` should have contained no plugin configuration, but contained ${builtins.toJSON config.plugins.lz-n.plugins}"; - } - { - assertion = - let - plugin = builtins.head config.plugins.lz-n.plugins; - in - plugin.colorscheme == "catppuccin"; - message = - let - plugin = builtins.head config.plugins.lz-n.plugins; - in - "`lz-n.plugins[0].colorscheme` should have been `catppuccin`, but contained ${builtins.toJSON plugin.colorscheme}"; - } - { - assertion = - let - plugin = builtins.head config.plugins.lz-n.plugins; - in - lib.hasInfix config.colorschemes.catppuccin.luaConfig.content plugin.after.__raw; - message = "`lz-n.plugins[0].after` should have contained `catppuccin` lua content."; - } - ]; + assertions = + let + plugin = getFirstLznPlugin config; + in + [ + { + assertion = (builtins.length config.plugins.lz-n.plugins) == 1; + message = "`lz-n.plugins` should have contained no plugin configuration, but contained ${builtins.toJSON config.plugins.lz-n.plugins}"; + } + { + assertion = plugin.colorscheme == "catppuccin"; + message = "`lz-n.plugins[0].colorscheme` should have been `catppuccin`, but contained ${builtins.toJSON plugin.colorscheme}"; + } + { + assertion = lib.hasInfix config.colorschemes.catppuccin.luaConfig.content plugin.after.__raw; + message = "`lz-n.plugins[0].after` should have contained `catppuccin` lua content."; + } + ]; }; lazy-load-enabled-automatically = @@ -253,22 +234,21 @@ }; }; - assertions = [ - { - assertion = (builtins.length config.plugins.lz-n.plugins) == 1; - message = "`lz-n.plugins` should have contained a single plugin configuration, but contained ${builtins.toJSON config.plugins.lz-n.plugins}"; - } - { - assertion = - let - inherit (config.plugins.lz-n) plugins; - plugin = if plugins == [ ] then null else builtins.head plugins; - keys = if plugin != null && builtins.isList plugin.keys then plugin.keys else [ ]; - in - (builtins.length keys) == 1; - message = "`lz-n.plugins[0].keys` should have contained a configuration."; - } - ]; + assertions = + let + plugin = getFirstLznPlugin config; + keys = getPluginKeys plugin; + in + [ + { + assertion = (builtins.length config.plugins.lz-n.plugins) == 1; + message = "`lz-n.plugins` should have contained a single plugin configuration, but contained ${builtins.toJSON config.plugins.lz-n.plugins}"; + } + { + assertion = (builtins.length keys) == 1; + message = "`lz-n.plugins[0].keys` should have contained a configuration."; + } + ]; }; wrap-functionless-luaConfig = @@ -290,20 +270,21 @@ }; }; - assertions = [ - { - assertion = (builtins.length config.plugins.lz-n.plugins) == 1; - message = "`lz-n.plugins` should have contained a single plugin configuration, but contained ${builtins.toJSON config.plugins.lz-n.plugins}"; - } - { - assertion = - let - plugin = builtins.head config.plugins.lz-n.plugins; - in - plugin.after.__raw == "function()\n " + config.plugins.telescope.luaConfig.content + " \nend"; - message = "`lz-n.plugins[0].after` should have contained a function wrapped `telescope` lua content."; - } - ]; + assertions = + let + plugin = getFirstLznPlugin config; + in + [ + { + assertion = (builtins.length config.plugins.lz-n.plugins) == 1; + message = "`lz-n.plugins` should have contained a single plugin configuration, but contained ${builtins.toJSON config.plugins.lz-n.plugins}"; + } + { + assertion = + plugin.after.__raw == "function()\n " + config.plugins.telescope.luaConfig.content + " \nend"; + message = "`lz-n.plugins[0].after` should have contained a function wrapped `telescope` lua content."; + } + ]; }; use-provided-raw-after = From b752606681ded3f69e99ed568c7075b3578dce48 Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Tue, 10 Dec 2024 10:07:13 -0600 Subject: [PATCH 11/11] tests/lazyloading/lz-n: runNvim false We don't need to run nvim and see what happens, these are just used for making sure we're generating the config appropriately. --- tests/test-sources/plugins/lazyloading/lz-n.nix | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/test-sources/plugins/lazyloading/lz-n.nix b/tests/test-sources/plugins/lazyloading/lz-n.nix index 53b2831835..f5a50a9154 100644 --- a/tests/test-sources/plugins/lazyloading/lz-n.nix +++ b/tests/test-sources/plugins/lazyloading/lz-n.nix @@ -12,6 +12,7 @@ in lazy-load-neovim-plugin-configured = { config, lib, ... }: { + test.runNvim = false; plugins = { lz-n = { enable = true; @@ -59,6 +60,7 @@ in lazy-load-lz-n-configured = { config, lib, ... }: { + test.runNvim = false; plugins = { codesnap = { enable = true; @@ -139,6 +141,7 @@ in dont-lazy-load-colorscheme-automatically = { config, ... }: { + test.runNvim = false; colorschemes.catppuccin.enable = true; plugins = { lz-n = { @@ -157,6 +160,7 @@ in dont-lazy-load-unconfigured = { config, ... }: { + test.runNvim = false; plugins = { neotest = { enable = true; @@ -179,6 +183,7 @@ in lazy-load-colorscheme-properly = { config, lib, ... }: { + test.runNvim = false; colorschemes.catppuccin = { enable = true; lazyLoad.enable = true; @@ -213,6 +218,7 @@ in lazy-load-enabled-automatically = { config, ... }: { + test.runNvim = false; plugins = { lz-n = { enable = true; @@ -254,6 +260,7 @@ in wrap-functionless-luaConfig = { config, ... }: { + test.runNvim = false; plugins = { lz-n = { enable = true; @@ -290,6 +297,7 @@ in use-provided-raw-after = { config, ... }: { + test.runNvim = false; plugins = { lz-n = { enable = true;