lib/helpers: build recursively

This commit is contained in:
Matt Sturgeon 2024-07-28 22:30:11 +01:00
parent a655679ecc
commit 0e98d9cf1e
No known key found for this signature in database
GPG key ID: 4F91844CED1A8299
8 changed files with 68 additions and 96 deletions

View file

@ -1,8 +1,4 @@
{ { lib, helpers }:
lib,
nixvimOptions,
nixvimTypes,
}:
with lib; with lib;
rec { rec {
autoGroupOption = types.submodule { autoGroupOption = types.submodule {
@ -16,34 +12,34 @@ rec {
}; };
autoCmdOptions = { autoCmdOptions = {
event = nixvimOptions.mkNullOrOption (with types; either str (listOf str)) '' event = helpers.mkNullOrOption (with types; either str (listOf str)) ''
The event or events to register this autocommand. The event or events to register this autocommand.
''; '';
group = nixvimOptions.mkNullOrOption (with types; either str int) '' group = helpers.mkNullOrOption (with types; either str int) ''
The autocommand group name or id to match against. The autocommand group name or id to match against.
''; '';
pattern = nixvimOptions.mkNullOrOption (with types; either str (listOf str)) '' pattern = helpers.mkNullOrOption (with types; either str (listOf str)) ''
Pattern or patterns to match literally against. Pattern or patterns to match literally against.
''; '';
buffer = nixvimOptions.mkNullOrOption types.int '' buffer = helpers.mkNullOrOption types.int ''
Buffer number for buffer local autocommands |autocmd-buflocal|. Buffer number for buffer local autocommands |autocmd-buflocal|.
Cannot be used with `pattern`. Cannot be used with `pattern`.
''; '';
# Introduced early October 2023. # Introduced early October 2023.
# TODO remove in early December 2023. # TODO remove in early December 2023.
description = nixvimOptions.mkNullOrOption types.str '' description = helpers.mkNullOrOption types.str ''
DEPRECATED, please use `desc`. DEPRECATED, please use `desc`.
''; '';
desc = nixvimOptions.mkNullOrOption types.str '' desc = helpers.mkNullOrOption types.str ''
A textual description of this autocommand. A textual description of this autocommand.
''; '';
callback = nixvimOptions.mkNullOrOption (with types; either str nixvimTypes.rawLua) '' callback = helpers.mkNullOrOption (with types; either str helpers.nixvimTypes.rawLua) ''
A function or a string. A function or a string.
- if a string, the name of a Vimscript function to call when this autocommand is triggered. - if a string, the name of a Vimscript function to call when this autocommand is triggered.
- Otherwise, a Lua function which is called when this autocommand is triggered. - Otherwise, a Lua function which is called when this autocommand is triggered.
@ -67,13 +63,13 @@ rec {
} }
''; '';
command = nixvimOptions.defaultNullOpts.mkStr "" '' command = helpers.defaultNullOpts.mkStr "" ''
Vim command to execute on event. Cannot be used with `callback`. Vim command to execute on event. Cannot be used with `callback`.
''; '';
once = nixvimOptions.defaultNullOpts.mkBool false "Run the autocommand only once."; once = helpers.defaultNullOpts.mkBool false "Run the autocommand only once.";
nested = nixvimOptions.defaultNullOpts.mkBool false "Run nested autocommands."; nested = helpers.defaultNullOpts.mkBool false "Run nested autocommands.";
}; };
autoCmdOption = types.submodule { options = autoCmdOptions; }; autoCmdOption = types.submodule { options = autoCmdOptions; };

View file

@ -5,30 +5,21 @@
... ...
}: }:
let let
nixvimBuilders = import ./builders.nix { inherit lib pkgs; }; # Build helpers recursively
nixvimTypes = import ./types.nix { inherit lib nixvimOptions; }; helpers =
nixvimUtils = import ./utils.nix { inherit lib nixvimTypes _nixvimTests; }; {
nixvimOptions = import ./options.nix { inherit lib nixvimTypes nixvimUtils; }; autocmd = import ./autocmd-helpers.nix { inherit lib helpers; };
nixvimDeprecation = import ./deprecation.nix { inherit lib; }; keymaps = import ./keymap-helpers.nix { inherit lib helpers; };
in
rec {
maintainers = import ./maintainers.nix;
lua = import ./to-lua.nix { inherit lib; }; lua = import ./to-lua.nix { inherit lib; };
keymaps = import ./keymap-helpers.nix { inherit lib nixvimOptions nixvimTypes; }; toLuaObject = helpers.lua.toLua;
autocmd = import ./autocmd-helpers.nix { inherit lib nixvimOptions nixvimTypes; }; maintainers = import ./maintainers.nix;
neovim-plugin = import ./neovim-plugin.nix { neovim-plugin = import ./neovim-plugin.nix { inherit lib helpers; };
inherit nixvimTypes = import ./types.nix { inherit lib helpers; };
lib vim-plugin = import ./vim-plugin.nix { inherit lib helpers; };
nixvimOptions }
nixvimUtils // import ./builders.nix { inherit lib pkgs; }
toLuaObject // import ./deprecation.nix { inherit lib; }
; // import ./options.nix { inherit lib helpers; }
}; // import ./utils.nix { inherit lib helpers _nixvimTests; };
vim-plugin = import ./vim-plugin.nix { inherit lib nixvimOptions nixvimUtils; }; in
inherit nixvimTypes; helpers
toLuaObject = lua.toLua;
}
// nixvimUtils
// nixvimOptions
// nixvimBuilders
// nixvimDeprecation

View file

@ -1,29 +1,25 @@
{ { lib, helpers }:
lib,
nixvimOptions,
nixvimTypes,
}:
with lib; with lib;
rec { rec {
# These are the configuration options that change the behavior of each mapping. # These are the configuration options that change the behavior of each mapping.
mapConfigOptions = { mapConfigOptions = {
silent = nixvimOptions.defaultNullOpts.mkBool false "Whether this mapping should be silent. Equivalent to adding `<silent>` to a map."; silent = helpers.defaultNullOpts.mkBool false "Whether this mapping should be silent. Equivalent to adding `<silent>` to a map.";
nowait = nixvimOptions.defaultNullOpts.mkBool false "Whether to wait for extra input on ambiguous mappings. Equivalent to adding `<nowait>` to a map."; nowait = helpers.defaultNullOpts.mkBool false "Whether to wait for extra input on ambiguous mappings. Equivalent to adding `<nowait>` to a map.";
script = nixvimOptions.defaultNullOpts.mkBool false "Equivalent to adding `<script>` to a map."; script = helpers.defaultNullOpts.mkBool false "Equivalent to adding `<script>` to a map.";
expr = nixvimOptions.defaultNullOpts.mkBool false "Means that the action is actually an expression. Equivalent to adding `<expr>` to a map."; expr = helpers.defaultNullOpts.mkBool false "Means that the action is actually an expression. Equivalent to adding `<expr>` to a map.";
unique = nixvimOptions.defaultNullOpts.mkBool false "Whether to fail if the map is already defined. Equivalent to adding `<unique>` to a map."; unique = helpers.defaultNullOpts.mkBool false "Whether to fail if the map is already defined. Equivalent to adding `<unique>` to a map.";
noremap = nixvimOptions.defaultNullOpts.mkBool true "Whether to use the `noremap` variant of the command, ignoring any custom mappings on the defined action. It is highly advised to keep this on, which is the default."; noremap = helpers.defaultNullOpts.mkBool true "Whether to use the `noremap` variant of the command, ignoring any custom mappings on the defined action. It is highly advised to keep this on, which is the default.";
remap = nixvimOptions.defaultNullOpts.mkBool false "Make the mapping recursive. Inverses `noremap`."; remap = helpers.defaultNullOpts.mkBool false "Make the mapping recursive. Inverses `noremap`.";
desc = nixvimOptions.mkNullOrOption types.str "A textual description of this keybind, to be shown in which-key, if you have it."; desc = helpers.mkNullOrOption types.str "A textual description of this keybind, to be shown in which-key, if you have it.";
buffer = nixvimOptions.defaultNullOpts.mkBool false "Make the mapping buffer-local. Equivalent to adding `<buffer>` to a map."; buffer = helpers.defaultNullOpts.mkBool false "Make the mapping buffer-local. Equivalent to adding `<buffer>` to a map.";
}; };
modes = { modes = {
@ -107,7 +103,7 @@ rec {
// (optionalAttrs (isAttrs action || action) { // (optionalAttrs (isAttrs action || action) {
action = mkOption ( action = mkOption (
{ {
type = nixvimTypes.maybeRaw str; type = helpers.nixvimTypes.maybeRaw str;
description = "The action to execute."; description = "The action to execute.";
} }
// (optionalAttrs (isAttrs action) action) // (optionalAttrs (isAttrs action) action)

View file

@ -1,9 +1,4 @@
{ { lib, helpers }:
lib,
nixvimOptions,
toLuaObject,
nixvimUtils,
}:
with lib; with lib;
{ {
# TODO: DEPRECATED: use the `settings` option instead # TODO: DEPRECATED: use the `settings` option instead
@ -81,7 +76,7 @@ with lib;
let let
optionPath = if isString option then [ option ] else option; # option is already a path (i.e. a list) optionPath = if isString option then [ option ] else option; # option is already a path (i.e. a list)
optionPathSnakeCase = map nixvimUtils.toSnakeCase optionPath; optionPathSnakeCase = map helpers.toSnakeCase optionPath;
in in
mkRenamedOptionModule (basePluginPath ++ optionPath) (settingsPath ++ optionPathSnakeCase) mkRenamedOptionModule (basePluginPath ++ optionPath) (settingsPath ++ optionPathSnakeCase)
) optionsRenamedToSettings); ) optionsRenamedToSettings);
@ -90,10 +85,10 @@ with lib;
{ {
enable = mkEnableOption originalName; enable = mkEnableOption originalName;
package = nixvimOptions.mkPluginPackageOption originalName defaultPackage; package = helpers.mkPluginPackageOption originalName defaultPackage;
} }
// optionalAttrs hasSettings { // optionalAttrs hasSettings {
settings = nixvimOptions.mkSettingsOption { settings = helpers.mkSettingsOption {
description = settingsDescription; description = settingsDescription;
options = settingsOptions; options = settingsOptions;
example = settingsExample; example = settingsExample;
@ -113,7 +108,7 @@ with lib;
} }
(optionalAttrs callSetup { (optionalAttrs callSetup {
${extraConfigNamespace} = '' ${extraConfigNamespace} = ''
require('${luaName}')${setup}(${optionalString (cfg ? settings) (toLuaObject cfg.settings)}) require('${luaName}')${setup}(${optionalString (cfg ? settings) (helpers.toLuaObject cfg.settings)})
''; '';
}) })
(optionalAttrs (isColorscheme && (colorscheme != null)) { colorscheme = mkDefault colorscheme; }) (optionalAttrs (isColorscheme && (colorscheme != null)) { colorscheme = mkDefault colorscheme; })

View file

@ -1,10 +1,6 @@
{ { lib, helpers }:
lib,
nixvimTypes,
nixvimUtils,
}:
with lib; with lib;
with nixvimUtils; with helpers;
let let
# Render a plugin default string # Render a plugin default string
pluginDefaultText = pluginDefaultText =
@ -85,7 +81,7 @@ rec {
); );
mkCompositeOption = description: options: mkCompositeOption' { inherit description options; }; mkCompositeOption = description: options: mkCompositeOption' { inherit description options; };
mkNullOrStr' = args: mkNullOrOption' (args // { type = with nixvimTypes; maybeRaw str; }); mkNullOrStr' = args: mkNullOrOption' (args // { type = with helpers.nixvimTypes; maybeRaw str; });
mkNullOrStr = description: mkNullOrStr' { inherit description; }; mkNullOrStr = description: mkNullOrStr' { inherit description; };
mkNullOrLua' = mkNullOrLua' =
@ -93,7 +89,7 @@ rec {
mkNullOrOption' ( mkNullOrOption' (
args args
// { // {
type = nixvimTypes.strLua; type = helpers.nixvimTypes.strLua;
apply = mkRaw; apply = mkRaw;
} }
); );
@ -104,7 +100,7 @@ rec {
mkNullOrOption' ( mkNullOrOption' (
args args
// { // {
type = nixvimTypes.strLuaFn; type = helpers.nixvimTypes.strLuaFn;
apply = mkRaw; apply = mkRaw;
} }
); );
@ -115,7 +111,7 @@ rec {
mkNullOrOption' ( mkNullOrOption' (
args args
// { // {
type = with nixvimTypes; either strLua type; type = with helpers.nixvimTypes; either strLua type;
apply = v: if isString v then mkRaw v else v; apply = v: if isString v then mkRaw v else v;
} }
); );
@ -126,7 +122,7 @@ rec {
mkNullOrOption' ( mkNullOrOption' (
args args
// { // {
type = with nixvimTypes; either strLuaFn type; type = with helpers.nixvimTypes; either strLuaFn type;
apply = v: if isString v then mkRaw v else v; apply = v: if isString v then mkRaw v else v;
} }
); );
@ -155,7 +151,7 @@ rec {
mkNullable' { inherit type pluginDefault description; }; mkNullable' { inherit type pluginDefault description; };
mkNullableWithRaw' = mkNullableWithRaw' =
{ type, ... }@args: mkNullable' (args // { type = nixvimTypes.maybeRaw type; }); { type, ... }@args: mkNullable' (args // { type = helpers.nixvimTypes.maybeRaw type; });
mkNullableWithRaw = mkNullableWithRaw =
type: pluginDefault: description: type: pluginDefault: description:
mkNullableWithRaw' { inherit type pluginDefault description; }; mkNullableWithRaw' { inherit type pluginDefault description; };
@ -191,17 +187,19 @@ rec {
mkStr' = args: mkNullableWithRaw' (args // { type = types.str; }); mkStr' = args: mkNullableWithRaw' (args // { type = types.str; });
mkStr = pluginDefault: description: mkStr' { inherit pluginDefault description; }; mkStr = pluginDefault: description: mkStr' { inherit pluginDefault description; };
mkAttributeSet' = args: mkNullable' (args // { type = nixvimTypes.attrs; }); mkAttributeSet' = args: mkNullable' (args // { type = helpers.nixvimTypes.attrs; });
mkAttributeSet = pluginDefault: description: mkAttributeSet' { inherit pluginDefault description; }; mkAttributeSet = pluginDefault: description: mkAttributeSet' { inherit pluginDefault description; };
mkListOf' = mkListOf' =
{ type, ... }@args: mkNullable' (args // { type = with nixvimTypes; listOf (maybeRaw type); }); { type, ... }@args:
mkNullable' (args // { type = with helpers.nixvimTypes; listOf (maybeRaw type); });
mkListOf = mkListOf =
type: pluginDefault: description: type: pluginDefault: description:
mkListOf' { inherit type pluginDefault description; }; mkListOf' { inherit type pluginDefault description; };
mkAttrsOf' = mkAttrsOf' =
{ type, ... }@args: mkNullable' (args // { type = with nixvimTypes; attrsOf (maybeRaw type); }); { type, ... }@args:
mkNullable' (args // { type = with helpers.nixvimTypes; attrsOf (maybeRaw type); });
mkAttrsOf = mkAttrsOf =
type: pluginDefault: description: type: pluginDefault: description:
mkAttrsOf' { inherit type pluginDefault description; }; mkAttrsOf' { inherit type pluginDefault description; };
@ -242,7 +240,7 @@ rec {
mkNullableWithRaw' ( mkNullableWithRaw' (
(filterAttrs (n: v: n != "name") args) (filterAttrs (n: v: n != "name") args)
// { // {
type = nixvimTypes.border; type = helpers.nixvimTypes.border;
description = concatStringsSep "\n" ( description = concatStringsSep "\n" (
(optional (description != "") description) (optional (description != "") description)
++ [ ++ [
@ -281,7 +279,7 @@ rec {
mkNullOrOption' ( mkNullOrOption' (
args args
// { // {
type = with nixvimTypes; either ints.unsigned logLevel; type = with helpers.nixvimTypes; either ints.unsigned logLevel;
apply = mapNullable ( apply = mapNullable (
value: if isInt value then value else mkRaw "vim.log.levels.${strings.toUpper value}" value: if isInt value then value else mkRaw "vim.log.levels.${strings.toUpper value}"
); );
@ -297,7 +295,7 @@ rec {
mkNullable' ( mkNullable' (
args args
// { // {
type = nixvimTypes.highlight; type = helpers.nixvimTypes.highlight;
inherit description; inherit description;
} }
); );

View file

@ -1,6 +1,6 @@
{ lib, nixvimOptions, ... }: { lib, helpers, ... }:
with lib; with lib;
with nixvimOptions; with helpers;
with lib.types; with lib.types;
let let
strLikeType = strLikeType =

View file

@ -1,6 +1,6 @@
{ {
lib, lib,
nixvimTypes, helpers,
_nixvimTests, _nixvimTests,
}: }:
with lib; with lib;
@ -115,7 +115,7 @@ rec {
null null
else if isString r then else if isString r then
{ __raw = r; } { __raw = r; }
else if nixvimTypes.isRawType r then else if helpers.nixvimTypes.isRawType r then
r r
else else
throw "mkRaw: invalid input: ${generators.toPretty { multiline = false; } r}"; throw "mkRaw: invalid input: ${generators.toPretty { multiline = false; } r}";

View file

@ -1,8 +1,4 @@
{ { lib, helpers }:
lib,
nixvimOptions,
nixvimUtils,
}:
with lib; with lib;
{ {
mkVimPlugin = mkVimPlugin =
@ -43,12 +39,12 @@ with lib;
if defaultPackage == null then if defaultPackage == null then
{ } { }
else else
{ package = nixvimOptions.mkPluginPackageOption name defaultPackage; }; { package = helpers.mkPluginPackageOption name defaultPackage; };
createSettingsOption = (isString globalPrefix) && (globalPrefix != ""); createSettingsOption = (isString globalPrefix) && (globalPrefix != "");
settingsOption = optionalAttrs createSettingsOption { settingsOption = optionalAttrs createSettingsOption {
settings = nixvimOptions.mkSettingsOption { settings = helpers.mkSettingsOption {
options = settingsOptions; options = settingsOptions;
example = settingsExample; example = settingsExample;
description = '' description = ''
@ -95,7 +91,7 @@ with lib;
let let
optionPath = if isString option then [ option ] else option; # option is already a path (i.e. a list) optionPath = if isString option then [ option ] else option; # option is already a path (i.e. a list)
optionPathSnakeCase = map nixvimUtils.toSnakeCase optionPath; optionPathSnakeCase = map helpers.toSnakeCase optionPath;
in in
mkRenamedOptionModule (basePluginPath ++ optionPath) (settingsPath ++ optionPathSnakeCase) mkRenamedOptionModule (basePluginPath ++ optionPath) (settingsPath ++ optionPathSnakeCase)
) optionsRenamedToSettings); ) optionsRenamedToSettings);