diff --git a/lua/lazyvim/plugins/coding.lua b/lua/lazyvim/plugins/coding.lua index a917cbc4..3280f957 100644 --- a/lua/lazyvim/plugins/coding.lua +++ b/lua/lazyvim/plugins/coding.lua @@ -96,50 +96,65 @@ return { }, -- snippets - { - "L3MON4D3/LuaSnip", - build = (not LazyVim.is_win()) - and "echo 'NOTE: jsregexp is optional, so not a big deal if it fails to build'; make install_jsregexp" - or nil, - dependencies = { - { - "rafamadriz/friendly-snippets", - config = function() - require("luasnip.loaders.from_vscode").lazy_load() - end, - }, - { + vim.snippet + and { "nvim-cmp", dependencies = { - "saadparwaiz1/cmp_luasnip", + { "rafamadriz/friendly-snippets" }, + { "garymjr/nvim-snippets", opts = { friendly_snippets = true } }, }, opts = function(_, opts) opts.snippet = { expand = function(args) - require("luasnip").lsp_expand(args.body) + vim.snippet.expand(args.body) end, } - table.insert(opts.sources, { name = "luasnip" }) + table.insert(opts.sources, { name = "snippets" }) end, - }, - }, - opts = { - history = true, - delete_check_events = "TextChanged", - }, - -- stylua: ignore - keys = { - { - "", - function() - return require("luasnip").jumpable(1) and "luasnip-jump-next" or "" - end, - expr = true, silent = true, mode = "i", - }, - { "", function() require("luasnip").jump(1) end, mode = "s" }, - { "", function() require("luasnip").jump(-1) end, mode = { "i", "s" } }, - }, - }, + keys = { + { + "", + function() + if vim.snippet.active({ direction = 1 }) then + vim.schedule(function() + vim.snippet.jump(1) + end) + return + end + return "" + end, + expr = true, + silent = true, + mode = "i", + }, + { + "", + function() + vim.schedule(function() + vim.snippet.jump(1) + end) + end, + silent = true, + mode = "s", + }, + { + "", + function() + if vim.snippet.active({ direction = -1 }) then + vim.schedule(function() + vim.snippet.jump(-1) + end) + return + end + return "" + end, + expr = true, + silent = true, + mode = { "i", "s" }, + }, + }, + } + or { import = "lazyvim.plugins.extras.coding.luasnip", enabled = vim.fn.has("nvim-0.10") == 0 }, -- auto pairs { diff --git a/lua/lazyvim/plugins/extras/coding/luasnip.lua b/lua/lazyvim/plugins/extras/coding/luasnip.lua new file mode 100644 index 00000000..3a12f9db --- /dev/null +++ b/lua/lazyvim/plugins/extras/coding/luasnip.lua @@ -0,0 +1,44 @@ +return { + "L3MON4D3/LuaSnip", + build = (not LazyVim.is_win()) + and "echo 'NOTE: jsregexp is optional, so not a big deal if it fails to build'; make install_jsregexp" + or nil, + dependencies = { + { + "rafamadriz/friendly-snippets", + config = function() + require("luasnip.loaders.from_vscode").lazy_load() + end, + }, + { + "nvim-cmp", + dependencies = { + "saadparwaiz1/cmp_luasnip", + }, + opts = function(_, opts) + opts.snippet = { + expand = function(args) + require("luasnip").lsp_expand(args.body) + end, + } + table.insert(opts.sources, { name = "luasnip" }) + end, + }, + }, + opts = { + history = true, + delete_check_events = "TextChanged", + }, + -- stylua: ignore + keys = { + { + "", + function() + return require("luasnip").jumpable(1) and "luasnip-jump-next" or "" + end, + expr = true, silent = true, mode = "i", + }, + { "", function() require("luasnip").jump(1) end, mode = "s" }, + { "", function() require("luasnip").jump(-1) end, mode = { "i", "s" } }, + }, +} diff --git a/lua/lazyvim/plugins/extras/coding/native_snippets.lua b/lua/lazyvim/plugins/extras/coding/native_snippets.lua deleted file mode 100644 index e94d40ad..00000000 --- a/lua/lazyvim/plugins/extras/coding/native_snippets.lua +++ /dev/null @@ -1,69 +0,0 @@ -if not vim.snippet then - LazyVim.warn("Native snippets are only supported on Neovim >= 0.10.0") - return {} -end - -return { - desc = "Use native snippets instead of LuaSnip. Only works on Neovim >= 0.10!", - { - "L3MON4D3/LuaSnip", - enabled = false, - }, - { - "nvim-cmp", - dependencies = { - { "rafamadriz/friendly-snippets" }, - { "garymjr/nvim-snippets", opts = { friendly_snippets = true } }, - }, - opts = function(_, opts) - opts.snippet = { - expand = function(args) - vim.snippet.expand(args.body) - end, - } - table.insert(opts.sources, { name = "snippets" }) - end, - keys = { - { - "", - function() - if vim.snippet.active({ direction = 1 }) then - vim.schedule(function() - vim.snippet.jump(1) - end) - return - end - return "" - end, - expr = true, - silent = true, - mode = "i", - }, - { - "", - function() - vim.schedule(function() - vim.snippet.jump(1) - end) - end, - silent = true, - mode = "s", - }, - { - "", - function() - if vim.snippet.active({ direction = -1 }) then - vim.schedule(function() - vim.snippet.jump(-1) - end) - return - end - return "" - end, - expr = true, - silent = true, - mode = { "i", "s" }, - }, - }, - }, -} diff --git a/lua/lazyvim/util/plugin.lua b/lua/lazyvim/util/plugin.lua index 3e90a767..ad13247a 100644 --- a/lua/lazyvim/util/plugin.lua +++ b/lua/lazyvim/util/plugin.lua @@ -10,6 +10,7 @@ M.deprecated_extras = { ["lazyvim.plugins.extras.formatting.conform"] = "`conform.nvim` is now the default **LazyVim** formatter.", ["lazyvim.plugins.extras.linting.nvim-lint"] = "`nvim-lint` is now the default **LazyVim** linter.", ["lazyvim.plugins.extras.ui.dashboard"] = "`dashboard.nvim` is now the default **LazyVim** starter.", + ["lazyvim.plugins.extras.coding.native_snippets"] = "Native snippets are now the default for **Neovim >= 0.10**", } M.deprecated_modules = { @@ -91,7 +92,7 @@ function M.fix_imports() Plugin.Spec.import = LazyVim.inject.args(Plugin.Spec.import, function(_, spec) local dep = M.deprecated_extras[spec and spec.import] if dep then - dep = dep .. "\n" .. "Please remove the extra to hide this warning." + dep = dep .. "\n" .. "Please remove the extra from `lazyvim.json` to hide this warning." LazyVim.warn(dep, { title = "LazyVim", once = true, stacktrace = true, stacklevel = 6 }) return false end