2024-10-09 19:50:34 +02:00
|
|
|
{
|
|
|
|
|
config,
|
|
|
|
|
lib,
|
2025-06-17 11:23:43 +08:00
|
|
|
pkgs,
|
2024-10-09 19:50:34 +02:00
|
|
|
...
|
|
|
|
|
}: let
|
|
|
|
|
inherit (lib.modules) mkIf;
|
|
|
|
|
|
2025-06-17 11:23:43 +08:00
|
|
|
inherit (lib.lists) replicate;
|
|
|
|
|
inherit
|
|
|
|
|
(lib.strings)
|
|
|
|
|
optionalString
|
|
|
|
|
removeSuffix
|
|
|
|
|
concatStrings
|
|
|
|
|
stringAsChars
|
|
|
|
|
concatMapStringsSep
|
|
|
|
|
;
|
|
|
|
|
inherit (lib.attrsets) mapAttrsToList;
|
|
|
|
|
inherit (pkgs) writeTextFile;
|
2024-10-09 19:50:34 +02:00
|
|
|
cfg = config.vim.snippets.luasnip;
|
2025-06-17 11:23:43 +08:00
|
|
|
# LuaSnip freaks out if the indentation is wrong in snippets
|
|
|
|
|
indent = n: s: let
|
|
|
|
|
indentString = concatStrings (replicate n " ");
|
|
|
|
|
sep = "\n" + indentString;
|
|
|
|
|
in
|
|
|
|
|
indentString
|
|
|
|
|
+ stringAsChars (c:
|
|
|
|
|
if c == "\n"
|
|
|
|
|
then sep
|
|
|
|
|
else c) (removeSuffix "\n" s);
|
|
|
|
|
customSnipmateSnippetFiles =
|
|
|
|
|
mapAttrsToList (
|
|
|
|
|
name: value:
|
|
|
|
|
writeTextFile {
|
|
|
|
|
name = "${name}.snippets";
|
|
|
|
|
text =
|
|
|
|
|
concatMapStringsSep "\n" (x: ''
|
|
|
|
|
snippet ${x.trigger} ${x.description}
|
|
|
|
|
${indent 2 x.body}
|
|
|
|
|
'')
|
|
|
|
|
value;
|
|
|
|
|
destination = "/snippets/${name}.snippets";
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
cfg.customSnippets.snipmate;
|
2024-10-09 19:50:34 +02:00
|
|
|
in {
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
vim = {
|
2025-01-11 14:02:21 +01:00
|
|
|
lazy.plugins.luasnip = {
|
|
|
|
|
package = "luasnip";
|
2025-01-12 12:48:44 +01:00
|
|
|
|
2025-01-12 09:58:55 +01:00
|
|
|
lazy = true;
|
2025-01-12 12:48:44 +01:00
|
|
|
|
2025-01-11 14:02:21 +01:00
|
|
|
setupModule = "luasnip";
|
|
|
|
|
inherit (cfg) setupOpts;
|
2025-01-12 12:48:44 +01:00
|
|
|
|
2025-01-12 11:39:41 +01:00
|
|
|
after = cfg.loaders;
|
2024-11-04 16:50:50 +01:00
|
|
|
};
|
2025-06-17 11:23:43 +08:00
|
|
|
startPlugins = cfg.providers ++ customSnipmateSnippetFiles;
|
2025-01-11 21:04:16 +01:00
|
|
|
autocomplete.nvim-cmp = mkIf config.vim.autocomplete.nvim-cmp.enable {
|
2024-11-04 16:50:50 +01:00
|
|
|
sources = {luasnip = "[LuaSnip]";};
|
|
|
|
|
sourcePlugins = ["cmp-luasnip"];
|
|
|
|
|
};
|
2025-06-17 11:23:43 +08:00
|
|
|
snippets.luasnip.loaders = ''
|
|
|
|
|
${optionalString (
|
|
|
|
|
cfg.customSnippets.snipmate != {}
|
|
|
|
|
) "require('luasnip.loaders.from_snipmate').lazy_load()"}
|
2025-07-16 19:22:19 +08:00
|
|
|
${optionalString (
|
|
|
|
|
config.vim.autocomplete.nvim-cmp.enable || config.vim.autocomplete.blink-cmp.friendly-snippets.enable
|
|
|
|
|
) "require('luasnip.loaders.from_vscode').lazy_load()"}
|
2025-06-17 11:23:43 +08:00
|
|
|
'';
|
2024-10-09 19:50:34 +02:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
}
|