plugins/nvim-snippets: init

This commit is contained in:
psfloyd 2024-08-03 13:45:18 -03:00
parent 6c1e87676c
commit c9a855fe68
3 changed files with 183 additions and 0 deletions

View file

@ -122,6 +122,7 @@
./snippets/friendly-snippets.nix ./snippets/friendly-snippets.nix
./snippets/luasnip ./snippets/luasnip
./snippets/nvim-snippets.nix
./statuslines/airline.nix ./statuslines/airline.nix
./statuslines/lightline.nix ./statuslines/lightline.nix

View file

@ -0,0 +1,63 @@
{
lib,
config,
pkgs,
...
}:
let
inherit (lib) types;
inherit (lib.nixvim) defaultNullOpts;
in
lib.nixvim.neovim-plugin.mkNeovimPlugin config {
name = "nvim-snippets";
luaName = "snippets";
defaultPackage = pkgs.vimPlugins.nvim-snippets;
maintainers = [ lib.maintainers.psfloyd ];
settingsOptions = {
create_autocmd = defaultNullOpts.mkBool false ''
Optionally load all snippets when opening a file.
Only needed if not using nvim-cmp.
'';
create_cmp_source = defaultNullOpts.mkBool true ''
Optionally create a nvim-cmp source.
Source name will be snippets.
'';
friendly_snippets = defaultNullOpts.mkBool false ''
Set to true if using friendly-snippets.
'';
ignored_filetypes = defaultNullOpts.mkListOf types.str null ''
Filetypes to ignore when loading snippets.
'';
extended_filetypes = defaultNullOpts.mkAttrsOf types.anything null ''
Filetypes to load snippets for in addition to the default ones. ex: {typescript = {
'javascript'}}'';
global_snippets = defaultNullOpts.mkListOf types.str [ "all" ] ''
Snippets to load for all filetypes.
'';
search_paths =
defaultNullOpts.mkListOf types.str [ { __raw = "vim.fn.stdpath('config') .. '/snippets'"; } ]
''
Paths to search for snippets.
'';
};
settingsExample = {
create_autocmd = true;
create_cmp_source = true;
friendly_snippets = true;
ignored_filetypes = [ "lua" ];
extended_filetypes = {
typescript = [ "javascript" ];
};
global_snippets = [ "all" ];
search_paths = [ { __raw = "vim.fn.stdpath('config') .. '/snippets'"; } ];
};
}

View file

@ -0,0 +1,119 @@
{
empty = {
plugins = {
cmp.enable = true;
nvim-snippets.enable = true;
};
};
defaults = {
plugins = {
cmp.enable = true;
nvim-snippets = {
enable = true;
settings = {
create_autocmd = false;
create_cmp_source = true;
friendly_snippets = false;
ignored_filetypes = null;
extended_filetypes = { };
global_snippets = [ "all" ];
search_paths = [ { __raw = "vim.fn.stdpath('config') .. '/snippets'"; } ];
};
};
};
};
example = {
plugins = {
friendly-snippets.enable = true;
cmp = {
enable = true;
settings = {
sources = [ { name = "snippets"; } ];
mapping.__raw = "require('cmp').mapping.preset.insert()";
};
};
nvim-snippets = {
enable = true;
settings = {
create_autocmd = false;
create_cmp_source = true;
friendly_snippets = true;
ignored_filetypes = [ "html" ];
extended_filetypes = {
typescript = [ "javascript" ];
tex = [ "latex" ];
};
global_snippets = [ "global_snippets" ];
search_paths = [
{ __raw = "vim.fn.stdpath('config') .. '/snippets'"; }
{ __raw = "vim.fn.stdpath('config') .. '/extra-snippets'"; }
];
};
};
};
keymaps = [
{
mode = "i";
key = "<Tab>";
action.__raw = ''
function()
if vim.snippet.active({ direction = 1 }) then
vim.schedule(function()
vim.snippet.jump(1)
end)
return
end
return "<Tab>"
end
'';
options = {
expr = true;
silent = true;
};
}
{
mode = "s";
key = "<Tab>";
action.__raw = ''
function()
vim.schedule(function()
vim.snippet.jump(1)
end)
end
'';
options = {
expr = true;
silent = true;
};
}
{
mode = [
"i"
"s"
];
key = "<S-Tab>";
action.__raw = ''
function()
if vim.snippet.active({ direction = -1 }) then
vim.schedule(function()
vim.snippet.jump(-1)
end)
return
end
return "<S-Tab>"
end
'';
options = {
expr = true;
silent = true;
};
}
];
};
}