Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib/options: lib/neovim-plugin: Add lazyLoad option to plugins #1866

Closed
wants to merge 8 commits into from
Closed
Prev Previous commit
Next Next commit
lib/options: add mkLazyLoadOption
This function will be used to generate lazyLoad options for plugins.
It is defined in options for later use in mkNeovimPlugin.
psfloyd committed Jul 15, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 23a58d20e3108d8249923e3b1099868a9e5a2fca
61 changes: 61 additions & 0 deletions lib/options.nix
Original file line number Diff line number Diff line change
@@ -368,4 +368,65 @@ rec {
else
example;
};

mkLazyLoadOption =
{
originalName ? "this plugin",
cfg ? { },
lazyLoad ? { },
}:
let
lazyLoadPluginDefault = {
enable = false;
name = originalName;
enabledInSpec = true;
} // lazyLoad;
getPluginDefault = n: if (lazyLoadPluginDefault ? ${n}) then lazyLoadPluginDefault.${n} else null;
in
mkOption {
description = "Lazy-load settings for ${originalName}.";
type =
with nixvimTypes;
submodule {
options = with defaultNullOpts; {
enable = mkOption {
type = bool;
default = getPluginDefault "enable";
description = "Enable lazy-loading for ${originalName}";
};
name = mkOption {
type = str;
default = getPluginDefault "name";
description = "The plugin's name (not the module name). This is what is passed to the load(name) function.";
};
enabledInSpec = mkStrLuaFnOr bool (getPluginDefault "enabledInSpec") ''
When false, or if the function returns false, then ${originalName} will not be included in the spec.
This option corresponds to the `enabled` property of lz.n.
'';
beforeAll = mkLuaFn (getPluginDefault "beforeAll") "Always executed before any plugins are loaded.";
before = mkLuaFn (getPluginDefault "before") "Executed before ${originalName} is loaded.";
after = mkLuaFn (getPluginDefault "after") "Executed after ${originalName} is loaded.";
event =
mkNullable (listOf str) (getPluginDefault "event")
"Lazy-load on event. Events can be specified as BufEnter or with a pattern like BufEnter *.lua";
cmd = mkNullable (listOf str) (getPluginDefault "cmd") "Lazy-load on command.";
ft = mkNullable (listOf str) (getPluginDefault "ft") "Lazy-load on filetype.";
#TODO: use keymap-helper?
keys = mkNullable (listOf str) (getPluginDefault "keys") "Lazy-load on key mapping.";
colorscheme = mkNullable (listOf str) (getPluginDefault "colorscheme") "Lazy-load on colorscheme.";
priority = mkNullable number (getPluginDefault "priority") ''
Only useful for start plugins (not lazy-loaded) to force loading certain plugins first.
Default priority is 50 (or 1000 if colorscheme is set).
'';
load = mkLuaFn (getPluginDefault "load") "Can be used to override the vim.g.lz_n.load() function for ${originalName}.";
};
config = mkIf (cfg != { }) (
mapAttrs (
name: value: if (builtins.typeOf value == "list") then value else mkDefault value
) lazyLoadPluginDefault
);
};
default = lazyLoadPluginDefault;
};

}