Skip to content

Commit

Permalink
lazy: move lz.n submodules out of lib
Browse files Browse the repository at this point in the history
  • Loading branch information
horriblename committed Aug 24, 2024
1 parent 590590b commit 5887fa8
Show file tree
Hide file tree
Showing 2 changed files with 189 additions and 189 deletions.
195 changes: 8 additions & 187 deletions lib/types/plugins.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
inherit (lib.options) mkOption;
inherit (lib.attrsets) attrNames mapAttrs' filterAttrs nameValuePair;
inherit (lib.strings) hasPrefix removePrefix;
inherit (lib.types) submodule either package enum str lines attrsOf anything listOf nullOr oneOf bool int;
inherit (lib.types) submodule either package enum str lines attrsOf anything listOf nullOr;

# Get the names of all flake inputs that start with the given prefix.
fromInputs = {
inputs,
Expand Down Expand Up @@ -50,193 +51,8 @@
};
};
};

luaInline = lib.mkOptionType {
name = "luaInline";
check = x: lib.nvim.lua.isLuaInline x;
};

lznKeysSpec = submodule {
options = {
desc = mkOption {
description = "Description of the key map";
type = nullOr str;
default = null;
};

noremap = mkOption {
description = "TBD";
type = bool;
default = false;
};

expr = mkOption {
description = "TBD";
type = bool;
default = false;
};

nowait = mkOption {
description = "TBD";
type = bool;
default = false;
};

ft = mkOption {
description = "TBD";
type = nullOr (listOf str);
default = null;
};

key = mkOption {
type = str;
description = "Key to bind to";
};

action = mkOption {
type = nullOr str;
default = null;
description = "Action to trigger.";
};

lua = mkOption {
type = bool;
default = false;
description = "If true the action is treated as a lua function instead of a vim command.";
};

mode = mkOption {
description = "Modes to bind in";
type = listOf str;
default = ["n" "x" "s" "o"];
};
};
};

lznPluginTableType = attrsOf lznPluginType;
lznPluginType = submodule {
options = {
## Should probably infer from the actual plugin somehow
## In general this is the name passed to packadd, so the dir name of the plugin
# name = mkOption {
# type= str;
# }

# Non-lz.n options

package = mkOption {
type = pluginType;
description = "Plugin package";
};

setupModule = mkOption {
type = nullOr str;
description = "Lua module to run setup function on.";
default = null;
};

setupOpts = mkOption {
type = submodule {freeformType = attrsOf anything;};
description = "Options to pass to the setup function";
default = {};
};

# lz.n options

enabled = mkOption {
type = nullOr (either bool str);
description = "When false, or if the lua function returns false, this plugin will not be included in the spec";
default = null;
};

beforeAll = mkOption {
type = nullOr str;
description = "Lua code to run before any plugins are loaded. This will be wrapped in a function.";
default = null;
};

before = mkOption {
type = nullOr str;
description = "Lua code to run before plugin is loaded. This will be wrapped in a function.";
default = null;
};

after = mkOption {
type = nullOr str;
description = "Lua code to run after plugin is loaded. This will be wrapped in a function.";
default = null;
};

event = mkOption {
description = "Lazy-load on event";
default = null;
type = let
event = submodule {
options = {
event = mkOption {
type = nullOr (either str (listOf str));
description = "Exact event name";
example = "BufEnter";
};
pattern = mkOption {
type = nullOr (either str (listOf str));
description = "Event pattern";
example = "BufEnter *.lua";
};
};
};
in
nullOr (oneOf [str (listOf str) event]);
};

cmd = mkOption {
description = "Lazy-load on command";
default = null;
type = nullOr (either str (listOf str));
};

ft = mkOption {
description = "Lazy-load on filetype";
default = null;
type = nullOr (either str (listOf str));
};

keys = mkOption {
description = "Lazy-load on key mapping";
default = null;
type = nullOr (oneOf [str (listOf lznKeysSpec) (listOf str)]);
example = ''
keys = [
{lhs = "<leader>s"; rhs = ":NvimTreeToggle<cr>"; desc = "Toggle NvimTree"}
]
'';
};

colorscheme = mkOption {
description = "Lazy-load on colorscheme.";
type = nullOr (either str (listOf str));
default = null;
};

priority = mkOption {
type = nullOr int;
description = "Only useful for stat plugins (not lazy-loaded) to force loading certain plugins first.";
default = null;
};

load = mkOption {
type = nullOr str;
default = null;
description = ''
Lua code to override the `vim.g.lz_n.load()` function for a single plugin.
This will be wrapped in a function
'';
};
};
};
in {
inherit extraPluginType fromInputs pluginType luaInline lznPluginType lznPluginTableType;
inherit extraPluginType fromInputs pluginType;

pluginsOpt = {
description,
Expand All @@ -248,6 +64,11 @@ in {
type = pluginsType;
};

luaInline = lib.mkOptionType {
name = "luaInline";
check = x: lib.nvim.lua.isLuaInline x;
};

/*
opts is a attrset of options, example:
```
Expand Down
Loading

0 comments on commit 5887fa8

Please sign in to comment.