-
Notifications
You must be signed in to change notification settings - Fork 30.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add transformations for placeholders #51621
Conversation
CC @jrieken |
Nice work! |
👏 looks good so far, keep going esp. with adding tests. Check out |
if (this._parseTransform(placeholder)) { | ||
parent.appendChild(placeholder); | ||
return true; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if that's actually supported by TextMate. Do you have a reference?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I know, TextMate only supports transformations for the simple case ${1/.../.../...}
. This two here would be an extension to the TextMate behavior. I agree, that the choice case might not be needed, but the nested one would be nice for default values, which covers exactly my use case. I implemented transformations for all case to have a consistent behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For Reference: http://manual.macromates.com/en/snippets#transformations
Another thing that differs from the TextMate behavior is that only the first placeholder is used for the transformation. I'll change that as well, so that every placeholder can holde it's own transformation. |
@jrieken I fixed the code and added quite some tests. I hope this is enough for merging. ;-) Now VS Code supports:
Which is a super set of the TextMate Syntax. So tm snippets work in vscode, but extended vscode snippets don't work in tm. Every placeholder has its one transformation, so you can create two different results for the same index. |
Thanks - quite busy the next few days but my hope is to squeeze this in during this week... |
Would be nice to see it in the next Update. I use this feature a lot. :-) |
Bang on. Thanks! Two small things left:
Scheduled this now for June, let's ship this. |
@jrieken Done. :) |
Thanks. |
Merged! 🍻 @go2sh |
Waiting for the VSCode PR microsoft/vscode#51621 to be released so we can use more complex snippets.
How to use I've read the docs and tried:
and
…but neither work. I don't see any tests for these transforms in this PR. I'm stumped. I posted a question here: cc @go2sh |
The integer in the EBNF docs refers to a RegExp group not to a tabstop reference so should work when typing "test": {
"prefix": "test",
"body": "${1} -> ${1/(Asdf)/${1:/upcase}/} ${1/(Asdf)/${1:/downcase}/}"
} |
In addition to #34683, it also doesn't support choice: |
Can't make |
@beausmith @moranje @csaar95 @thorn0 The vscode team removed all the advanced options as they create some regressions on existing snippets. See the docs. Only ${1/../../} is supported. Sorry for that. The removal also broke my usecase... |
The docs aren't clear about this. The Grammar section doesn't include placeholder transforms at all. At the same time, the Placeholder Transform section doesn't have any examples and doesn't mention whether transforms can be combined with default values. So it's not really clear what supposed to be supported and what is not. |
The grammar is clear. Transform is only valid for a tab-stop or a variable. The docs are not perfect. I try to make a pr. The Placeholder Transform section is from a time, where every thing was possible. |
Ah, now I see it. |
I'm trying a simple |
Was struggling with this for a while, then understood - the transformation is not applied in real time - you have to hit Tab, and then it will get applied. Funny! |
This PR adds transformations for placeholders by extending the syntax in the same way transformations are use with variables. Transformations are executed, when the user changes to the next placeholder.
I don't know if there is a better/more efficient way, but for me it works.
Fixes #34683.
TODO:
PS: My first contribution to vscode. Great editor. :)
Best Regards,
go2sh