My luasnip only jupdates after jumping to the next placeholder

I have this snippet (mnemonic for smart require)

The bellow solution is based on Tjdevris youtube video:

local ls = require "luasnip"
local fmt = require("luasnip.extras.fmt").fmt
local fmta = require("luasnip.extras.fmt").fmta
local rep = require("luasnip.extras").rep
local dl = require'luasnip.extras'.dynamic_lambda
local l = require'luasnip.extras'.lambda

-- some shorthands...
local snip = ls.snippet
local node = ls.snippet_node
local text = ls.text_node
local insert = ls.insert_node
local func = ls.function_node
local choice = ls.choice_node
local dynamicn = ls.dynamic_node

snip(
  "sreq",
  fmt(
    [[local {} = require "{}"]], {
      func(function(import_name)
        local parts= vim.split(import_name[1][1], ".", true)
        return parts[#parts] or ""
      end, { 1 }),
      insert(1),
    })
),

Could someone test this to see how it behaves?

I have found something related here:

I only need a decent cmp-nvim +luasnip config to solve this issue

1 Like

I figure out what was the problem:

The line:

update_events = "TextChanged", "TextChangedI", 

update_events is a table, so:

update_events = {"TextChanged", "TextChangedI"}