[Suggestion] extending "Live Template" by "follow-up-template"s targetting other lines/files
Hello.
First of congratulation on a great product. I have been using Rider for C# / ASP.NET MVC development for over a year and cannot imagine existing without it. Exalting to work with a tool that appreciates what makes this whole programming business a worthwhile experience.
I have been struggling with this idea for a while and wondered how others would feel about it so maybe we will find out.
====================
=== Live Template - Current state of usage
Live Template allows us to minimize the amount of typing, by separating the boiler-plate code into parts that stay the same vs. those that change - using the arbitrary amount of $var0$, $var1$ e.g. all-time classic:
public $TYPE$ $NAME$ { get; set; }
If you are un-aware of how you can set up your own, heartily recommend you give the documentation a read
https://www.jetbrains.com/help/idea/using-live-templates.html
More coding less typing is the motto.
==============================
=== The suggestion: follow-up-templates
Ok, so having just applied-triggered a specific Live Template, we know the values of $var$s and could now use these inside 1..N follow-up-templates.
Well what is this "follow-up-template" anyway :
(A) defines a file+line~place where they need to go
- note a tiny annoyance with line number is when several follow-ups would target the same file - so maybe use https://www.jetbrains.com/help/rider/Bookmarks.html#toggle-bookmarks
(B) defines what is to be printed
- using the same rules as any regular live template (while reusing the triggered-live-template values) within a different context
Another way to look at this is that you would extend the current live template definition with two more properties (as (B) is implicit), so new ones would be (A) as stated above and (C) would allow us to set the one single optional other "trigger-parent-template".
================================
=== Odd scenario to illustrate the use case
I am writing HTML and creating an element that needs id attribute - which the javascript will eventually need to know - and I also want to use Razor-View-C# variable to keep this programming-language-goo together.
First trigger the very simple live template, as usualy
@$PROPNAME$
starring at HTML such as: <div id="**here the live template triggers**">
Then the follow-up-templates (I->IV) configured beforehand - once for the sole purpose of developing this page.
(I) propagate the variable name to C# const [in current .cshtml]
const string $PROPNAME$ = nameof($PROPNAME$);
(II) define external javascript variable that will hold the - re-factorable name [in some .js file]
let $PROPNAME$ = "";
(III) pass assing its content by Razor inside <script> tag [in current .cshtml]
let $PROPNAME$ = "@$PROPNAME$";
(IV) and might as well capture the jQuery object that I want at some point [in some .js file]
let el$PROPNAME$ = $($PROPNAME$);
So notice that a is a considerable amount of boiler-plate-code derived from just one $PROPNAME$ input on my part, and there will be maybe 10 maybe 50, of these elements ... so the time spent setting up follow-up-templates will pay up eventually - and even more effectively in future, because one only needs to set (A) part of the follow-up-template because (B) will likely stay the same.
It means I can keep my attention focused on developing the spot of HTML which is currently important, not having to run - at minimum to point (I) from which I need the Razor const.
It also allows me to keep name-relations clearer over the boundary of different programming languages - where otherwise all-mighty code completion cannot sadly help me.
===============
So now try to abstract from what you just saw, I think that usage for this feature can be actually pretty broad.
From where I stand - seeing how live templates work already, and what was achieved with your SW generally, this would seem easy to add, most demanding prehaps is how convinient UI-wise the definition of (A) should be - but even the most rudimentary case of absolute file path + line number would work miracles as far as I am concerned.
Except for the obvious question of how much of a fringe usage this would be. Is it not often the case you do not know what you like until you give it a try?
So please if you think this is even marginally useful, VOTE this up :).
Sorry for the long post, keep up the good work.
Please sign in to leave a comment.