Create multiline string snippet #913
-
Hello! I'd like to create a snippet which basically inserts the following content: {
name = "Some Task",
builder = function(params)
return {
cmd = { "echo" },
args = { "hello", "world" },
name = "Greet",
cwd = "/tmp",
env = {
VAR = "FOO",
},
components = { "my_custom_component", "default" },
metadata = {
foo = "bar",
},
}
end,
desc = "Optional description of task",
tags = { overseer.TAG.BUILD },
params = {},
priority = 50,
condition = {
filetype = { "c", "cpp" },
dir = "/home/user/my_project",
callback = function(search)
print(vim.inspect(search))
return true
end,
},
} currently my snipped file looks like this: local ls = require("luasnip")
local s = ls.snippet
local sn = ls.snippet_node
local isn = ls.indent_snippet_node
local t = ls.text_node
local i = ls.insert_node
local f = ls.function_node
local c = ls.choice_node
local d = ls.dynamic_node
local r = ls.restore_node
local events = require("luasnip.util.events")
local ai = require("luasnip.nodes.absolute_indexer")
return {
s("overseer_template", {
t([[
{
name = "Some Task",
builder = function(params)
return {
cmd = { "echo" },
args = { "hello", "world" },
name = "Greet",
cwd = "/tmp",
env = {
VAR = "FOO",
},
components = { "my_custom_component", "default" },
metadata = {
foo = "bar",
},
}
end,
desc = "Optional description of task",
tags = { overseer.TAG.BUILD },
params = {},
priority = 50,
condition = {
filetype = { "c", "cpp" },
dir = "/home/user/my_project",
callback = function(search)
print(vim.inspect(search))
return true
end,
},
}
]]),
}),
} but I'm getting the following error message if I'm expanding the E5108: Error executing lua ....local/share/nvim/lazy/LuaSnip/lua/luasnip/util/util.lua:230: 'replacement string' item contains newlines
stack traceback:
[C]: in function 'nvim_buf_set_text'
....local/share/nvim/lazy/LuaSnip/lua/luasnip/util/util.lua:230: in function 'put'
...local/share/nvim/lazy/LuaSnip/lua/luasnip/nodes/node.lua:69: in function 'put_initial'
...al/share/nvim/lazy/LuaSnip/lua/luasnip/nodes/snippet.lua:689: in function 'put_initial'
...al/share/nvim/lazy/LuaSnip/lua/luasnip/nodes/snippet.lua:561: in function 'trigger_expand'
...rnax/.local/share/nvim/lazy/LuaSnip/lua/luasnip/init.lua:243: in function 'snip_expand'
...cal/share/nvim/lazy/cmp_luasnip/lua/cmp_luasnip/init.lua:143: in function 'execute'
...ornax/.local/share/nvim/lazy/nvim-cmp/lua/cmp/source.lua:393: in function 'execute'
...tornax/.local/share/nvim/lazy/nvim-cmp/lua/cmp/entry.lua:486: in function 'execute'
.../tornax/.local/share/nvim/lazy/nvim-cmp/lua/cmp/core.lua:486: in function <.../tornax/.local/share/nvim/lazy/nvim-cmp/lua/cmp/core.lua:485>
...ocal/share/nvim/lazy/nvim-cmp/lua/cmp/utils/feedkeys.lua:47: in function <...ocal/share/nvim/lazy/nvim-cmp/lua/cmp/utils/feedkeys.lua:45> does anyone have an idea how I can fix this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Mutilinetext in text-nodes is not supported (at least not that way). The strings being passed to a text-node must not contain newlines. You can pass a table of strings (without newlines) tough, between the table-elements newlines will be created. You could (the possibilities that came to my mind)
|
Beta Was this translation helpful? Give feedback.
Mutilinetext in text-nodes is not supported (at least not that way). The strings being passed to a text-node must not contain newlines. You can pass a table of strings (without newlines) tough, between the table-elements newlines will be created.
(I guess the reason is how it works to indent all inserted lines the right amount of times)
You could (the possibilities that came to my mind)
t({"line1", "line2"})
fmt
featurestring.gmatch
with a pattern like([^\n])\n
(didn't test it) might be useful) and then pass the table to the text-node