diff --git a/plugins/default.nix b/plugins/default.nix index 680128fd..8784db90 100644 --- a/plugins/default.nix +++ b/plugins/default.nix @@ -122,6 +122,7 @@ ./snippets/friendly-snippets.nix ./snippets/luasnip + ./snippets/nvim-snippets.nix ./statuslines/airline.nix ./statuslines/lightline.nix diff --git a/plugins/snippets/nvim-snippets.nix b/plugins/snippets/nvim-snippets.nix new file mode 100644 index 00000000..64f8d5f9 --- /dev/null +++ b/plugins/snippets/nvim-snippets.nix @@ -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'"; } ]; + }; +} diff --git a/tests/test-sources/plugins/snippets/nvim-snippets.nix b/tests/test-sources/plugins/snippets/nvim-snippets.nix new file mode 100644 index 00000000..a468d9bd --- /dev/null +++ b/tests/test-sources/plugins/snippets/nvim-snippets.nix @@ -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 = ""; + action.__raw = '' + function() + if vim.snippet.active({ direction = 1 }) then + vim.schedule(function() + vim.snippet.jump(1) + end) + return + end + return "" + end + ''; + options = { + expr = true; + silent = true; + }; + } + { + mode = "s"; + key = ""; + action.__raw = '' + function() + vim.schedule(function() + vim.snippet.jump(1) + end) + end + ''; + options = { + expr = true; + silent = true; + }; + } + { + mode = [ + "i" + "s" + ]; + key = ""; + action.__raw = '' + function() + if vim.snippet.active({ direction = -1 }) then + vim.schedule(function() + vim.snippet.jump(-1) + end) + return + end + return "" + end + ''; + options = { + expr = true; + silent = true; + }; + } + ]; + }; +}