Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CodeRush style typed templates for ReSharper

I'm a big fan of CodeRush and their philosophy around templates. At my current job, we'll be doing a large amount of pairing and the consensus is a preference for ReSharper (v6), which pretty much puts me in a place where I MUST use it.

I'm not looking to start a CodeRush/Resharper war here. There are plenty of things to like about Resharper, but there's one thing I'm having a hard time getting past in ReSharper.

ReSharper's Live template mechanism, wile good, doesn't have built-in notions for typing the way CodeRush does (at least not as I can tell). A simple example is as follows. To gen the following code:

public String MyStringProperty { get; set; }

In CodeRush...I could type "as" ('a' for AutoProperty and 's' for string), then simply change the name of the property.

In ReSharper, I need to type "prop" (for Property), then set the type and and name.

There does not seem to be a similar notion for type awareness or type shortcuts in ReSharper's Live Templates. As such, there doesn't appear to be anything akin to the numerous two and three character templates to get you pre-typed variables, properties, methods, etc...

So, finally the question after all that background. Is there any way to replicate this notion of "typed templates" in ReSharper without creating a new live template for every template/type combination?

like image 984
Steve Brouillard Avatar asked Dec 27 '11 16:12

Steve Brouillard


1 Answers

Currently, ReSharper does not support the usage pattern you're referring to. However, there are two options I can think of to make this possible.

  • One option is to generate live templates for all common use cases. I use this file, but please note that it hasn't been tested with R#6.1.
  • Another option would be to simply write a plug-in to do this. The ReSharper SDK has a HtmlZen example that does something very similar, i.e. expand a DSL string into a piece of code. You could easily do the same for mnemonic expansion.

Note that whichever option you select, you won't get an ability to expand templates by pressing Space — this is simply not possible in ReSharper right now.

Please let me know if you have further questions.

Dmitri

like image 168
Dmitri Nesteruk Avatar answered Sep 28 '22 15:09

Dmitri Nesteruk