mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 00:25:42 +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
|
||||
;
|
||||
|
||||
strLikeType =
|
||||
mkStrLuaType =
|
||||
description:
|
||||
lib.mkOptionType {
|
||||
name = "str";
|
||||
name = "strLua";
|
||||
inherit description;
|
||||
descriptionClass = "noun";
|
||||
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;
|
||||
in
|
||||
|
@ -107,8 +114,8 @@ rec {
|
|||
};
|
||||
};
|
||||
|
||||
strLua = strLikeType "lua code string";
|
||||
strLuaFn = strLikeType "lua function string";
|
||||
strLua = mkStrLuaType "lua code string";
|
||||
strLuaFn = mkStrLuaType "lua function string";
|
||||
|
||||
# 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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue