1.2.0
Deprecations & Breaking Changes
None :)
New Features
ls_file_snippets
and ls_file_autosnippets
Up until now the snippets loaded by the lua-loader had to be returned in a big list at the end of the files. This prevents defining functions used in those snippets near them (at least if they are defined naively), and generally makes these files less readable.
Now, the tables ls_file_snippets
and ls_file_autosnippets
exposed (additionally!), and snippets can be added to them and don't have to be returned at the end of the files.
To really make use of this, adding something like
ls.setup({
snip_env = {
s = function(...)
local snip = ls.s(...)
-- we can't just access the global `ls_file_snippets`, since it will be
-- resolved in the environment of the scope in which it was defined.
table.insert(getfenv(2).ls_file_snippets, snip)
end,
parse = function(...)
local snip = ls.parser.parse_snippet(...)
table.insert(getfenv(2).ls_file_snippets, snip)
end,
-- remaining definitions.
...
},
...
})
makes s
and parse
automatically add the snippets defined with them.
edit_snippet_files
: extend
-option, by @pianocomposer321
edit_snippet_files
can be used to quickly jump to any file contributing snippets to the current file.
Before 61238b9, it was only possible to select an already-existing file, after it, it's possible to add some custom logic to extend the list of found files arbritarily.
A great application of this is the possibility of adding a new file in known snippet-collections:
-- loaded collections.
local snippet_collections = {
-- lua-snippets
{
dir = "/home/simon/.config/nvim/luasnippets",
extension = "lua"
},
-- snipmate-snippets
-- this would edit snippets provided by vim-snippets.
{
dir = "/home/simon/.local/share/nvim/site/pack/packer/start/vim-snippets/snippets/",
extension = "snippets"
}
-- vscode would be much more involved, if you figure something out, showcase
-- it in a discussion :D
}
require("luasnip.loaders").edit_snippet_files({
extend = function(ft, files)
local extend_items = {}
for _, collection in ipairs(snippet_collections) do
-- check if a file from the collection is present in the items
-- already.
for _, file in ipairs(files) do
if file:match(collection.dir) then
-- a file is in personal_dir, no need to create a new file there.
goto continue
end
end
-- not present, create item to add this file.
table.insert(extend_items, {
-- label of the new file.
"New file in " .. collection.dir,
-- location of the new file.
("%s/%s.%s"):format(collection.dir, ft, collection.extension)})
-- luajit only!!
:: continue ::
end
return extend_items
end
})
(The doc-entry contains a simpler example, and a proper definition of the option).
Repeat nodes automatically in fmt
, by @uyha
This can be used to make snippets created with fmt
more readable, by repeating nodes belonging to duplicated keys.
s("fmt", fmt([[
This {iNode} will be repeated here {iNode}
]], {
iNode = i(1)
}, {repeat_duplicates = true}))
repeat_duplicates
is false by defaults, use extend_decorator to override this default if you prefer this behaviour to failing.
pascalcase
and camelcase
for lsp-snippets
Up until now, we had not implemented these transformations. As long as jsregexp
is installed, these will behave exactly like they do in vscode.
Logging
Luasnip now has some logging in place! This is especially useful to quickly find misconfigurations with the loaders, so definitely give it a shot. Some more details in the doc.
Pretty display of available snippets, by @lyonelz96
Opens a buffer with a pretty display of all available snippets. Very configurable!
The doc contains an extensive overview of what is possible with this. So far, there is only one pretty static way to show the available snippets in a buffer, enhancing this to create a tree-like view of all snippets would be a nice extension.
New Contributors
- @pianocomposer321 made their first contribution in #502
- @Samasaur1 made their first contribution in #645
- @tomtomjhj made their first contribution in #658
- @mrzzy made their first contribution in #666
- @Andrew15-5 made their first contribution in #679
- @uyha made their first contribution in #665
- @dheimgartner made their first contribution in #683
- @lyonelz96 made their first contribution in #652
- @bootleq made their first contribution in #727
- @Prince213 made their first contribution in #734
Thanks, all of you :)
Full Changelog: v1.1.0...v1.2.0