LuaSnip
LuaSnip copied to clipboard
Allow self-dependent dynamicNode
Deal with/Explicitly allow dynamicNodes being updated due to a change inside of them. This is to enable stuff like #1096 and #1102, where the text of an insertNode should be updated while typing.
One important limitation this has (for now??) is that the updates have to reach some equilibrium (text is unchanged after a second update), otherwise we just keep updating.
One example:
ls.setup_snip_env()
local opt_arg = require("luasnip.nodes.optional_arg").new_opt
ls.add_snippets("all", {
s("test", {
t":",
d(1, function(args)
if args[1] == nil then
return sn(nil, { i(1, "fff", {key = "asd"}) })
else
for i, str in ipairs(args[1]) do
args[1][i] = str:lower()
end
return sn(nil, { i(1, args[1], {key = "asd"}) })
end
end, { opt_arg(k("asd")) }),
t":"
})
}, {key = "qwe"})
Note the other new addition, opt_arg (optional argnodes, we currently don't run the dynamicNode-function if an argnode is missing), for allowing the initial creation of the sn when the "asd"-node does not yet exist.
This is missing tests and doc for now, and I'm not certain it handles all cases correctly, but I'd like to show this since I think it should work for simple ones.