Skip to content

Commit

Permalink
lib: migrate helpers.nixvimTypes -> lib.types
Browse files Browse the repository at this point in the history
  • Loading branch information
MattSturgeon committed Aug 21, 2024
1 parent b414a53 commit b7f419a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 18 deletions.
2 changes: 1 addition & 1 deletion lib/autocmd-helpers.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lib/keymap-helpers.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
27 changes: 12 additions & 15 deletions lib/options.nix
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ 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' =
args:
mkNullOrOption' (
args
// {
type = helpers.nixvimTypes.strLua;
type = types.strLua;
apply = helpers.mkRaw;
}
);
Expand All @@ -99,7 +99,7 @@ rec {
mkNullOrOption' (
args
// {
type = helpers.nixvimTypes.strLuaFn;
type = types.strLuaFn;
apply = helpers.mkRaw;
}
);
Expand All @@ -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;
}
);
Expand All @@ -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;
}
);
Expand Down Expand Up @@ -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; };
Expand Down Expand Up @@ -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; };
Expand Down Expand Up @@ -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)
++ [
Expand Down Expand Up @@ -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}"
);
Expand All @@ -295,7 +292,7 @@ rec {
mkNullable' (
args
// {
type = helpers.nixvimTypes.highlight;
type = types.highlight;
inherit description;
}
);
Expand Down
2 changes: 2 additions & 0 deletions lib/types.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion lib/utils.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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}";
Expand Down

0 comments on commit b7f419a

Please sign in to comment.