Skip to content

Commit

Permalink
plugins/lz-n: make sub-options type anything
Browse files Browse the repository at this point in the history
  • Loading branch information
psfloyd committed Jul 27, 2024
1 parent 6ac95b4 commit efd52d4
Show file tree
Hide file tree
Showing 2 changed files with 146 additions and 98 deletions.
222 changes: 131 additions & 91 deletions plugins/pluginmanagers/lz-n.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
"<C-a>"
(helpers.mkRaw ''{ "<leader>ft", "<CMD>Neotree toggle<CR>", 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";
Expand All @@ -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 ''{ "<leader>ft", "<CMD>Neotree toggle<CR>", desc = "NeoTree toggle" }'';
after = ''
function()
require("neo-tree").setup()
end
'';
}
{
__unkeyed = "telescope.nvim";
cmd = [ "Telescope" ];
keys = [
(helpers.mkRaw ''{ "<leader>fa", "<CMD>Telescope autocommands<CR>", desc = "Telescope autocommands" }'')
(helpers.mkRaw ''{ "<leader>fb", "<CMD>Telescope buffers<CR>", 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 = [
"<C-a>"
[
"<C-x>"
"g<C-x>"
]
{
__unkeyed-1 = "<leader>fb";
__unkeyed-2 = "<CMD>Telescope buffers<CR>";
desc = "Telescope buffers";
}
(helpers.mkRaw ''{ "<leader>ft", "<CMD>Neotree toggle<CR>", 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 = "<leader>ft";
__unkeyed-2 = "<CMD>Neotree toggle<CR>";
desc = "NeoTree toggle";
}
];
after = ''
function()
require("neo-tree").setup()
end
'';
}
{
__unkeyed = "telescope.nvim";
cmd = [ "Telescope" ];
keys = [
{
__unkeyed-1 = "<leader>fa";
__unkeyed-2 = "<CMD>Telescope autocommands<CR>";
desc = "Telescope autocommands";
}
{
__unkeyed-1 = "<leader>fb";
__unkeyed-2 = "<CMD>Telescope buffers<CR>";
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;
Expand Down
22 changes: 15 additions & 7 deletions tests/test-sources/plugins/pluginmanagers/lz-n.nix
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,13 @@ in
return true
end
'';
keys = helpers.mkRaw ''
{{"<leader>ft", "<CMD>Neotree toggle<CR>", desc = "NeoTree toggle"}}
'';
keys = [
{
__unkeyed-1 = "<leader>ft";
__unkeyed-2 = "<CMD>Neotree toggle<CR>";
desc = "NeoTree toggle";
}
];
after = # lua
''
function()
Expand Down Expand Up @@ -74,17 +78,21 @@ in
plugins.lz-n = {
enable = true;
plugins = [
# enabled, on keys as rawLua
# enabled, on keys
{
__unkeyed = "neo-tree.nvim";
enabled = ''
function()
return true
end
'';
keys = helpers.mkRaw ''
{{"<leader>ft", "<CMD>Neotree toggle<CR>", desc = "NeoTree toggle"}}
'';
keys = [
{
__unkeyed-1 = "<leader>ft";
__unkeyed-2 = "<CMD>Neotree toggle<CR>";
desc = "NeoTree toggle";
}
];
after = # lua
''
function()
Expand Down

0 comments on commit efd52d4

Please sign in to comment.