From b7f419a759f70126e220533b724cc17e8528b184 Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Sat, 3 Aug 2024 16:36:50 +0100 Subject: [PATCH] lib: migrate `helpers.nixvimTypes` -> `lib.types` --- lib/autocmd-helpers.nix | 2 +- lib/keymap-helpers.nix | 2 +- lib/options.nix | 27 ++++++++++++--------------- lib/types.nix | 2 ++ lib/utils.nix | 2 +- 5 files changed, 17 insertions(+), 18 deletions(-) diff --git a/lib/autocmd-helpers.nix b/lib/autocmd-helpers.nix index 8f83ccfc82..c47fcaaa86 100644 --- a/lib/autocmd-helpers.nix +++ b/lib/autocmd-helpers.nix @@ -39,7 +39,7 @@ rec { A textual description of this autocommand. ''; - callback = helpers.mkNullOrOption (with types; either str helpers.nixvimTypes.rawLua) '' + callback = helpers.mkNullOrOption (with types; either str rawLua) '' A function or a string. - 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. diff --git a/lib/keymap-helpers.nix b/lib/keymap-helpers.nix index e6863f40a3..80271c7c0a 100644 --- a/lib/keymap-helpers.nix +++ b/lib/keymap-helpers.nix @@ -117,7 +117,7 @@ rec { // (optionalAttrs (isAttrs action || action) { action = mkOption ( { - type = helpers.nixvimTypes.maybeRaw str; + type = maybeRaw str; description = "The action to execute."; apply = v: if options.lua.isDefined or false && config.lua then helpers.mkRaw v else v; } diff --git a/lib/options.nix b/lib/options.nix index d187d5a255..5ce86672d6 100644 --- a/lib/options.nix +++ b/lib/options.nix @@ -80,7 +80,7 @@ rec { ); mkCompositeOption = description: options: mkCompositeOption' { inherit description options; }; - mkNullOrStr' = args: mkNullOrOption' (args // { type = with helpers.nixvimTypes; maybeRaw str; }); + mkNullOrStr' = args: mkNullOrOption' (args // { type = with types; maybeRaw str; }); mkNullOrStr = description: mkNullOrStr' { inherit description; }; mkNullOrLua' = @@ -88,7 +88,7 @@ rec { mkNullOrOption' ( args // { - type = helpers.nixvimTypes.strLua; + type = types.strLua; apply = helpers.mkRaw; } ); @@ -99,7 +99,7 @@ rec { mkNullOrOption' ( args // { - type = helpers.nixvimTypes.strLuaFn; + type = types.strLuaFn; apply = helpers.mkRaw; } ); @@ -110,7 +110,7 @@ rec { mkNullOrOption' ( args // { - type = with helpers.nixvimTypes; either strLua type; + type = with types; either strLua type; apply = v: if isString v then helpers.mkRaw v else v; } ); @@ -121,7 +121,7 @@ rec { mkNullOrOption' ( args // { - type = with helpers.nixvimTypes; either strLuaFn type; + type = with types; either strLuaFn type; apply = v: if isString v then helpers.mkRaw v else v; } ); @@ -149,8 +149,7 @@ rec { type: pluginDefault: description: mkNullable' { inherit type pluginDefault description; }; - mkNullableWithRaw' = - { type, ... }@args: mkNullable' (args // { type = helpers.nixvimTypes.maybeRaw type; }); + mkNullableWithRaw' = { type, ... }@args: mkNullable' (args // { type = types.maybeRaw type; }); mkNullableWithRaw = type: pluginDefault: description: mkNullableWithRaw' { inherit type pluginDefault description; }; @@ -186,19 +185,17 @@ rec { mkStr' = args: mkNullableWithRaw' (args // { type = types.str; }); mkStr = pluginDefault: description: mkStr' { inherit pluginDefault description; }; - mkAttributeSet' = args: mkNullable' (args // { type = helpers.nixvimTypes.attrs; }); + mkAttributeSet' = args: mkNullable' (args // { type = types.attrs; }); mkAttributeSet = pluginDefault: description: mkAttributeSet' { inherit pluginDefault description; }; mkListOf' = - { type, ... }@args: - mkNullable' (args // { type = with helpers.nixvimTypes; listOf (maybeRaw type); }); + { type, ... }@args: mkNullable' (args // { type = with types; listOf (maybeRaw type); }); mkListOf = type: pluginDefault: description: mkListOf' { inherit type pluginDefault description; }; mkAttrsOf' = - { type, ... }@args: - mkNullable' (args // { type = with helpers.nixvimTypes; attrsOf (maybeRaw type); }); + { type, ... }@args: mkNullable' (args // { type = with types; attrsOf (maybeRaw type); }); mkAttrsOf = type: pluginDefault: description: mkAttrsOf' { inherit type pluginDefault description; }; @@ -239,7 +236,7 @@ rec { mkNullableWithRaw' ( (filterAttrs (n: v: n != "name") args) // { - type = helpers.nixvimTypes.border; + type = types.border; description = concatStringsSep "\n" ( (optional (description != "") description) ++ [ @@ -279,7 +276,7 @@ rec { mkNullOrOption' ( args // { - type = with helpers.nixvimTypes; either ints.unsigned logLevel; + type = with types; either ints.unsigned logLevel; apply = mapNullable ( value: if isInt value then value else helpers.mkRaw "vim.log.levels.${strings.toUpper value}" ); @@ -295,7 +292,7 @@ rec { mkNullable' ( args // { - type = helpers.nixvimTypes.highlight; + type = types.highlight; inherit description; } ); diff --git a/lib/types.nix b/lib/types.nix index 772e6387d0..2a4c0e6a5f 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -16,6 +16,8 @@ let isRawType = v: v ? __raw && isString v.__raw; in rec { + # TODO: deprecate in favor of types.rawLua.check + # Or move to utils, lua, etc? inherit isRawType; rawLua = mkOptionType { diff --git a/lib/utils.nix b/lib/utils.nix index 7c548f6861..14e8281135 100644 --- a/lib/utils.nix +++ b/lib/utils.nix @@ -115,7 +115,7 @@ rec { null else if isString r then { __raw = r; } - else if helpers.nixvimTypes.isRawType r then + else if types.isRawType r then r else throw "mkRaw: invalid input: ${generators.toPretty { multiline = false; } r}";