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.

Free DevExpress Products - Get Your Copy Today

The following free DevExpress product offers remain available. Should you have any questions about the free offers below, please submit a ticket via the DevExpress Support Center at your convenience. We'll be happy to follow-up.
No Comments

Please login or register to post comments.