Introduction

Code Reviewing is a must for a software project/product to maintain the code quality (indirectly the overall quality) and to share knowledge by pointing out best practices, etc. There are not lots of tools out there to help out with code reviews and not all those tools fit into organizational needs. What this tool does is that it makes it really easy to do code reviews and to address the review comments easily with less effort.

Background

Doing code reviews or addressing them by the owner of the code can be done even without using tools. It can be done even with an Excel file, where the reviewer reports his comments on an Excel file and passes it to the code owner and he addresses the comments by navigating to the code areas mentioned on the Excel file. But is this something we should do as professionals giving software solutions to others?

This process should be very much integrated with the development IDE, and neither reviewer nor the developer should have the need to switch to other unrelated applications in the code review process (unless really needed, not just to read the comments and navigate to the correct place).

So my idea was to search for an IDE plug-in to help with this, where reviews can be done totally within the IDE itself. Not being able to find such a tool exactly the way I wanted, I thought of developing one.

Using the Code

This is a plug-in for the Visual Studio IDE, so all you have to do this is deploy the plug-in and enable it, to use it. If you are not interested in the code and you would just like to try it out, all you have to do is download the "ReviewPal Add-In binaries" and copy it to the plug-in directory.

How Visual Studio plug-ins work is through the ".AddIn" files. At the startup of the VS IDE, it looks for the plug-in location usually "Visual Studio 2008" folder under current users documents folder and loads those Add-ins. These .AddIn files are just XML files, like the one below:

The important tag here is the <Assembly> which contains the DLL location for the Add-In. For usage only; this could be set to the release version of the DLL either from the same directory where .AddIn file resides or from an installation folder. If you are to develop the Add-In or for debugging, this can be directed to the debug folder of the DLL.

The starting point of a Visual Studio plug-in is the "Connect" class which implements the two interfaces "IDTExtensibility2" and "IDTCommandTarget". This class is auto generated initially when you create a project with the template "Visual Studio Add-In" under "Other project types --> Extensibility". Then the key point of change is required on the "OnConnection" method of the "Connect" class.

We gain the great power of VS extensibility here with a reference to the Visual Studio instance, which we assign as a reference object within our plug-in (visualStudioInstance variable in the code), so that we get to access the IDE and control it. And then we load the UI elements implemented as "ReviewPal.UI.ReviewWindow". Notice that we load our custom UI elements through the "windows2.CreateToolWindow2" method, which creates a window within the IDE same like other in-built Visual Studio windows like the Solution Explorer or Task List. This way we inherently gain all the behaviors of the typical VS IDE windows like docking, floating, etc.

Once we have this setup, it becomes much like developing a Windows Forms application, which means you can do anything that a windows forms application can do, interacting with the IDE as and when required. So what I have done here is, provide a list of Reviews as in a grid control and user populates it with review comments. When adding a new review comment, we can get the current IDE properties as follows through the "VisualStudioInstance" reference we assigned in the initial OnConnecttion method.

With the Plug-in enabled on Visual Studio 2008 solution, you can navigate through the source code and add review comments for the code, which will be saved into an XML document when you click save (for which I have chosen XML serialization for easy implementation). And you can pass the review comments (the saved file) to the owner of the code in whatever way is preferred (may be through SVN). Then the owner of the code needs to load the review file using the same plug-in, and he can easily navigate to the code locations to address them. The data currently gathered during a review looks like below:

One thing to note about the Solution items hierarchy in Visual Studio is as follows:

When navigating through the solution for searching location (implementation of the ReviewPal.Common.ScanForProjectItems method), first we need to iterate through the Project s in the Solution, then ProjectItems in the projects. ProjectItem could have inner ProjectItems (in case of project items having multiple items like for an ASP.NET page with three items of .aspx, .aspx.cs, designer.cs) or it could have SubProject or nothing inner. So when searching for items, it's implemented in a recursive way to handle this.

With a little effort on XSLT, the XML can be made friendly for the users without the plug-in, Example: Click here.

Points of Interest

So anyone can use this plug-in as a sample to start writing Visual Studio plug-ins. As a fan of Jetbrains Resharper, I tried developing plug-ins with Resharper, and also checked out DX Core, but both seemed to have less documentation to get it going, and at last I thought why should I rely on another third-party library to implement this type of a simple (but very useful ) plug-in.

History

v .1.0.1 ... This is the initial version and I'll be updating ... may be with your valuable comments (when I some find time)

I have added added to the Visual Studio Gallery @ <a href="http://visualstudiogallery.msdn.microsoft.com/d1e40c49-da36-42a5-8d5a-4ebe1feabbc9">http://visualstudiogallery.msdn.microsoft.com/d1e40c49-da36-42a5-8d5a-4ebe1feabbc9</a>
as well as open sourced @ <a href="http://reviewpal.codeplex.com/">http://reviewpal.codeplex.com/</a>

In Short, once u copy the build files (dll etc) to the Visual Studio Add-In folder and restart Visual Studio IDE, you'll see a Add-in called Review Pal available in Tool -> Add-in Manager. load it to use the plugin.

1.It doesn't really modify Visual Studio, but loads the plug-in dll on top of it. There could be issues like memory consumption issues if the plug-in is not properly developed. But hey, it can do all that if you have it loaded. You can always unload the plug-in from Tools -> Add-In Manager.

2.Rollback to previous situation only require deleting the .dll file and the Add-in configuration file from the Addins directory, as I have mentioned in the steps to user the code.
Try it out

- How do you delete an item? Right now you can do that by editing the xml.
- If it is possible, it would be nice to include the name of the function where the code you are reviewing is in.
- When I click on an item to go to the reviewed code I get a "Project item not found" dialog box, but it does jump to the appropriate line.
- A new status for an item could be "Performed" and then "Verified/Closed"