-
Hello! This is a snippet I wanted to do for the longest time but never managed to make it work like I want... I want a snippet like I managed to get the first part of the behavior, with Hence why what I'm looking for is a kind of restore node with a dynamic default, but I really don't know how to achieve that. Am I going in the right direction? For reference, snippet definition (using my own DSL helpers)snip("lr", {desc = "local require"}, U.myfmt {
[[local <var> = require"<module>"]],
{
module = i(1, "module", {key="mod-name"}),
-- must be the 'last part of <module>' except if I set it to something else
var = ls.dynamic_node(
2,
function(given_nodes_text)
return ls.snippet_node(nil, { ls.restore_node(1, "var-name", i(nil, given_nodes_text[1])) })
end,
{node_ref"mod-name"}
)
},
}) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
Friendly ping @L3MON4D3 since it seems you're reactive on other discussions but didn't reply here, maybe you missed it? 🤔 |
Beta Was this translation helpful? Give feedback.
-
Mhmmm, I think you'd need some custom logic there, or settle for something slightly simpler:
Hope this helps :) |
Beta Was this translation helpful? Give feedback.
Mhmmm, I think you'd need some custom logic there, or settle for something slightly simpler:
mod-name
is updated, the dynamicNode is called correctly, but the restoreNode will re-use the insertNode that was generated previously => there is no dynamic component.You could circumvent this by resetting the stored text when the dynamicNode is called (we don't have api for this, but you can do
snippet.stored["var-name"] = nil
for now), but then the text you enter yourself would also be lost upon every dynamicNode update.In any case, to get this to work exactly like you want, you'd have to track whether the tex…