LuaSnip icon indicating copy to clipboard operation
LuaSnip copied to clipboard

vs code transform error

Open tofulm opened this issue 2 years ago • 12 comments

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

tofulm avatar Jun 19 '23 10:06 tofulm

Oh, I assumed that the transform requires a placeholder to copy from. How does vscodium behave with the second example?

L3MON4D3 avatar Jun 19 '23 11:06 L3MON4D3

with the second example, vs codium does the transformation (JOHN)

tofulm avatar Jun 19 '23 11:06 tofulm

Oh, so it generates a placeholder, you type into it, and when you leave the transformation is applied?

L3MON4D3 avatar Jun 19 '23 12:06 L3MON4D3

Oh, so it generates a placeholder, you type into it, and when you leave the transformation is applied?

yes

tofulm avatar Jun 19 '23 13:06 tofulm

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

tofulm avatar Jun 19 '23 13:06 tofulm

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

L3MON4D3 avatar Jun 19 '23 13:06 L3MON4D3

I understand

tofulm avatar Jun 19 '23 13:06 tofulm

Is there anything I can do to make this happen? Where should I start?

uloco avatar Nov 06 '23 12:11 uloco

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 :)

L3MON4D3 avatar Nov 07 '23 10:11 L3MON4D3

@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 avatar Feb 01 '24 03:02 hawkinchina

@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)

tofulm avatar Feb 01 '24 10:02 tofulm

With Ultisnips :

snippet aa  "(JOHN)"
`!p t[1] = t[1].upper() `(${1})${0}`
endsnippet

tofulm avatar Feb 01 '24 10:02 tofulm