CodeRush Tip – The References Toolwindow

What does it do?

The References Toolwindow shows you every reference to a specified type or identifier (solution wide). It is triggered either using the DevExpress\Tool Windows\References menu or by using it’s default shortcut of [Shift] +[F12]

Why is this different from “Find in Files”?

Intelligent search

Put simply, “Find in Files” is not very clever.

Imagine that you inherit a large legacy application, and are informed that there is a global variable called “str”. You’d like to get some idea of how often this variable is accessed…. some sense of how tightly or loosely coupled it is to the rest of the system.

Before the References Tool window, your best bet was Visual Studio’s “Find in Files” feature. This will find you every minor reference to str anywhere in your search range. It will blindly find you references, comments and even partials, but this isn’t always very useful.

Can you imagine how many hits you’re going to get back searching for references to ‘str’? You’d get hits on string, instruction, tostring, stretch, strong, strange, and of course any comment with any of the previous words and more in it. That is a lot of false positives.

The References Tool window provides an intelligent search, picking up only references to the identifier in question.

Presentation of Results

The results are displayed (by default) in a tool window split left and right (see below).

  • The left side is the main tree of results arranged in a tree by project, files namespaces etc.
  • The right side is used for showing a preview of the selected result in situ.

ReferencesToolWindowDisplay

Single clicking or otherwise selecting any single result in the list on the left, will cause the preview window on the right to be updated to show the result in question along with any surrounding code to give added contextual information.

Command vs. Live Sync mode

The References Toolwindow can operate in 2 different modes.

ReferencesCommandMode  OR referencesLiveSync

When pushed, these buttons will change the mode, displaying at all times whichever is the current mode.

In Command mode the References Toolwindow will wait for you to explicitly click the refresh button (on the far left of it’s toolbar), before refreshing it’s contents based on the identifier at the caret..

In Live Sync mode CodeRush will refresh the References window every time you move the caret from one identifier to another.

Manipulating the results

ReferencesToolbar

The buttons after the mode toggle allow you to manipulate how the results are displayed.

  • The first 2 buttons allow you to sort references by either Reference Count or Alphabetically.
  • The next 5 buttons toggle hierarchy elements in the results. (ie Projects, Files, Namespaces, Classes and Methods in the Tree of results.
  • The next 2 buttons allow you to alter the font size of the results in the tree.
  • The next 3 buttons let you pick a preview location (right, bottom or off.)
  • The final button determines if the progress indicator shows up when references are being calculated.

How Fast is it?

Another good question. I decided to put that to the test. I went out and tried to find the largest open source solution I could. So that others might duplicate my test.

After a little searching I came across SharpDevelop. This is a pretty well known open source IDE. An alternative, if you will, to Visual studio. It’s a pretty complex project with over 750, 000 lines of code.

I loaded up the primary solution and had a look around. I was looking for something that would produce a lot of results, to really push the References Tool window.

Then it hit me….. “Let’s search for references to string.” There should be more than a few of those in a solution this size.. right?

So I found an initial reference to string, and hit [Shift]+[F12]

ReferencesToolWindow

As you can see from the results. I got back more than 16000 references in ~6 seconds including the time it took to populate the results window. In the real world, you’re not typically going to be searching for something that prolific. but even if you are, 6 seconds is a pretty quick time to get your results back in.

For what it’s worth… if I had used “Find In Files”, I’d have got back 21,933 references in 2316 files. That’s over 5717 extra results I didn’t want or need. These would have included partial matches and comments that might have had nothing to do with the type I was actually searching for.

Ah and did I mention that this works with C#', VB.Net, C++ and even JavaScript.

6 comment(s)
Phillip -
Phillip -

Yeah, this is one of my favorite features.  And it crushes Resharper in performance.  See: http://tinyurl.com/3ldcn55

11 April, 2011
Phillip -
Phillip -

oops...  The link I included is cool but this is the one I actually wanted to reference. http://tinyurl.com/3b8a2rl

11 April, 2011
John Newcombe
John Newcombe

Thanks for the tip, I've been doing the Search in Files for too long, how easy is this and not too mention quick.

12 April, 2011
Erin Leary
Erin Leary

I love this feature for finding references, and have been using it for a while to find references when I have the cursor over a type. But maybe I'm missing it, how can I search for a type I type in? For example, I want to find all references of "EmailUtility" but I'm in some random piece of code that doesn't use it. Is there a way to press Ctrl-F12 and type EmailUtility for it to find all references?

12 April, 2011
Rory Becker - DevExpress
Rory Becker - DevExpress

@Erin sorry Erin AFAIK this isn't possible.

However there is another feature that you might try looking at called QuickNav.

I'll be posting on this soon, but in essence it's a Quick Search for Types Etc

Trigger it with Ctrl+Shift+Q and be sure to explore the drop down set of options on the right

12 April, 2011
ELeger
ELeger

This (neat) tool should rather be compared with the equivalent feature built in VS ("Find all references"). ;-)

Few would use "Find in files" for the job.

10 January, 2012

Please login or register to post comments.