-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
Snippet transformations for placeholders #34683
Comments
Fully support and want this. Here is an example use case: I generally call my async task objects in JS "taskDoThing" and the generator assigned to them "doThing" e.g. taskMyThing: task(function* myThing(model) {
// do things with model
}) and so I would ideally like to write a snippet like the following:
or something, in order to ease this process. For what it's worth I personally don't know if it's necessary to physically have a cursor in two places just in order to put the value in two places at the same time, seems kind of like a workaround solution / different than what you are "semantically" doing. |
I also fully support and want this. This only feature is preventing my hole company to switch to vs code. |
Struggling with this too to write Test methods using snake_case, with method name coming from the description I type in the docblock (able to to it in Sublime). |
This is a really crucial feature of TM snippet syntax and its really, really sad that it is not yet supported, as I have used it extensively both in TextMate and in Sublime Text. I'm in a process of implementing my Hayaku package from ST (https://github.com/hayaku/hayaku, you can see those snippets with transformations which I generate for it in action here: https://youtu.be/Nipi67jYHxo?t=30s, starting from 0:30s), and without this snippets feature my reimplementation would never be complete I'm afraid. If thinking about how that should be implemented: I think that whenever the transformations would be used for the mirrored snippets, those shouldn't become full-fledged cursors and should be just an inserted text. This way there shouldn't be any problems with multi-cursors, and, anyway, whenever you look at how those transformations are used, you won't expect them to work as cursors. And I think ST already does it this way? So when the mirrored tabstop is used as-is, it is a cursor, whenever there is a transformation, it loses its cursor status and becomes a dynamic inserted text. |
Yes please. Just spent an hour trying to get this to work for my enum snippet, should have checked here sooner. |
Are there any news on this issue? This would be great addon for VS Code. |
If it helps to have another concrete example, I'd like to use this to add the filename as a title to my |
Any updates on this issue. This is real blocker for my company |
I need camel casing and pascal casing feature included in the scope of this issue. |
Is there anyway I can upvote the importance of implementing this feature? |
While we are all waiting for this feature very much, I ended up with a temporary solution which is to use |
Should we open a change.org letter so they hear us? |
That's an open source project. If you really need it, feel free to contribute 😄 |
Thought I'd take you up on that. Gotta say tho, the codebase is quite intimidating for an outsider. I was able, though, to figure out that snippets are only parsed once (when they're highlighted in the little suggestion popup). As far as I can tell the parser should already be able to handle placeholder transforms once the placeholders have been replaced with a value, so I'm guessing what you'd have to do is to make the application parse the selected snippet for every keystroke. Upon realizing this I gave up and started dreaming about moving to the countryside and living off the land. |
We are planning this for June! Thanks to @go2sh 👏 🎉 ! Placeholder transformations will be applied when going to the next/final placeholder (not while typing). This is how it looks. "Emitter/Event": {
"prefix": "emitter",
"body": [
"private readonly ${1} = new Emitter<$2>();",
"readonly ${1/^_(.*)/$1/}: Event<$2> = this.$1.event;",
"$0"
]
} |
This is very nice, I just hope you would think about making it possible to achieve this in real time somewhere in the future, as instant feedback can be very important, and for a lot of cases the afterward transformation would be almost useless, sadly. Still, nice work! |
@kizu This is not so easy with the current design. Since multipart snippets have multiple cursor, you have to overwrite the value from the cursor over and over again. Also, the snippet controller isn't called until you press tab again. So, there is also no easy hook for a live update. :-/ |
@go2sh Yes, I understand that in current design it can be close to impossible to implement properly, so what I'm saying — this should be changed in the engine, so any cursor with a transformation wouldn't be actually a cursor, but would just have some conditional content inserted at its place with a “cursory” visuals. |
I just installed version 1.25.0 an tried the example snippet:
It results into:
Am I doing something wrong? |
@stijnvanderlaan Thanks for letting us know. The problem is a conflict between quick suggestions (completions as type) and placeholder navigation, both controlled via tab. We had given tab higher priority when snippet mode is active but had to revert it late in the endgame. See #50776 (comment). We are working on this for July (and open for suggestions) For placeholder transform: For now, when the intellisense widget shows hit esc to cancel it, then tab will do the right thing |
Ahh, I think I know the problem, it only transforms once you hit tab. It does not transform when you type or exit in another way by clicking somewhere, I was expecting a direct transformation. |
Yeah, that'll be nice but a lot harder to implement... |
edit: moved question to the PR: #51621 (comment) |
This is a follow up item for #6920 which implemented snippet transformation for variables. This issue tracks the remainder which is transforms for placeholders. Unfortunately they are much harder to implement, as today snippet controller uses multi-cursor-math for insertion and multi-cursors are defined to always insert the same text everywhere.
The text was updated successfully, but these errors were encountered: