Compare commits
No commits in common. "463a4f2d43033dc75d4e84522d0ff670001622bb" and "001a91bc8d8f11f6f6e87ab7e9e73440e67f6937" have entirely different histories.
463a4f2d43
...
001a91bc8d
6 changed files with 9 additions and 201 deletions
|
@ -20,11 +20,11 @@
|
|||
},
|
||||
"nix2lua": {
|
||||
"locked": {
|
||||
"lastModified": 1716215210,
|
||||
"narHash": "sha256-GjwpjhNGdrGH0dElAvcKSFY3nbRw4JYOKtKMmhMsEWw=",
|
||||
"lastModified": 1716152918,
|
||||
"narHash": "sha256-AvjnTReWS5TFgjXKtUOuzVjHZz94bhmRBGpTBP9XfqI=",
|
||||
"ref": "refs/heads/main",
|
||||
"rev": "4d3ae67617c2c1301a1a90601e20e15614d20319",
|
||||
"revCount": 52,
|
||||
"rev": "da13688260265f83e8b8221a7b46d8d84b3942fc",
|
||||
"revCount": 47,
|
||||
"type": "git",
|
||||
"url": "https://git.pleshevski.ru/mynix/nix2lua"
|
||||
},
|
||||
|
|
|
@ -25,7 +25,7 @@ let
|
|||
inherit event;
|
||||
inherit (cfg) pattern;
|
||||
callback = with lib; with nix2lua; lambda [ "ev" ] (lib.flatten [
|
||||
(flip mapAttrsToList cfg.opt (k: set "vim.opt.${k}"))
|
||||
(flip mapAttrsToList cfg.opt (k: v: if v == null then null else set "vim.opt.${k}" v))
|
||||
]);
|
||||
};
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ in
|
|||
# Global Opts
|
||||
(flip mapAttrsToList config.vim.g (k: set "vim.g.${k}"))
|
||||
# Opts
|
||||
(flip mapAttrsToList config.vim.opt (k: set "vim.opt.${k}"))
|
||||
(flip mapAttrsToList config.vim.opt (k: v: if v == null then null else set "vim.opt.${k}" v))
|
||||
# Plugins
|
||||
(map (v: v.genConfig) (filter (v: v.enable) (attrValues config.plugin)))
|
||||
# Cmd
|
||||
|
|
|
@ -1,177 +1,7 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
|
||||
let
|
||||
inherit (lib.nix2lua) LuaNil scope lset pipe1 call call1;
|
||||
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 {
|
||||
type = with lib.types; listOf (submodule snippetNodeOpts);
|
||||
};
|
||||
unwrapNodes = map (n: n.genConfig);
|
||||
|
||||
genConfig = lib.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;
|
||||
default = "";
|
||||
};
|
||||
};
|
||||
}));
|
||||
default = null;
|
||||
};
|
||||
|
||||
inherit genConfig;
|
||||
};
|
||||
|
||||
config = {
|
||||
genConfig =
|
||||
let
|
||||
ins = config.insert;
|
||||
ch = config.choice;
|
||||
sn = config.snippet;
|
||||
in
|
||||
if config.text != null then call1 "t" config.text
|
||||
else if ins != null then
|
||||
if builtins.isInt ins then call "i" [ ins ]
|
||||
else call "i" [ (unwrapJump ins.jump) ins.text ]
|
||||
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;
|
||||
};
|
||||
};
|
||||
|
||||
snippetOpts = { name, ... } @ sub: {
|
||||
options = with lib; with types; {
|
||||
context = mkOption {
|
||||
type = either str attrs;
|
||||
description = ''
|
||||
`:help luasnip-snippets';
|
||||
'';
|
||||
};
|
||||
|
||||
nodes = nodes // { default = [ ]; };
|
||||
|
||||
inherit genConfig;
|
||||
};
|
||||
|
||||
config = {
|
||||
context = lib.mkDefault name;
|
||||
|
||||
genConfig = call "s" [ sub.config.context (unwrapNodes sub.config.nodes) ];
|
||||
};
|
||||
};
|
||||
|
||||
snippetGroupOpts = { ... } @ sub: {
|
||||
options = with lib; {
|
||||
filetype = mkOption {
|
||||
type = types.str;
|
||||
};
|
||||
|
||||
opts = {
|
||||
type = mkOption {
|
||||
type = types.nullOr (types.enum [ "snippets" "autosnippets" ]);
|
||||
default = null;
|
||||
};
|
||||
key = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
};
|
||||
override_priority = mkOption {
|
||||
type = types.nullOr types.number;
|
||||
default = null;
|
||||
description = ''
|
||||
Set priority for all snippets.
|
||||
|
||||
`:help luasnip-api`
|
||||
'';
|
||||
};
|
||||
default_priority = mkOption {
|
||||
type = types.nullOr types.number;
|
||||
default = null;
|
||||
description = ''
|
||||
Set priority only for snippets without snippet priority.
|
||||
|
||||
`:help luasnip-api`
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
snippets = mkOption {
|
||||
type = types.attrsOf (types.submodule snippetOpts);
|
||||
default = { };
|
||||
};
|
||||
|
||||
inherit genConfig;
|
||||
};
|
||||
|
||||
config = {
|
||||
genConfig =
|
||||
let plugin = config.plugin.luasnip; in
|
||||
let inherit (sub.config) filetype snippets opts; in
|
||||
pipe1 plugin.var (call "add_snippets" [
|
||||
filetype
|
||||
(map (s: s.genConfig) (builtins.attrValues snippets))
|
||||
opts
|
||||
]);
|
||||
};
|
||||
};
|
||||
in
|
||||
{
|
||||
options.plugins.snippet.luasnip = with lib; {
|
||||
|
@ -183,34 +13,12 @@ in
|
|||
type = types.attrs;
|
||||
default = { };
|
||||
};
|
||||
|
||||
snippetGroups = mkOption {
|
||||
type = types.listOf (types.submodule snippetGroupOpts);
|
||||
default = [ ];
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
plugin.luasnip = rec {
|
||||
plugin.luasnip = {
|
||||
inherit (cfg) package;
|
||||
varName = "luasnip";
|
||||
setupSettings = cfg.settings;
|
||||
afterSetup = lib.mkIf (cfg.snippetGroups != [ ]) [
|
||||
(scope (lib.flatten [
|
||||
(lib.mapAttrsToList (k: v: lset k (pipe1 varName v)) {
|
||||
s = "snippet";
|
||||
sn = "snippet_node";
|
||||
isn = "indent_snippet_node";
|
||||
t = "text_node";
|
||||
i = "insert_node";
|
||||
f = "function_node";
|
||||
c = "choice_node";
|
||||
d = "dynamic_node";
|
||||
r = "restore_node";
|
||||
})
|
||||
(map (sg: sg.genConfig) cfg.snippetGroups)
|
||||
]))
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ in
|
|||
};
|
||||
|
||||
beforeSetup = with lib; optionals (cfg.extraGrammars != { }) (
|
||||
mapAttrsToList (k: v: set (pipe1 "parser_config" v.language) { }) cfg.extraGrammars
|
||||
mapAttrsToList (k: v: set "parser_config.${v.language}" { }) cfg.extraGrammars
|
||||
);
|
||||
|
||||
setupSettings = lib.mkMerge [
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
with lib.nix2lua;
|
||||
let
|
||||
inherit (lib.mod) Space cmd leader localLeader ctrl;
|
||||
inherit (lib.mod) Space cmd leader localLeader;
|
||||
gs = config.plugin.gitsigns-nvim.varName;
|
||||
hop = config.plugin.hop-nvim.varName;
|
||||
in
|
||||
|
|
Loading…
Reference in a new issue