Delta Engine Blog

AI, Robotics, multiplatform game development and Strict programming language

RegionAddin to fix collapsing and expanding regions in Orcas and IronPython region support!

I've been working with VS Orcas for 3-4 months now and while most projects are still in C#, I switch over to IronPython more and more, especially if I do anything new like some Silverlight website.

CodeRush is working ok in VS Orcas, but there are still some issues, for example expanding/collapsing regions like in my CR_Commenter plugin does not work at all. Visual Studio's Ctlr+M+M and Ctlr+M+L work, but they are pretty much useless because they either collapse just the most inner region (Ctrl+M+M) or just too much (Ctlr+M+L) and pressing these hotkeys is too complicated anyway.

With CR_Commenter you can press Ctrl+4 to collapse or expand the region you are in or Ctrl+5 to collapse/expand all regions (but not summaries, methods, etc.). This works fine in VS 2005, but not in Orcas, there are also some other issues in Orcas like switch or namespace blocks are not commented anymore. For this reason I started writing a new addin (without using CodeRush this time) last month, but I never found time to finish it.

Instead I wrote a new addin this weekend. It just fixes the region issue and adds support for IronPython, which does not have any regions at all. Now regions for all classes, defs (methods) and if blocks are generated for you and can be expanded and collapsed with the same hotkeys (Ctrl+4, Ctrl+5 or the VS defaults). Please note that I had commenter support for IronPython too and added stuff like #region and #endregion to it too, but it does not feel like Python anymore if you add too much comments and blocks. The beauty of Python is its short and self-explaining code and the more I work with it the more I like it.

RegionAddin Hotkeys:
  • Ctrl+1, Ctrl+2: Comment code like CR_Commenter (not implemented yet, it is commented out, too much features from CR_Commenter missing).
  • Ctrl+3: Build region like CodeRush or CR_Commenter, also commented out, CodeRush's version currently does work much better, but adds comments to #endregion
  • Ctrl+4: Collapse or expand the current region you are in
  • Ctrl+5: Collapse or expand all regions in the current file. In IronPython it has 3 modes: All uncollapsed, All methods collapsed, All classes and methods collapsed
  • Ctrl+6: Regenerate all collapsable blocks in IronPython, this is important because the IronPython language service does not support any collapseable blocks, maybe I will implement that later in there ...

Lets take a look at the region feature of RegionAddin for IronPython, Ctrl+6 generate all regions at once, otherwise regions are created automatically as you write code.

As always here is the full SourceCode and a Installer:
This is version 1, I will improve the addin in the future and provide better versions with more features in the future. Maybe I will also finish the CommenterAddin completely and add more support for IronPython (have to think about how it makes sense). Hopefully the RegionAddin is useful for C# and IronPython right now, it also supports all other C style languages like C++.