Compare commits
No commits in common. "aeb09834d6239e1074d9ff30b7fa939f2db1cdf1" and "463a4f2d43033dc75d4e84522d0ff670001622bb" have entirely different histories.
aeb09834d6
...
463a4f2d43
1 changed files with 66 additions and 49 deletions
|
@ -4,13 +4,24 @@ 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;
|
||||||
|
|
||||||
|
|
||||||
|
jump = lib.mkOption {
|
||||||
|
type = with lib.types; nullOr number;
|
||||||
|
default = null;
|
||||||
|
description = ''
|
||||||
|
This determines when this node will be jumped to.
|
||||||
|
|
||||||
|
`:help luasnip-insertnode`
|
||||||
|
`:help luasnip-basics-jump-index`
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
unwrapJump = index: if index == null then LuaNil else index;
|
||||||
|
|
||||||
nodes = lib.mkOption {
|
nodes = lib.mkOption {
|
||||||
type = with lib.types; listOf (submodule snippetNodeOpts);
|
type = with lib.types; listOf (submodule snippetNodeOpts);
|
||||||
default = [ ];
|
|
||||||
};
|
};
|
||||||
unwrapNodes = map (n: n.genConfig);
|
unwrapNodes = map (n: n.genConfig);
|
||||||
|
|
||||||
|
|
||||||
genConfig = lib.mkOption {
|
genConfig = lib.mkOption {
|
||||||
type = lib.types.attrs;
|
type = lib.types.attrs;
|
||||||
internal = true;
|
internal = true;
|
||||||
|
@ -18,63 +29,72 @@ let
|
||||||
|
|
||||||
snippetNodeOpts = { config, ... }: {
|
snippetNodeOpts = { config, ... }: {
|
||||||
options = with lib; with types; {
|
options = with lib; with types; {
|
||||||
kind = mkOption {
|
|
||||||
type = enum [ "text" "insert" "choice" "snippet" ];
|
|
||||||
};
|
|
||||||
|
|
||||||
text = mkOption {
|
text = mkOption {
|
||||||
type = nullOr (either str (listOf str));
|
type = nullOr (either str (listOf str));
|
||||||
default = null;
|
default = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
jump = lib.mkOption {
|
insert = mkOption {
|
||||||
type = with lib.types; nullOr number;
|
type = nullOr (either number (submodule ({ ... }: {
|
||||||
default = null;
|
options = {
|
||||||
description = ''
|
inherit jump;
|
||||||
This determines when this node will be jumped to.
|
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`
|
`:help luasnip-insertnode`
|
||||||
`:help luasnip-basics-jump-index`
|
'';
|
||||||
'';
|
};
|
||||||
|
};
|
||||||
|
})));
|
||||||
|
default = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
inherit nodes;
|
choice = mkOption {
|
||||||
|
type = nullOr (submodule ({ ... }: {
|
||||||
|
options = { inherit jump nodes; };
|
||||||
|
}));
|
||||||
|
default = null;
|
||||||
|
};
|
||||||
|
|
||||||
# only for kind=snippet
|
snippet = mkOption {
|
||||||
indentString = mkOption {
|
type = nullOr (submodule ({ ... }: {
|
||||||
type = types.str;
|
options = {
|
||||||
default = "";
|
inherit jump nodes;
|
||||||
|
indent = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
default = "";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}));
|
||||||
|
default = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
inherit genConfig;
|
inherit genConfig;
|
||||||
};
|
};
|
||||||
|
|
||||||
config =
|
config = {
|
||||||
let
|
genConfig =
|
||||||
inherit (config) kind text jump nodes;
|
let
|
||||||
|
ins = config.insert;
|
||||||
unwrapJump = index: if index == null then LuaNil else index;
|
ch = config.choice;
|
||||||
in
|
sn = config.snippet;
|
||||||
{
|
in
|
||||||
kind = lib.mkDefault (
|
if config.text != null then call1 "t" config.text
|
||||||
if nodes != [ ] then "snippet"
|
else if ins != null then
|
||||||
else if jump != null then "insert"
|
if builtins.isInt ins then call "i" [ ins ]
|
||||||
else "text"
|
else call "i" [ (unwrapJump ins.jump) ins.text ]
|
||||||
);
|
else if ch != null then
|
||||||
|
call "c" [ (unwrapJump ch.jump) (unwrapNodes ch.nodes) ]
|
||||||
genConfig =
|
else if sn != null then
|
||||||
if kind == "text" then
|
if sn.indent != "" then
|
||||||
if text != null then call1 "t" text
|
call "isn" [ (unwrapJump sn.jump) (unwrapNodes sn.nodes) sn.indent ]
|
||||||
else throw "luasnip textnode require a 'text' config"
|
else call "sn" [ (unwrapJump sn.jump) (unwrapNodes sn.nodes) ]
|
||||||
else if kind == "insert" then call "i" [ (unwrapJump jump) text ]
|
else null;
|
||||||
else if kind == "choice" then call "c" [ (unwrapJump jump) (unwrapNodes nodes) ]
|
};
|
||||||
else if kind == "snippet" then
|
|
||||||
if config.indentString != "" then
|
|
||||||
call "isn" [ (unwrapJump jump) (unwrapNodes nodes) config.indentString ]
|
|
||||||
else
|
|
||||||
call "sn" [ (unwrapJump jump) (unwrapNodes nodes) ]
|
|
||||||
else null;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
snippetOpts = { name, ... } @ sub: {
|
snippetOpts = { name, ... } @ sub: {
|
||||||
|
@ -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)) {
|
||||||
|
|
Loading…
Reference in a new issue