LuaSnip
LuaSnip copied to clipboard
Bug with snippets using `$`, as PHP ones
"for …": {
"prefix": "for",
"body": [
"for (\\$${1:i}=${2:0}; \\$$1 < $3; \\$$1++) { ",
"\t${0:# code...}",
"}"
],
"description": "For-loop"
},
- If I jump to locations without editing iterator name (by default
i) everything goes fine - If I edit iterator name (parameter
$1) extra dollars appears:
Cannot reproduce with
ls.snippets = {all={ls.parser.parse_snippet("for", "for (\\$${1:i}=${2:0}; \\$$1 < $3; \\$$1++) { \n\t${0:# code...}\n}")}}
https://user-images.githubusercontent.com/41961280/133851520-13161b5b-e059-491e-961b-69d2550a77c1.mp4
Could you try disabling other plugins/try the snippet in a buffer with another filetype until it works? (pretty likely that this is similar to #129, so mainly disable autoformatting)
Just discovered that this happens when LSP client is attached. I'm using intelephense.
You could try disabling formatting (or other features, until it works) in lspconfig.intelephense.setup{}.
I wasn't able to find such a setting and I think formatting isn't related, because code isn't formatted when I expand a snippet
With vsnip this problem disappears
I found the dotfiles of someone who also opened an issue about formatting with intelephense, maybe try their options link
The problem disappearing with vsnip is because they manually track changes done to text whereas luasnip uses extmarks. Problem is, if a region of text that contains extmarks is changed via nvims api, the extmarks are pushed to the end, even if there wasn't any (visible) change, therefore autoformatting can mess luasnip up pretty bad
I found the dotfiles of someone who also opened an issue about formatting with intelephense, maybe try their options link
I tried this config but it doesn't seem to work :cry:
Dammit :/
Could you post the output of lua Luasnip_current_nodes[vim.api.nvim_get_current_buf()].parent:dump() after changing the text in $1?
Output of lua Luasnip_current_nodes[vim.api.nvim_get_current_buf()].parent:dump() after changing the text in $1
1
false false
2 0
2 5
2
false false
2 5
2 9
3
false false
2 9
2 10
4
false true
2 10
2 11
5
true false
2 11
2 14
6
false false
2 14
2 18
7
false false
2 18
2 21
8
false false
2 21
2 21
9
false false
2 21
2 24
10
false false
2 24
2 28
11
false false
2 28
3 1
12
false false
3 1
3 10
13
false false
3 10
4 1
Yep, the problem is that the second node ($1) is in the range (2,5), (2,9), whereas it should start at (2,6) (going after the text in your first screenshots).
You could try asking around on gitter or matrix for how to disable formatting (maybe disabling it in the capabilities passed in setup could work, as a last resort)
Ok thanks, I'll investigate