From 29694855025a5ca5237ea01e6fee7e16a67d0ceb Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Tue, 21 May 2024 01:43:02 +0300 Subject: [PATCH] neovim: refac luasnip snippets --- flake.lock | 8 ++-- neovim/snippets.nix | 113 +++++++++++++++++++++++++++++++------------- 2 files changed, 83 insertions(+), 38 deletions(-) diff --git a/flake.lock b/flake.lock index 2e97afb..68ab243 100644 --- a/flake.lock +++ b/flake.lock @@ -279,11 +279,11 @@ ] }, "locked": { - "lastModified": 1716215872, - "narHash": "sha256-zjy9raJUx+14DVMDuVfZYbBOPcHgMBxk2vt+rmNn7uk=", + "lastModified": 1716244689, + "narHash": "sha256-tFsMxZcbg8WAmNmmL/WxFjp4wgCK2XzTDkM5PNZqCZQ=", "ref": "refs/heads/main", - "rev": "463a4f2d43033dc75d4e84522d0ff670001622bb", - "revCount": 80, + "rev": "881339ef7077b5c1d07041a0024575a4170c0174", + "revCount": 83, "type": "git", "url": "https://git.pleshevski.ru/pleshevskiy/nixeovim" }, diff --git a/neovim/snippets.nix b/neovim/snippets.nix index 7c67e63..1b6aa2c 100644 --- a/neovim/snippets.nix +++ b/neovim/snippets.nix @@ -1,47 +1,92 @@ { ... }: -let - t = text: { inherit text; }; - i = jump: text: { inherit jump text; }; - c = jump: nodes: { inherit jump nodes; }; -in { plugins.snippet.luasnip.snippetGroups = [ { filetype = "nix"; snippets = { "if".nodes = [ - (t "if ") - (i 1 "condition") - (t " then ") - (i 2 "trueBody") - (t " else ") - (i 3 "falseBody") - (t ";") + { text = "if "; } + { jump = 1; text = "condition"; } + { text = " then "; } + { jump = 2; text = "trueBody"; } + { text = " else "; } + { jump = 3; text = "falseBody"; } + { text = ";"; } ]; + "var".nodes = [ - (i 1 "name") - (t " = ") - (c 2 [ - (i null "value") - { - snippet.nodes = [ - { insert = 1; } - (t "[") - { insert = 2; } - (t "]") - ]; - } - { - snippet.nodes = [ - { insert = 1; } - (t "{") - { insert = 2; } - (t "}") - ]; - } - ]) - (t ";") + { jump = 1; text = "name"; } + { text = " = "; } + { + jump = 2; + choices = [ + { kind = "insert"; text = "value"; } + { + nodes = [ + { jump = 1; } + { text = "["; } + { jump = 2; } + { text = "]"; } + ]; + } + { + nodes = [ + { jump = 1; } + { text = "{"; } + { jump = 2; } + { text = "}"; } + ]; + } + ]; + } + { text = ";"; } + ]; + + "module".nodes = [ + { text = "{ "; } + { + jump = 1; + choices = [ + { kind = "insert"; text = "pkgs, "; } + { text = "config, "; } + { text = "config, lib, "; } + { text = "config, lib, pkgs, "; } + ]; + } + { text = "..."; } + { text = [ " }:" "" ]; } + { + jump = 2; + choices = [ + { + nodes = [ + { jump = 1; } + { text = "let "; } + { jump = 2; } + { text = "in"; } + ]; + } + { + nodes = [ + { jump = 1; } + { text = "with "; } + { jump = 2; text = "lib"; } + { text = ";"; } + ]; + } + { text = ""; } + ]; + } + { text = [ "" "{" "" ]; } + { + jump = 3; + nodes = [ + { text = " "; } + { jump = 1; text = "hello"; } + ]; + } + { text = [ "" "}" ]; } ]; }; }