lib: switch to mkLuaInline

This commit is contained in:
Ching Pei Yang 2024-03-16 09:29:07 +00:00
parent 5ea6272bee
commit 77d3cd5e0c
3 changed files with 9 additions and 7 deletions

View File

@ -48,11 +48,13 @@ in rec {
# Convert a list of lua expressions to a lua table. The difference to listToLuaTable is that the elements here are expected to be lua expressions already, whereas listToLuaTable converts from nix types to lua first
luaTable = items: ''{${concatStringsSep "," items}}'';
isLuaInline = {_type ? null, ...}: _type == "lua-inline";
toLuaObject = args:
if isAttrs args
then
if hasAttr "__raw" args
then args.__raw
if isLuaInline args
then args.expr
else if hasAttr "__empty" args
then "{ }"
else

View File

@ -4,6 +4,6 @@
typesLanguage = import ./languages.nix {inherit lib;};
in {
inherit (typesDag) dagOf;
inherit (typesPlugin) pluginsOpt extraPluginType mkPluginSetupOption rawLua;
inherit (typesPlugin) pluginsOpt extraPluginType mkPluginSetupOption luaInline;
inherit (typesLanguage) diagnostics mkGrammarOption;
}

View File

@ -145,13 +145,13 @@ in {
type = pluginsType;
};
rawLua = lib.mkOptionType {
name = "rawLua";
check = val: isString val || val ? __raw;
luaInline = lib.mkOptionType {
name = "luaInline";
check = x: lib.nvim.lua.isLuaInline x || builtins.isString x;
merge = loc: defs: let
val =
if isString loc
then {__raw = val;}
then lib.generators.mkLuaInline loc
else loc;
in
lib.mergeOneOption val defs;