L3MON4D3 / LuaSnip

Snippet Engine for Neovim written in Lua.
Apache License 2.0
3.46k stars 245 forks source link

Error: Function node args from result of another dynamic node #1120

Open rathod-sahaab opened 9 months ago

rathod-sahaab commented 9 months ago

This is a minimal example to decrease verbosity.

What I actually want to do is declare variables at i(3) from the variables type in declaration of void solve(...)

cin >> a >> b;
//  to
//dynamic node -> void solve({} a, {} b) {, i(1), i(2)
void solve(int a, int b)
// to
int a;
string b;

Overview of config, I can't even get dynamic node to read from output of function node. Reading from input works

return {
  s(
    "codeforces",
    fmt(
      [[
-- ...

void solve({}) {{
  {}
}}

int main(int argc, char *argv[]) {{
    -- declare variables
    {}  
    cin >> {};
    solve({});
  }}
  -- ...
}}
]],
      {
        d(2, function(args)
          vim.print(args)
          local parts = stringz.split(args[1][1], ",")
          local nodes = {}

          for index, part in ipairs(parts) do
            table.insert(nodes, t(part .. ", "))
          end

          return sn(nil, nodes)
        end, k("solve-passed-params"), { key = "solve-args" }),
        i(0, "", { key = "solve-body" }),
        i(3),
        f(function(args)
          vim.print(args)
          local parts = stringz.split(args[1][1]:gsub("%s+", ""), ">>")
          return table.concat(parts, ", ")
        end, k("input"), { "solve-passed-params" }),
      }
    )
  ),
}
L3MON4D3 commented 8 months ago

Oh, are you just missing the key = "solve-passed-params" in f(...)?