From efd52d4284226588f7f53f1715b1e4e15e52ea74 Mon Sep 17 00:00:00 2001 From: psfloyd Date: Fri, 26 Jul 2024 21:41:51 -0300 Subject: [PATCH] plugins/lz-n: make sub-options type anything --- plugins/pluginmanagers/lz-n.nix | 222 +++++++++++------- .../plugins/pluginmanagers/lz-n.nix | 22 +- 2 files changed, 146 insertions(+), 98 deletions(-) diff --git a/plugins/pluginmanagers/lz-n.nix b/plugins/pluginmanagers/lz-n.nix index cd30728a8e..492d144e30 100644 --- a/plugins/pluginmanagers/lz-n.nix +++ b/plugins/pluginmanagers/lz-n.nix @@ -7,55 +7,6 @@ ... }: with lib; -let - lzPluginType = - with helpers.nixvimTypes; - let - maybeRawStrOrList = oneOf [ - str - (listOf (maybeRaw str)) - rawLua - ]; - in - submodule { - freeformType = attrsOf anything; - options = { - __unkeyed = mkOption { - type = str; - description = '' - The "unkeyed" attribute is the plugin's name. - This is passed to `load` function and should normally match the repo name of the plugin. - - More specifically, this is the name of the folder in `/pack/opt/{name}` that is loaded with `load` (`packadd` by default). - See `:h packadd`. - ''; - }; - enabled = helpers.defaultNullOpts.mkStrLuaFnOr bool true '' - When false, or if the function returns false, then this plugin will not be included in the spec. - This option corresponds to the `enabled` property of lz.n. - ''; - beforeAll = helpers.mkNullOrLuaFn "Always executed before any plugins are loaded."; - before = helpers.mkNullOrLuaFn "Executed before this plugin is loaded."; - after = helpers.mkNullOrLuaFn "Executed after this plugin is loaded."; - event = helpers.mkNullOrOption maybeRawStrOrList "Lazy-load on event. Events can be specified as BufEnter or with a pattern like BufEnter *.lua"; - cmd = helpers.mkNullOrOption maybeRawStrOrList "Lazy-load on command."; - ft = helpers.mkNullOrOption maybeRawStrOrList "Lazy-load on filetype."; - colorscheme = helpers.mkNullOrOption maybeRawStrOrList "Lazy-load on colorscheme."; - keys = helpers.mkNullOrOption' { - type = maybeRawStrOrList; - description = "Lazy-load on key mapping. Mode is `n` by default."; - example = [ - "" - (helpers.mkRaw ''{ "ft", "Neotree toggle", desc = "NeoTree toggle" }'') - ]; - }; - priority = helpers.defaultNullOpts.mkUnsignedInt (lib.literalMD "`50` (or `1000` if `colorscheme` is set)") '' - Only useful for start plugins (not lazy-loaded) to force loading certain plugins first. - ''; - load = helpers.mkNullOrLuaFn "Can be used to override the `vim.g.lz_n.load()` function for this plugin."; - }; - }; -in helpers.neovim-plugin.mkNeovimPlugin config { name = "lz-n"; originalName = "lz.n"; @@ -76,50 +27,139 @@ helpers.neovim-plugin.mkNeovimPlugin config { callSetup = false; # Does not use setup - extraOptions = { - plugins = mkOption { - description = '' - List of plugin specs provided to the `require('lz.n').load` function. - Plugin specs can be ${helpers.nixvimTypes.rawLua.description}. - ''; - default = [ ]; - type = types.listOf lzPluginType; - example = [ - { - __unkeyed = "neo-tree.nvim"; - enabled = '' - function() - return true - end - ''; - keys = helpers.mkRaw ''{ "ft", "Neotree toggle", desc = "NeoTree toggle" }''; - after = '' - function() - require("neo-tree").setup() - end - ''; - } - { - __unkeyed = "telescope.nvim"; - cmd = [ "Telescope" ]; - keys = [ - (helpers.mkRaw ''{ "fa", "Telescope autocommands", desc = "Telescope autocommands" }'') - (helpers.mkRaw ''{ "fb", "Telescope buffers", desc = "Telescope buffers" }'') - ]; - } - { - __unkeyed = "onedarker.nvim"; - colorscheme = [ "onedarker" ]; - } - (helpers.mkRaw '' + extraOptions = + let + lzPluginType = + with helpers.nixvimTypes; + submodule { + freeformType = attrsOf anything; + options = { + __unkeyed = mkOption { + type = str; + description = '' + The "unkeyed" attribute is the plugin's name. + This is passed to `load` function and should normally match the repo name of the plugin. + + More specifically, this is the name of the folder in `/pack/opt/{name}` that is loaded with `load` (`packadd` by default). + See `:h packadd`. + ''; + }; + enabled = helpers.defaultNullOpts.mkStrLuaFnOr bool true '' + When false, or if the function returns false, then this plugin will not be included in the spec. + This option corresponds to the `enabled` property of lz.n. + ''; + beforeAll = helpers.mkNullOrLuaFn "Always executed before any plugins are loaded."; + before = helpers.mkNullOrLuaFn "Executed before this plugin is loaded."; + after = helpers.mkNullOrLuaFn "Executed after this plugin is loaded."; + load = helpers.mkNullOrLuaFn "Can be used to override the `vim.g.lz_n.load()` function for this plugin."; + + priority = helpers.defaultNullOpts.mkUnsignedInt (lib.literalMD "`50` (or `1000` if `colorscheme` is set)") '' + Only useful for start plugins (not lazy-loaded) to force loading certain plugins first. + ''; + event = helpers.mkNullOrOption' { + type = anything; + description = "Lazy-load on event. Events can be specified as BufEnter or with a pattern like BufEnter *.lua"; + example = [ + "BufEnter *.lua" + "DeferredUIEnter" + ]; + }; + cmd = helpers.mkNullOrOption' { + type = anything; + description = "Lazy-load on command."; + example = [ + "Neotree" + "Telescope" + ]; + }; + ft = helpers.mkNullOrOption' { + type = anything; + description = "Lazy-load on filetype."; + example = [ "tex" ]; + }; + colorscheme = helpers.mkNullOrOption' { + type = anything; + description = "Lazy-load on colorscheme."; + example = "onedarker"; + }; + keys = helpers.mkNullOrOption' { + type = listOf anything; + description = "Lazy-load on key mapping. Mode is `n` by default."; + example = [ + "" + [ + "" + "g" + ] + { + __unkeyed-1 = "fb"; + __unkeyed-2 = "Telescope buffers"; + desc = "Telescope buffers"; + } + (helpers.mkRaw ''{ "ft", "Neotree toggle", desc = "NeoTree toggle" }'') + ]; + }; + }; + }; + in + { + plugins = mkOption { + description = '' + List of plugin specs provided to the `require('lz.n').load` function. + Plugin specs can be ${helpers.nixvimTypes.rawLua.description}. + ''; + default = [ ]; + type = types.listOf lzPluginType; + example = [ { - "crates.nvim", - ft = "toml", - }, - '') - ]; + __unkeyed = "neo-tree.nvim"; + enabled = '' + function() + return true + end + ''; + keys = [ + { + __unkeyed-1 = "ft"; + __unkeyed-2 = "Neotree toggle"; + desc = "NeoTree toggle"; + } + ]; + after = '' + function() + require("neo-tree").setup() + end + ''; + } + { + __unkeyed = "telescope.nvim"; + cmd = [ "Telescope" ]; + keys = [ + { + __unkeyed-1 = "fa"; + __unkeyed-2 = "Telescope autocommands"; + desc = "Telescope autocommands"; + } + { + __unkeyed-1 = "fb"; + __unkeyed-2 = "Telescope buffers"; + desc = "Telescope buffers"; + } + ]; + } + { + __unkeyed = "onedarker.nvim"; + colorscheme = [ "onedarker" ]; + } + (helpers.mkRaw '' + { + "crates.nvim", + ft = "toml", + }, + '') + ]; + }; }; - }; extraConfig = cfg: { globals.lz_n = modules.mkAliasAndWrapDefsWithPriority id options.plugins.lz-n.settings; diff --git a/tests/test-sources/plugins/pluginmanagers/lz-n.nix b/tests/test-sources/plugins/pluginmanagers/lz-n.nix index 7f07222775..ee1f0fe9a5 100644 --- a/tests/test-sources/plugins/pluginmanagers/lz-n.nix +++ b/tests/test-sources/plugins/pluginmanagers/lz-n.nix @@ -43,9 +43,13 @@ in return true end ''; - keys = helpers.mkRaw '' - {{"ft", "Neotree toggle", desc = "NeoTree toggle"}} - ''; + keys = [ + { + __unkeyed-1 = "ft"; + __unkeyed-2 = "Neotree toggle"; + desc = "NeoTree toggle"; + } + ]; after = # lua '' function() @@ -74,7 +78,7 @@ in plugins.lz-n = { enable = true; plugins = [ - # enabled, on keys as rawLua + # enabled, on keys { __unkeyed = "neo-tree.nvim"; enabled = '' @@ -82,9 +86,13 @@ in return true end ''; - keys = helpers.mkRaw '' - {{"ft", "Neotree toggle", desc = "NeoTree toggle"}} - ''; + keys = [ + { + __unkeyed-1 = "ft"; + __unkeyed-2 = "Neotree toggle"; + desc = "NeoTree toggle"; + } + ]; after = # lua '' function()