Post-process a Live Template Variable
When writing tests, I tend to write out a short phrase in snake case for the name of the test... Is there a way to use a live template to automate the snake_case process of this? For instance, I'd like to be able to make a template like:
/** @test */
public function $NAME$()
{
$END$
}
Upon hitting tab after typing in a value such as "a guest can not access the dashboard" for the `$NAME$`, I'd like to apply a post-processor to it that takes the value and changes it to "a_guest_can_not_access_the_dashboard".
Currently, I'm accomplishing this in a very round-about way... I have the following template:
/** @test */
public function $NAME$()
{
// $NAMESRC$$END$
}
I then have `$NAME$` set to an expression of `snakeCase(NAMESRC)`, after hitting <tab> to exit the live template placeholders, I then press Ctrl + Y to delete the current line and <end> to correct the indent.
Please sign in to leave a comment.
Hello,
It is not possible to do this within a template but there's a plugin called "String Manipulation" that can convert any case or phrase to any case.
Maybe it would be suitable?
Unfortunately, that's not really any better... using that, I'd have something like: (brackets indicate active live template field)
I'd then have to do Ctrl + A (Select All), Ctrl + Alt + M (Manipulation Menu), 5 (Snake Case), Tab ($END)... I could set a hotkey for just snake case, but even then it's a longer and more tedious process than my current approach...
Would be nice to see post-scripts on live template variables...
It would be great if you could submit the detailed feature request to our tracking system here: http://youtrack.jetbrains.com/issues/IDEA#newissue=yes .
This would be a good feature to have. I couldn't find any ticket in youtrack, so I created one.
https://youtrack.jetbrains.com/issue/IDEA-243485
Existing issue that you can vote for: https://youtrack.jetbrains.com/issue/IDEABKL-6613 .