0

I am trying to create a snippet that changes based on the optional lua pattern input, but I am getting an error about a local tmp for the dynamic node. The desired outcome for typing $cup$ is $\cup$ while for $bcup$, $\bigcup_{<>}^{<>} and I get this error when typing $cup$ or $bcup$. My indexing for the dynamic node seems fine. Any clarification on how to fix this, or why I get this for the dynamic node and not the function node would be appreciated.

Snippet:

return{

s({trig = '([b]?)cup', wordTrig = false, regTrig = true, snippetType = 'autosnippet'},  
     fmta("\\\\<>cup<>",  
          {  
               f(function(\_, snip)  
                    if snip.captures\[1] == 'b' then  
                         return 'big'  
                    end  
               end),  
               d(1, function(\_, snip)  
                    if snip.captures\[1] == 'b' then  
                         return sn(nil, { t("_{"), i(1), t("}^{"), i(2), t("}") })  
                    end  
               end),  
          }  
     )   
),
  
}

Error Message:

Error detected while processing TextChangedI Autocommands for "*":                                            
Error executing lua callback: ...hare/nvim/lazy/LuaSnip/lua/luasnip/nodes/dynamicNode.lua:154: attempt to index local 'tmp' (a nil value) 

enter image description here

3

1 Answer 1

0

Apparently, the answer was that function nodes and dynamic nodes had to return a string and snippetnode, so the revised code that works is

return{

s({trig = '([b]?)cup', wordTrig = false, regTrig = true, snippetType = 'autosnippet'},  
     fmta("\\\\<>cup<>",  
          {  
               f(function(\_, snip)  
                    if snip.captures\[1] == 'b' then  
                         return 'big'  
                    else
                         return ''
                    end  
               end),  
               d(1, function(\_, snip)  
                    if snip.captures\[1] == 'b' then  
                         return sn(nil, { t("_{"), i(1), t("}^{"), i(2), t("}") })  
                    else  
                         return sn(nil, {})
                    end  
               end),  
          }  
     )   
),
  
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.