Skip to content
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

Closed
jrieken opened this issue Sep 20, 2017 · 24 comments · Fixed by #51621
Closed

Snippet transformations for placeholders #34683

jrieken opened this issue Sep 20, 2017 · 24 comments · Fixed by #51621
Assignees
Labels
feature-request Request for new features or functionality on-testplan snippets
Milestone

Comments

@jrieken
Copy link
Member

jrieken commented Sep 20, 2017

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.

@jrieken jrieken self-assigned this Sep 20, 2017
@vscodebot vscodebot bot added the editor label Sep 20, 2017
@jrieken jrieken added feature-request Request for new features or functionality snippets and removed editor labels Sep 20, 2017
@alexdima alexdima added this to the Backlog milestone Sep 20, 2017
@alexdima alexdima removed their assignment Sep 20, 2017
@peabnuts123
Copy link

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:

task${1/(.*)/capitalize}: task(function* {1:doSomething}(model) {
  // do async things
  $0
})

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.

@jose-mdz
Copy link

I also fully support and want this. This only feature is preventing my hole company to switch to vs code.

@godbout
Copy link

godbout commented Oct 26, 2017

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

@kizu
Copy link

kizu commented Dec 19, 2017

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.

@IllNate
Copy link

IllNate commented Jan 11, 2018

Yes please. Just spent an hour trying to get this to work for my enum snippet, should have checked here sooner.

@joebelladonna
Copy link

joebelladonna commented Jan 28, 2018

Are there any news on this issue? This would be great addon for VS Code.

@timwis
Copy link

timwis commented Feb 1, 2018

If it helps to have another concrete example, I'd like to use this to add the filename as a title to my .md documents. So when I create a new file called weekend_notes.md the first line will be # Weekend notes. Not sure I can accomplish this without the ability to replace _ with a space.

@KhalilMohammad
Copy link

Any updates on this issue. This is real blocker for my company

@KhalilMohammad
Copy link

I need camel casing and pascal casing feature included in the scope of this issue.

@moranje
Copy link

moranje commented Apr 8, 2018

Is there anyway I can upvote the importance of implementing this feature?

@xsburg
Copy link

xsburg commented Apr 8, 2018

While we are all waiting for this feature very much, I ended up with a temporary solution which is to use TM_SELECTED_TEXT when I need only one variable in a snippet to be transformed. It's limited and less convenient but solves cases like 'Redux action creator + constant' good enough.

@menendezau
Copy link

Should we open a change.org letter so they hear us?

@rrousselGit
Copy link

That's an open source project. If you really need it, feel free to contribute 😄

@asbjornh
Copy link

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.

@go2sh
Copy link
Contributor

go2sh commented Jun 11, 2018

#51621

@jrieken jrieken modified the milestones: Backlog, June 2018 Jun 20, 2018
@jrieken
Copy link
Member Author

jrieken commented Jun 20, 2018

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.

jun-20-2018 11-38-31

"Emitter/Event": {
	"prefix": "emitter",
	"body": [
		"private readonly ${1} = new Emitter<$2>();",
		"readonly ${1/^_(.*)/$1/}: Event<$2> = this.$1.event;",
		"$0"
	]
}

@kizu
Copy link

kizu commented Jun 20, 2018

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!

@go2sh
Copy link
Contributor

go2sh commented Jun 20, 2018

@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. :-/

@kizu
Copy link

kizu commented Jun 20, 2018

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

@stijnvanderlaan
Copy link

stijnvanderlaan commented Jul 5, 2018

I just installed version 1.25.0 an tried the example snippet:

"HelloWorld": {
	"prefix": "say_hello",
	"body": "${1} ${2} -> ${1/Hello/Hallo/} ${2/World/Welt/}"
}

It results into:

Hello World  -> Hello World 

Am I doing something wrong?

@jrieken
Copy link
Member Author

jrieken commented Jul 6, 2018

@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

@stijnvanderlaan
Copy link

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.

@jrieken
Copy link
Member Author

jrieken commented Jul 6, 2018

I was expecting a direct transformation

Yeah, that'll be nice but a lot harder to implement...

@beausmith
Copy link

beausmith commented Jul 10, 2018

edit: moved question to the PR: #51621 (comment)

@vscodebot vscodebot bot locked and limited conversation to collaborators Aug 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality on-testplan snippets
Projects
None yet
Development

Successfully merging a pull request may close this issue.