A potential fix for the regex triggers
leiserfg opened this issue · 3 comments
I was thinking that a potential fix for the snippets with regexes as trigger (that most of the time misbehave) and I came up with an idea that can potentially fix it.
If the regex is capable of matching the current input, then the current input should be the item in the list.
If it does not then the input in the list could be a string derived from the pattern (I mean derive in the academic sense).
For instance:
A snippet with the regex
lorem(%d*)
For a text lorem
should return lorem
as item for the list (because the pattern matches the text).
For a text lor
should return lorem0
as item for the list (because lorem0
is a minimal string derived from the pattern).
The derivations from regexes to strings can be hard to implement, but fortunately in this case lua patterns are very simple so they should be easily derivable.
I can try implementing this over the weekend. will let you know the progress
I think a good solution to this would be to use the snippets docTrig
if it has one. That's basically the "default" text for regTrig snippets. It would be much easier than trying to generate a minimal matching string for the trigger pattern.
https://github.com/L3MON4D3/LuaSnip/blob/master/doc/luasnip.txt#L103
Just for the record, I reported this at luasnip some time ago
Related issue on LuaSnip repo: L3MON4D3/LuaSnip/issues/563