Compare commits

...

4 commits

Author SHA1 Message Date
18c17b7b8d
meta: don't check indent style for npins sources & lockfile
Some checks failed
Set up binary cache / cachix (default) (push) Has been cancelled
Set up binary cache / cachix (maximal) (push) Has been cancelled
Set up binary cache / cachix (nix) (push) Has been cancelled
Treewide Checks / Validate flake (push) Has been cancelled
Treewide Checks / Check formatting (push) Has been cancelled
Treewide Checks / Check source tree for typos (push) Has been cancelled
Treewide Checks / Validate documentation builds (push) Has been cancelled
Treewide Checks / Validate hyperlinks in documentation sources (push) Has been cancelled
Treewide Checks / Validate Editorconfig conformance (push) Has been cancelled
Build and deploy documentation / Check latest commit (push) Has been cancelled
Build and deploy documentation / publish (push) Has been cancelled
2025-06-20 20:44:48 +03:00
raf
76becd77e0
Merge pull request #961 from rrvsh/luasnip-customsnippets
snippets/luasnip: add the ability to add custom snippets
2025-06-20 16:36:52 +03:00
Mohammad Rafiq
8c7fdc0f5d
feat(snippets/luasnip): allow custom snippets 2025-06-19 10:31:17 +08:00
787678dd73
flake: bump inputs 2025-06-18 23:42:17 +03:00
5 changed files with 111 additions and 13 deletions

View file

@ -19,13 +19,12 @@ indent_style = space
indent_size = 2 indent_size = 2
tab_width = 2 tab_width = 2
[*.{diff,patch}] [*.{diff,patch,lock}]
end_of_line = unset end_of_line = unset
insert_final_newline = unset insert_final_newline = unset
trim_trailing_whitespace = unset trim_trailing_whitespace = unset
[*.lock]
indent_size = unset
[npins/sources.json] [npins/sources.json]
insert_final_newline = unset indent_style = unset
indent_size = unset
trim_trailing_whitespace = unset

View file

@ -352,6 +352,7 @@
[rrvsh](https://github.com/rrvsh): [rrvsh](https://github.com/rrvsh):
- Add custom snippet support to `vim.snippets.luasnip`
- Fix namespace of python-lsp-server by changing it to python3Packages - Fix namespace of python-lsp-server by changing it to python3Packages
[Noah765](https://github.com/Noah765): [Noah765](https://github.com/Noah765):

12
flake.lock generated
View file

@ -58,11 +58,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1749796250, "lastModified": 1750047244,
"narHash": "sha256-oxvVAFUO9husnRk6XZcLFLjLWL9z0pW25Fk6kVKwt1c=", "narHash": "sha256-vluLARrk4485npdyHOj8XKr0yk6H22pNf+KVRNL+i/Y=",
"owner": "oxalica", "owner": "oxalica",
"repo": "nil", "repo": "nil",
"rev": "9e4cccb088440c20703d62db9de8d5ae06d4a449", "rev": "870a4b1b5f12004832206703ac15aa85c42c247b",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -73,11 +73,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1749743618, "lastModified": 1750215678,
"narHash": "sha256-ibsz06u1jlWyH7YURnRhLQn38Tuc5zwknr00suFjvfA=", "narHash": "sha256-Rc/ytpamXRf6z8UA2SGa4aaWxUXRbX2MAWIu2C8M+ok=",
"owner": "nixos", "owner": "nixos",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "8d6cdc7756817e0c4b24567271634a44bcf80752", "rev": "5395fb3ab3f97b9b7abca147249fa2e8ed27b192",
"type": "github" "type": "github"
}, },
"original": { "original": {

View file

@ -1,11 +1,48 @@
{ {
config, config,
lib, lib,
pkgs,
... ...
}: let }: let
inherit (lib.modules) mkIf; inherit (lib.modules) mkIf;
inherit (lib.lists) replicate;
inherit
(lib.strings)
optionalString
removeSuffix
concatStrings
stringAsChars
concatMapStringsSep
;
inherit (lib.attrsets) mapAttrsToList;
inherit (pkgs) writeTextFile;
cfg = config.vim.snippets.luasnip; cfg = config.vim.snippets.luasnip;
# 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;
in { in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
vim = { vim = {
@ -19,11 +56,16 @@ in {
after = cfg.loaders; after = cfg.loaders;
}; };
startPlugins = cfg.providers; startPlugins = cfg.providers ++ customSnipmateSnippetFiles;
autocomplete.nvim-cmp = mkIf config.vim.autocomplete.nvim-cmp.enable { autocomplete.nvim-cmp = mkIf config.vim.autocomplete.nvim-cmp.enable {
sources = {luasnip = "[LuaSnip]";}; sources = {luasnip = "[LuaSnip]";};
sourcePlugins = ["cmp-luasnip"]; sourcePlugins = ["cmp-luasnip"];
}; };
snippets.luasnip.loaders = ''
${optionalString (
cfg.customSnippets.snipmate != {}
) "require('luasnip.loaders.from_snipmate').lazy_load()"}
'';
}; };
}; };
} }

View file

@ -1,6 +1,6 @@
{lib, ...}: let {lib, ...}: let
inherit (lib.options) mkEnableOption mkOption literalExpression literalMD; inherit (lib.options) mkEnableOption mkOption literalExpression literalMD;
inherit (lib.types) listOf lines; inherit (lib.types) listOf lines submodule str attrsOf;
inherit (lib.nvim.types) pluginType mkPluginSetupOption; inherit (lib.nvim.types) pluginType mkPluginSetupOption;
in { in {
options.vim.snippets.luasnip = { options.vim.snippets.luasnip = {
@ -36,5 +36,61 @@ in {
setupOpts = mkPluginSetupOption "LuaSnip" { setupOpts = mkPluginSetupOption "LuaSnip" {
enable_autosnippets = mkEnableOption "autosnippets"; enable_autosnippets = mkEnableOption "autosnippets";
}; };
customSnippets.snipmate = mkOption {
type = attrsOf (
listOf (submodule {
options = {
trigger = mkOption {
type = str;
description = ''
The trigger used to activate this snippet.
'';
};
description = mkOption {
type = str;
default = "";
description = ''
The description shown for this snippet.
'';
};
body = mkOption {
type = str;
description = ''
[LuaSnip Documentation]: https://github.com/L3MON4D3/LuaSnip#add-snippets
The body of the snippet in SnipMate format (see [LuaSnip Documentation]).
'';
};
};
})
);
default = {};
example = ''
{
all = [
{
trigger = "if";
body = "if $1 else $2";
}
];
nix = [
{
trigger = "mkOption";
body = '''
mkOption {
type = $1;
default = $2;
description = $3;
example = $4;
}
''';
}
];
}
'';
description = ''
A list containing custom snippets in the SnipMate format to be loaded by LuaSnip.
'';
};
}; };
} }