You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a snippet with a function node is expanded for the first time in a session, the function node appears to undergo a pre-evaluation phase using some placeholder variables. After this initial phase, it is reinvoked with the "correct"/expected variables. I am attempting to define a snippet as follows:
It seems that my snippet function is being called once during its initial setup. On this first invocation, snip.env.LS_SELECTED_TEXT is not of the expected type and instead holds the string "$LS_SELECTED_TEXT". I'm not entirely sure why this happens during initialization, so I handle it by returning an empty node. Is there a more appropriate way to handle this situation?
But that has the behavior of only containing the expected text the very first time the snippet is invoked, so I don't think that is what I want.
I have read :h luasnip-selection, :h luasnip-functionnode, :h luasnip-dynamicnode, I went through the examples, I watched some tutorials, and I even now know there is this fake_env function that is causing this behavior, but I do not know why it is this way and not mentioned.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
When a snippet with a function node is expanded for the first time in a session, the function node appears to undergo a pre-evaluation phase using some placeholder variables. After this initial phase, it is reinvoked with the "correct"/expected variables. I am attempting to define a snippet as follows:
It seems that my snippet function is being called once during its initial setup. On this first invocation,
snip.env.LS_SELECTED_TEXT
is not of the expected type and instead holds the string "$LS_SELECTED_TEXT". I'm not entirely sure why this happens during initialization, so I handle it by returning an empty node. Is there a more appropriate way to handle this situation?I saw #647
where the author uses:
But that has the behavior of only containing the expected text the very first time the snippet is invoked, so I don't think that is what I want.
I have read
:h luasnip-selection
,:h luasnip-functionnode
,:h luasnip-dynamicnode
, I went through the examples, I watched some tutorials, and I even now know there is thisfake_env
function that is causing this behavior, but I do not know why it is this way and not mentioned.Beta Was this translation helpful? Give feedback.
All reactions