Compare commits

..

No commits in common. "aeb09834d6239e1074d9ff30b7fa939f2db1cdf1" and "463a4f2d43033dc75d4e84522d0ff670001622bb" have entirely different histories.

View file

@ -4,28 +4,6 @@ let
inherit (lib.nix2lua) LuaNil scope lset pipe1 call call1; inherit (lib.nix2lua) LuaNil scope lset pipe1 call call1;
cfg = config.plugins.snippet.luasnip; cfg = config.plugins.snippet.luasnip;
nodes = lib.mkOption {
type = with lib.types; listOf (submodule snippetNodeOpts);
default = [ ];
};
unwrapNodes = map (n: n.genConfig);
genConfig = lib.mkOption {
type = lib.types.attrs;
internal = true;
};
snippetNodeOpts = { config, ... }: {
options = with lib; with types; {
kind = mkOption {
type = enum [ "text" "insert" "choice" "snippet" ];
};
text = mkOption {
type = nullOr (either str (listOf str));
default = null;
};
jump = lib.mkOption { jump = lib.mkOption {
type = with lib.types; nullOr number; type = with lib.types; nullOr number;
@ -37,42 +15,84 @@ let
`:help luasnip-basics-jump-index` `:help luasnip-basics-jump-index`
''; '';
}; };
unwrapJump = index: if index == null then LuaNil else index;
inherit nodes; nodes = lib.mkOption {
type = with lib.types; listOf (submodule snippetNodeOpts);
};
unwrapNodes = map (n: n.genConfig);
# only for kind=snippet genConfig = lib.mkOption {
indentString = mkOption { type = lib.types.attrs;
internal = true;
};
snippetNodeOpts = { config, ... }: {
options = with lib; with types; {
text = mkOption {
type = nullOr (either str (listOf str));
default = null;
};
insert = mkOption {
type = nullOr (either number (submodule ({ ... }: {
options = {
inherit jump;
text = mkOption {
type = nullOr (either str (listOf str));
default = null;
description = ''
A single string for just one line, a list with entries for multiple lines.
This text will be SELECTed when the `insertNode` is jumped into.
`:help luasnip-insertnode`
'';
};
};
})));
default = null;
};
choice = mkOption {
type = nullOr (submodule ({ ... }: {
options = { inherit jump nodes; };
}));
default = null;
};
snippet = mkOption {
type = nullOr (submodule ({ ... }: {
options = {
inherit jump nodes;
indent = mkOption {
type = types.str; type = types.str;
default = ""; default = "";
}; };
};
}));
default = null;
};
inherit genConfig; inherit genConfig;
}; };
config = config = {
let
inherit (config) kind text jump nodes;
unwrapJump = index: if index == null then LuaNil else index;
in
{
kind = lib.mkDefault (
if nodes != [ ] then "snippet"
else if jump != null then "insert"
else "text"
);
genConfig = genConfig =
if kind == "text" then let
if text != null then call1 "t" text ins = config.insert;
else throw "luasnip textnode require a 'text' config" ch = config.choice;
else if kind == "insert" then call "i" [ (unwrapJump jump) text ] sn = config.snippet;
else if kind == "choice" then call "c" [ (unwrapJump jump) (unwrapNodes nodes) ] in
else if kind == "snippet" then if config.text != null then call1 "t" config.text
if config.indentString != "" then else if ins != null then
call "isn" [ (unwrapJump jump) (unwrapNodes nodes) config.indentString ] if builtins.isInt ins then call "i" [ ins ]
else else call "i" [ (unwrapJump ins.jump) ins.text ]
call "sn" [ (unwrapJump jump) (unwrapNodes nodes) ] else if ch != null then
call "c" [ (unwrapJump ch.jump) (unwrapNodes ch.nodes) ]
else if sn != null then
if sn.indent != "" then
call "isn" [ (unwrapJump sn.jump) (unwrapNodes sn.nodes) sn.indent ]
else call "sn" [ (unwrapJump sn.jump) (unwrapNodes sn.nodes) ]
else null; else null;
}; };
}; };
@ -86,7 +106,7 @@ let
''; '';
}; };
inherit nodes; nodes = nodes // { default = [ ]; };
inherit genConfig; inherit genConfig;
}; };
@ -175,9 +195,6 @@ in
inherit (cfg) package; inherit (cfg) package;
varName = "luasnip"; varName = "luasnip";
setupSettings = cfg.settings; setupSettings = cfg.settings;
extraImports = lib.mkIf (cfg.snippetGroups != [ ]) {
luasnip_types = "luasnip.util.types";
};
afterSetup = lib.mkIf (cfg.snippetGroups != [ ]) [ afterSetup = lib.mkIf (cfg.snippetGroups != [ ]) [
(scope (lib.flatten [ (scope (lib.flatten [
(lib.mapAttrsToList (k: v: lset k (pipe1 varName v)) { (lib.mapAttrsToList (k: v: lset k (pipe1 varName v)) {