Delta Engine Blog

All about multiplatform and game development

CR_Commenter v1.8 - Autogenerate comments with this CodeRush plugin

I worked on the CR_Commenter v1.8 Update all weekend and tested it a little bit today at work. If you do not know about the CR_Commenter plugin for CodeRush yet (I originally wrote it back in 2004 and still use it every single day), please read this article of version 1.7 from 2006 or check out the original Commenter - A CodeRush plugin which helps you to comment your code article on from 2004

Here are the coolest new features in v1.8:
  • New and updated hotkeys, also made sure all of them work as advertised! You can also now switch on and off much more features and hotkeys if you like (e.g. disable Ctrl+1, Ctrl+3 or Ctrl+.). Normally the commenter will do his work every time you press '}' while coding and automatically add comments, xml blocks and the header (no need for any hotkeys during normal coding). But you can also press the following hotkeys to perform special actions:

    • Ctrl+1: Does perform the same action as closing a block with '}', but can be used anywhere inside a method or class.

    • Ctrl+2 or Ctrl+.: Adds a namespace for the current word at the cursor. Used to support automatically adding a namespace in C# 3.0 (back in v1.7), but now works the same way as VS 2008 plus saving you from pressing Enter to accept a namespace suggestion. If you like the VS2008 way better (allowing different namespaces), just disable Ctrl+. and VS will work as before.

    • Ctrl+3 or Ctrl+R: Auto generate region around the current block (method, property, constructor, etc.), for selections use Ctrl+R. You can also press Shift+Ctrl+3 to process the whole file! This feature was originally added in CodeRush v1.5, but abandoned in v1.6 and v1.7 after CodeRush supported it internally. Now the feature is back with lots of improvements, auto generating regions all over the place and producing region names for you. Can of course be disabled if you like the CodeRush way better (having to type the region name yourself).

    • Ctrl+4: Toggle collapsing and expanding current selection. This feature often caused trouble in v1.7 because it collapsed sometimes regions you were working in (e.g. method blocks with sub regions), now it will not longer disrupt your work and never close any region you are working on (except you want to with this hotkey).

    • Ctrl+5: Toggle collapsing and expanding everything at top level. Very cool to quickly check out what this file is about, use it in conjunction with first generating all region blocks (Shift+Ctrl+3).

    • Ctrl+6: Update all comments and xml blocks for the whole file. Was Ctrl+9 before and Ctrl+F9 even before that, this method is not required very often because Ctrl+1 handles most of this already. Please also note that Ctrl+7 was abondoned for now (resort language blocks and regions) because this feature is very complex and not implemented yet (see above for v2.0).

    • Ctrl+9 or Ctrl+F9: Generate all unit tests automatically for us (I use F9 to test, Ctrl+F9 makes sense to generate tests)! This will add a sub class called Tests, which contains all public methods as tests, which will all fail by default. Then all unit tests will have to be written and tested until everything is implemented correctly. Existing test methods will not be overwritten! This features is the major improvement in v1.8 for me, it will add unit tests automatically for us at the bottom of file to provide 100% code coverage (all unit tests should fail initially, add and change code to make them work).

  • Thought about auto sorting and removing namespaces for all files, but that works just fine with the new VS2008 Powertools.

  • Fixed '}' inside string or comment, even if CodeRush has not processed the whole file yet (double checking now). E.g. the following string will not longer produce any comments:
    SQL = String.Format("UPDATE GC SET Status = {0} WHERE ID = {1}", Msg, ID);

  • Added option to not update comments on } (or Ctrl+1)

  • Supporting to generate regions again, but split up function names, also suppress CodeRush region generation with Ctrl+3, Ctrl+R (also suppressing VS hotkeys now) Better support for auto generated region blocks for big methods, just press Ctrl+3 to generate region (let CR_Commenter choose the name automatically, allow editing after pressing Ctrl+3).

  • Press Shift+Ctrl+3 to generate all regions at once for the whole file! The commenter will also not longer produce regions were you already have some (even if they are different), especially if you press Ctrl+3 multiple times you will see what I mean ^^.

  • Fixed #if DEBUG in Using directives (caused trouble, was removed)

  • Also added code to always remove #if DEBUG and #endif, especially at the beginning and end of the Using directives region

  • Fixed double line #using Using directives issue when using directives got mixed up.

  • Fixed long line commenter generation, will now still work, but not longer cut of any of your code. If you have long code lines (>100 letters), you can still generate comments for them and the Commenter will not longer cut anything off (you are responsible for formating the code).

  • Fixed auto-collapsing of regions, especially when closing blocks in methods, the method should not auto-collapse!

  • Checked support with other languages (which are at least similar to C#) like Lua, Python, etc.

  • In Python/Lua, etc. we had to disable } comment generation and also use other comments (# for python, -- for lua) when using Ctrl+1 for header generation.

  • Test all other hotkeys and make sure they do not affect the code badly in CodeRush unsupported languages (note: VB is still not supported since it is very different from c# code).

  • Supports now any unit test framework, actually does not care anymore what you use, only the unit test generation code will add Xunit, but you can easily change that code if you want to.

  • Options are now available directly into Editor tree of the CodeRush options!

  • Refactored all classes, added about 4 new classes and removed 1 unused class. The source code is now much easier to read, to follow and to change.

  • Remove commented out code, cleaned up the source code a lot.

  • And finally applied the commenter to the commenter source code :)
Some cool and highly complex ideas (like the auto refactoring and resorting of all code elements in a file) did not make it into v1.8 and will probably lay on ice for a while until I start developing CR_Commenter v2.0. But other than that I'm pretty happy with the new version and both the new region generation code and the new unit test generation code is really helpful, plus the many fixes and improvements of existing features make it more enjoyable to use CR_Commenter.

Download CR_Commenter v1.8 here (free as usual, you will need DXCore, which you can download here freely):