github L3MON4D3/LuaSnip v2.1.0
2.1.0

latest releases: v2.3.0, v2.2.0, v2.1.1...
12 months ago

Deprecations and Breaking Changes

Only a deprecation in this release: the history-option is superseded by the more granular keep_roots, link_roots, and link_children. Take a look at the documentation for more information on the new options.

Highlights

Snippet-insertion (#941)

Before this PR, a newly-expanded snippet was always set up such that after jumping through it, the node that was active during expansion was entered again. This was very easy to implement, but unfortunately can cause annoying issues when the active node is not close to the expanded snippet (jumping across the whole buffer).
The improved snippet-insertion prevents issues like this by linking the jumps of newly-expanded snippets not based on active node, but based on buffer-position. There is some information on it here.
The following recording shows the new behaviour, for example how snippets are traversed based on buffer-position, and how inserting snippets into a node properly activates it (visible due to orange dots indicating an active choiceNode)

1699875457.mp4

Another nice feature enabled by the datastructures that have to be maintained to allow this behaviour is that given some buffer-position (for example the cursor), we can look for the node that is located there. See this entry in the wiki for an example of this.

Treesitter-postfix (#980)

Another pretty cool feature: where previously postfix-snippets could only capture text matching some pattern, treesitter-postfix-snippets can capture text from treesitter-queries!
Since captures from the query are also made available to the snippet (via snippet.env), this may be a quick way to quickly refactor, see for example the following:

ts_post({
    matchTSNode = {
        query = [[
            (function_declaration
              name: (identifier) @fname
              parameters: (parameters) @params
              body: (block) @body
            ) @prefix
        ]],
        query_lang = "lua",
    },
    trig = ".var"
}, fmt([[
    local {} = function{}
        {}
    end
]], {
    l(l.LS_TSCAPTURE_FNAME),
    l(l.LS_TSCAPTURE_PARAMS),
    l(l.LS_TSCAPTURE_BODY),
}))


The documentation has another example, and describes the various options.

Luasnip-Luarock (#1050)

Finally, luasnip is now available as a luarock, which means it can be added by rocks.nvim.

What's Changed

New Contributors

A big Thank You! to all contributors to LuaSnip ❤️ :)

Full Changelog: v2.0.0...v2.1.0

Don't miss a new LuaSnip release

NewReleases is sending notifications on new releases.