Tuesday, March 09, 2010

New plugin: CR_NavigateToDefinition

[CardsOnTable:I did not write this plugin. It was written by Jorge Rowies. Thanks so much Jorge. My life, at least, is now much easier]

I know what you’re thinking…. You’re thinking “Why the **** do I need a plugin for that?”… You’re thinking “Studio already does that!!”.

Please just bear with me… All will become clear[er]

So for those who aren’t already at this point let’s spin back a bit first.

What does this plugin do?

Well this plugin will navigate from a type or member to the declaration of that type or member. Which is to say it will find the source code of that element and position your caret on it.

Why do I need this plugin?

Well you might not. this plugin is built to serve an edge case scenario that might not apply to you.

Visual studio already has a function “Goto Definition” which appears to serve the same purpose as this plugin.

Visual Studio Limitations

Visual studio is capable of finding the source you are looking for if the source you are looking for is…

  • …in the same project as that from which you start.
  • …in a project referenced (only a project reference will do) from the project from which you start.

If you use file references then you are normally out of luck.

Why would I use File references if I have the source?

Well your reasons may vary…  I myself have 3 reasons:

  1. Historically (VS2002, VS2003) had some file locking bugs which appeared to lock the produced binaries when intellisense accessed them which would prevent a rebuild until VS was restarted. (This was the reason we switched to File references only in the first place. It probably no longer applies.)
  2. For performance reasons it can be useful to be able to carve up your solution into multiple sub-solutions in order to work on a smaller section of the problem you are assigned to. Using File references allows you to do this quickly and easily as you are already referencing the binary versions of everything. (I have not had to do this in a while because CodeRush’s performance is really that good. But back in the day I had very poor hardware and CodeRush has not always been as performant (Damn it! It’s my blog and I say that ‘Performant’ is a perfectly valid word) as it is now.
  3. We have an external build process which builds reference versions of our dlls etc under known conditions. These are the files that ultimately go into out installers and therefore it makes sense that these are the versions of the files that are actually referenced by the various projects in a solution.

Other uses

So imagine that you’re coding against a 3rd party open source library. (Could be ASP.MVC. Could be Log4Net could be anything really.) You are referencing their binary because frankly you don’t see the value in trying to build their source as well as your own, but it’s comforting to  have it there in case you need it.

Now suddenly you come across a need to understand something about it’s internals. You have 2 choices:

  • Load the OS solution in a new copy of studio
  • Add the OS solution’s project’s to your existing copy of studio

The first of these is the simplest, but you now have to navigate through the OS solution as a separate entity which has no connection to your own project. Thee is no easy way to navigate between the OS solution and your own.

Instead consider adding their solution’s projects to your own. In some cases this is madness as they will have 15 or more projects and things can get out of hand very quickly. However in some cases like ASP.MVC or Log4Net, there are few projects in the OS solution and these can be added very quickly.

Normally this would not have provided any advantage. You would ask VS for the definition of ‘Controller’ and would be greeted with a wonderful view of the Object browser. This will of course give you a view of what members the ‘Controller’ has, but would do nothing for helping you learn how it worked…

With CR_NavigateToDefinition in place, you can now jump directly from a usage of ‘Controller’ to it’s actual definition in it’s own project and you didn’t have to alter any of your own references to do it.

If this plugin interests you you can find further details here

No comments: