LuaSnip
LuaSnip copied to clipboard
vs code transform error
this snippet is OK
"aa": {
"prefix": "aa",
"body": "$1 (${1/(.*)/${1:/upcase}/}) $0"
},
=> john (JOHN)
But :
"bb": {
"prefix": "bb",
"body": "(${1/(.*)/${1:/upcase}/}) $0"
},
=> (john)
why is it mandatory to have $1 for the transformation to work
In vscodium, it works
Oh, I assumed that the transform requires a placeholder to copy from. How does vscodium behave with the second example?
with the second example, vs codium does the transformation
(JOHN)
Oh, so it generates a placeholder, you type into it, and when you leave the transformation is applied?
Oh, so it generates a placeholder, you type into it, and when you leave the transformation is applied?
yes
with : update_events = 'TextChanged,TextChangedI'
and width this snippet :
"aa": {
"prefix": "aa",
"body": "$1 (${1/(.*)/${1:/upcase}/}) $0"
},
when i type :
a => a (A)
ab => ab (AB)
the transformation is dynamic
yes
Ouh, that's a bit of an issue, it doesn't really fit into the dynamicNode-model which currently takes care of doing these transformations.
Still, it should be possible to implement this (external_update_dynamic_node can handle it), but it won't happen soon since it's a pretty big change AFAICT
I understand
Is there anything I can do to make this happen? Where should I start?
Hey!
I think the best way to implement this would be to look into lua/luasnip/util/parser/ast_parser.lua, it has the bulk of the functions responsible for transforming a vscode-snippet-ast into a luasnip-snippet.
Not completely sure if the ast even identifies these constructs correctly, if not, you'll have to also dive into neovim_parser.lua in that same directory.
Sorry for this being not too helpful, I'd have to completely refamiliarize myself with that code as well to find a good way to implement this feature, for which I don't have time right now :/ However, if these help, a PR would be very welcome of course :)
@tofulm why it cannot transform upcase , after i add the following snippet in global.json of friendly-snippets. "aa": { "prefix": "aa", "body": "$1 (${1/(.*)/${1:/upcase}/}) $0" }, => john (john)
@hawkinchina
aa": { "prefix": "aa", "body": "$1 (${1/(.*)/${1:/upcase}/}) $0" },
it's ok => john (JOHN)
But
bb": { "prefix": "bb", "body": " (${1/(.*)/${1:/upcase}/}) $0" },
=> (john) and not (JOHN)
With Ultisnips :
snippet aa "(JOHN)"
`!p t[1] = t[1].upper() `(${1})${0}`
endsnippet