LuaSnip
LuaSnip copied to clipboard
choiceNode not working due to ext_opt misconfiguration
(as discussed #luasnip:matrix.org)
I found myself with nonworking choiceNodes - the behaviour was rather strange, my snippet got stuck inbetween jumping into a choiceNode.
Take this snippet (which expands to a github archive source URL):
snippet('github',
fmt([[https://github.com/{}/{}/archive/{}/$name-$version.tar.gz]], {
i(1, "author"),
i(2, "project"),
c(3, {
t"$version",
t"v$version",
}),
}
)
),
You will be able to interact fine and freely (e.g. jump, edit) between the first two insertNodes, but jumping to the third node will leave you stuck, unable to jump back or out. You can not toggle between choices either.
It turned out my luasnip config contained an error and didn't notify me about it.
local ls = require 'luasnip'
ls.config.set_config {
history = true,
updateevents = 'TextChanged,TextChangedI',
enable_autosnippets = true,
ext_opts = {
[types.choiceNode] = {
active = {
virt_text = { { '<-', 'Error' } },
_text = { { 'choiceNode', 'Comment' } },
},
},
},
ext_base_prio = 300,
ext_prio_increase = 1,
ft_func = require('luasnip.extras.filetype_functions').from_cursor,
}
ext_opts in this case was misconfigured. Deleting the line starting with _text made choiceNodes work again.
Right, thatnk you :+1:
The reason the choiceNode broke is that the _text-key leads to an error from neovim, upon which we silently remove the snippet. The reasoning here is that most errors are the result of extmarks messing up, silently removing the snippet is a good option for these cases.
We should log all errormessages (or do some logging in general) so these misconfigurations become easier to find.