LuaSnip icon indicating copy to clipboard operation
LuaSnip copied to clipboard

Bug with snippets using `$`, as PHP ones

Open xeluxee opened this issue 4 years ago • 11 comments

  "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: luasnip-issue

xeluxee avatar Sep 17 '21 20:09 xeluxee

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)

L3MON4D3 avatar Sep 17 '21 20:09 L3MON4D3

Just discovered that this happens when LSP client is attached. I'm using intelephense.

xeluxee avatar Sep 18 '21 15:09 xeluxee

You could try disabling formatting (or other features, until it works) in lspconfig.intelephense.setup{}.

L3MON4D3 avatar Sep 18 '21 17:09 L3MON4D3

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

xeluxee avatar Sep 20 '21 15:09 xeluxee

I found the dotfiles of someone who also opened an issue about formatting with intelephense, maybe try their options link

L3MON4D3 avatar Sep 20 '21 17:09 L3MON4D3

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

L3MON4D3 avatar Sep 20 '21 17:09 L3MON4D3

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:

xeluxee avatar Sep 20 '21 20:09 xeluxee

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?

L3MON4D3 avatar Sep 20 '21 21:09 L3MON4D3

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

xeluxee avatar Sep 21 '21 19:09 xeluxee

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)

L3MON4D3 avatar Sep 21 '21 19:09 L3MON4D3

Ok thanks, I'll investigate

xeluxee avatar Sep 21 '21 20:09 xeluxee