LuaSnip
LuaSnip copied to clipboard
Errors with rust-analyzer provided snippets
Expansion of rust-analyzer provided snippets like ~pd or ~ppd which is just a eprintln!("$0 = {:#?}", $0);
gives me this errors:
"E5108: Error executing lua ...site/pack/packer/start/LuaSnip/lua/luasnip/util/util.lua:62: bad argument #1 to 'ipairs' (table expected, got nil)
stack traceback:
[C]: in function 'ipairs'
...site/pack/packer/start/LuaSnip/lua/luasnip/util/util.lua:62: in function 'expand_tabs'
.../packer/start/LuaSnip/lua/luasnip/nodes/functionNode.lua:48: in function 'update'
.../pack/packer/start/LuaSnip/lua/luasnip/nodes/snippet.lua:761: in function 'update'
.../pack/packer/start/LuaSnip/lua/luasnip/nodes/snippet.lua:440: in function 'trigger_expand'
...nvim/site/pack/packer/start/LuaSnip/lua/luasnip/init.lua:169: in function 'snip_expand'
...nvim/site/pack/packer/start/LuaSnip/lua/luasnip/init.lua:299: in function 'lsp_expand'
/home/zapp/.config/nvim/lua/config/nvim-cmp.lua:5: in function 'expand'
...re/nvim/site/pack/packer/start/nvim-cmp/lua/cmp/core.lua:455: in function <...re/nvim/site/pack/packer/start/nvim-cmp/lua/cmp/core.lua:416>
...te/pack/packer/start/nvim-cmp/lua/cmp/utils/feedkeys.lua:51: in function <...te/pack/packer/start/nvim-cmp/lua/cmp/utils/feedkeys.lua:49>"
I assume, that the problem with $0 placeholder, because manual command :lua require'luasnip'.lsp_expand('eprintln!("$1 = {:#?}", $1);', {})
works as it should.
Yup, passing the i(0)
to functionNodes
(which is happening here, it's just hidden behind the parser) isn't supported :/
One quick solution, although it's not the best, would be to expand an equivalent, working snippet instead of the broken one in nvim-cmps snippet-expand-callback.
Or more generally, detect when $0
is mirrored, and switch both to $<highest placeholder+1>
@L3MON4D3 I will blame vscode and lsp for having such an unclear specification for the snippets. Does that work in vscode? The specification says $0 is where the cursor stops, which place should be that in this situation if there are two?
I think it does, I'd be very surprised if any of those snippets don't work in vscode. I guess it could be justified with "if there are two tabstops the cursor jumps to the first and the second contains a copy", but yeah, that's a bit of a stretch.
We could add a function that checks for some of these cases luasnip can't handle and "fixes" them automatically.
So something like eprintln!("$0 = {:#?}", $0);
is actually our eprintln!("$1$0 = {:#?}", $1);
?
Yep, that should work I think
From now on, these invalid $0
are replaced by $0$1
(in this case at least)