mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-22 00:48:58 +02:00
lib/types: make strLua
coerce strings to rawLua
Instead of relying on option `apply` functions to coerce the value to rawLua, this can be done in the type's merge function. Inspired by `types.coercedTo` in nixpkgs.
This commit is contained in:
parent
7886be8760
commit
a9c08fb6a5
1 changed files with 12 additions and 5 deletions
|
@ -8,14 +8,21 @@ let
|
||||||
mkNullOrOption
|
mkNullOrOption
|
||||||
;
|
;
|
||||||
|
|
||||||
strLikeType =
|
mkStrLuaType =
|
||||||
description:
|
description:
|
||||||
lib.mkOptionType {
|
lib.mkOptionType {
|
||||||
name = "str";
|
name = "strLua";
|
||||||
inherit description;
|
inherit description;
|
||||||
descriptionClass = "noun";
|
descriptionClass = "noun";
|
||||||
check = v: lib.isString v || isRawType v;
|
check = v: lib.isString v || isRawType v;
|
||||||
merge = lib.options.mergeEqualOption;
|
merge =
|
||||||
|
loc: defs:
|
||||||
|
lib.pipe defs [
|
||||||
|
# Coerce strings to rawLua
|
||||||
|
# TODO: consider deprecating this behaviour
|
||||||
|
(lib.map (def: def // { value = lib.nixvim.mkRaw def.value; }))
|
||||||
|
(lib.options.mergeEqualOption loc)
|
||||||
|
];
|
||||||
};
|
};
|
||||||
isRawType = v: v ? __raw && lib.isString v.__raw;
|
isRawType = v: v ? __raw && lib.isString v.__raw;
|
||||||
in
|
in
|
||||||
|
@ -107,8 +114,8 @@ rec {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
strLua = strLikeType "lua code string";
|
strLua = mkStrLuaType "lua code string";
|
||||||
strLuaFn = strLikeType "lua function string";
|
strLuaFn = mkStrLuaType "lua function string";
|
||||||
|
|
||||||
# When building the documentation `either` is extended to return the nestedType's sub-options
|
# When building the documentation `either` is extended to return the nestedType's sub-options
|
||||||
# This type can be used to avoid infinite recursion when evaluating the docs
|
# This type can be used to avoid infinite recursion when evaluating the docs
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue