lib: migrate helpers.nixvimTypes -> lib.types

This commit is contained in:
Matt Sturgeon 2024-08-03 16:36:50 +01:00
parent b414a53649
commit b7f419a759
No known key found for this signature in database
GPG key ID: 4F91844CED1A8299
5 changed files with 17 additions and 18 deletions

View file

@ -39,7 +39,7 @@ rec {
A textual description of this autocommand. 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. 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.

View file

@ -117,7 +117,7 @@ rec {
// (optionalAttrs (isAttrs action || action) { // (optionalAttrs (isAttrs action || action) {
action = mkOption ( action = mkOption (
{ {
type = helpers.nixvimTypes.maybeRaw str; type = maybeRaw str;
description = "The action to execute."; description = "The action to execute.";
apply = v: if options.lua.isDefined or false && config.lua then helpers.mkRaw v else v; apply = v: if options.lua.isDefined or false && config.lua then helpers.mkRaw v else v;
} }

View file

@ -80,7 +80,7 @@ rec {
); );
mkCompositeOption = description: options: mkCompositeOption' { inherit description options; }; 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; }; mkNullOrStr = description: mkNullOrStr' { inherit description; };
mkNullOrLua' = mkNullOrLua' =
@ -88,7 +88,7 @@ rec {
mkNullOrOption' ( mkNullOrOption' (
args args
// { // {
type = helpers.nixvimTypes.strLua; type = types.strLua;
apply = helpers.mkRaw; apply = helpers.mkRaw;
} }
); );
@ -99,7 +99,7 @@ rec {
mkNullOrOption' ( mkNullOrOption' (
args args
// { // {
type = helpers.nixvimTypes.strLuaFn; type = types.strLuaFn;
apply = helpers.mkRaw; apply = helpers.mkRaw;
} }
); );
@ -110,7 +110,7 @@ rec {
mkNullOrOption' ( mkNullOrOption' (
args 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; apply = v: if isString v then helpers.mkRaw v else v;
} }
); );
@ -121,7 +121,7 @@ rec {
mkNullOrOption' ( mkNullOrOption' (
args 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; apply = v: if isString v then helpers.mkRaw v else v;
} }
); );
@ -149,8 +149,7 @@ rec {
type: pluginDefault: description: type: pluginDefault: description:
mkNullable' { inherit type pluginDefault description; }; mkNullable' { inherit type pluginDefault description; };
mkNullableWithRaw' = mkNullableWithRaw' = { type, ... }@args: mkNullable' (args // { type = types.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; };
@ -186,19 +185,17 @@ 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 = helpers.nixvimTypes.attrs; }); mkAttributeSet' = args: mkNullable' (args // { type = types.attrs; });
mkAttributeSet = pluginDefault: description: mkAttributeSet' { inherit pluginDefault description; }; mkAttributeSet = pluginDefault: description: mkAttributeSet' { inherit pluginDefault description; };
mkListOf' = mkListOf' =
{ type, ... }@args: { type, ... }@args: mkNullable' (args // { type = with types; listOf (maybeRaw type); });
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: { type, ... }@args: mkNullable' (args // { type = with types; attrsOf (maybeRaw type); });
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; };
@ -239,7 +236,7 @@ rec {
mkNullableWithRaw' ( mkNullableWithRaw' (
(filterAttrs (n: v: n != "name") args) (filterAttrs (n: v: n != "name") args)
// { // {
type = helpers.nixvimTypes.border; type = types.border;
description = concatStringsSep "\n" ( description = concatStringsSep "\n" (
(optional (description != "") description) (optional (description != "") description)
++ [ ++ [
@ -279,7 +276,7 @@ rec {
mkNullOrOption' ( mkNullOrOption' (
args args
// { // {
type = with helpers.nixvimTypes; either ints.unsigned logLevel; type = with types; either ints.unsigned logLevel;
apply = mapNullable ( apply = mapNullable (
value: if isInt value then value else helpers.mkRaw "vim.log.levels.${strings.toUpper value}" value: if isInt value then value else helpers.mkRaw "vim.log.levels.${strings.toUpper value}"
); );
@ -295,7 +292,7 @@ rec {
mkNullable' ( mkNullable' (
args args
// { // {
type = helpers.nixvimTypes.highlight; type = types.highlight;
inherit description; inherit description;
} }
); );

View file

@ -16,6 +16,8 @@ let
isRawType = v: v ? __raw && isString v.__raw; isRawType = v: v ? __raw && isString v.__raw;
in in
rec { rec {
# TODO: deprecate in favor of types.rawLua.check
# Or move to utils, lua, etc?
inherit isRawType; inherit isRawType;
rawLua = mkOptionType { rawLua = mkOptionType {

View file

@ -115,7 +115,7 @@ rec {
null null
else if isString r then else if isString r then
{ __raw = r; } { __raw = r; }
else if helpers.nixvimTypes.isRawType r then else if types.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}";