Welcome to MSDN Blogs Sign in | Join | Help

Call Hierarchy Navigation in Visual Studio 2010

We're currently designing a new IDE feature named Call Hierarchy. Essentially, it allows you to find places where a given method is called, which is similar to how Find All References currently works. However, unlike Find All References, the Call Hierarchy feature provides more deep understanding and more detailed information about calls.

Invocation

You can invoke the Call Hierarchy toolwindow by right-clicking on a method, property or constructor name in the code editor and choosing View Call Hierarchy from the context menu:

image

Tool window

A toolwindow will appear docked on the bottom of the Visual Studio window:

image

You can expand the node for the method to see information about it: incoming calls to the method ("Calls To") and outgoing calls ("Calls From"):

image

Here's how it works. A method (or a property, or a constructor) is displayed as a root in the treeview. You can expand the node to get a list of "search categories" - things you want to find. Four search categories are currently supported:

  1. Calls To - "incoming" calls to this member
  2. Calls From - "outgoing" calls mentioned in this member's body
  3. Overrides - available only for abstract or virtual members
  4. Implements - finds places where an interface member is implemented

When you expand a search node (such as Calls To 'GetCallableMethods'), a solution-wide search is started in the background and the results appear under the Calls To folder. You can click on a result, and the details will appear in the Details list view on the right hand side.

The Details list view shows all the exact call sites and locations in code where GetCallableMethods is called from GenerateXsdForComplexTypes. We see that the method is being called only once, the line of code is shown, as well as file name and position in the file. Double-clicking on that call site will navigate to it in the code editor.

The advantages of Call Hierarchy compared to Find All References is that it allows you to explore and drill deep multiple levels into the call graph (find caller's caller etc.) Also, Call Hierarchy has deeper and more fine-granular understanding of the source code - while Find All References just finds the symbols, Call Hierarchy differentiates abstract and virtual methods, interface implementations, actual calls from delegate creation expressions, etc. Also it works like a scratch-pad: you can add any member as another root-level item in the call hierarchy tool window and have several members displayed there at once. Finally, the Details Pane given information about the concrete call sites, if a method is being called several times in the body of the calling method.

Toolbar

In the toolbar you can select the scope of the search: search in currently opened file only, current project or the entire solution.

Refresh button re-fills the treeview in case the original source code was modified.

If a root node of the treeview is selected, the "Delete Root" button will remove it from the treeview. You can add any member as a new root in the treeview by right-clicking on it in the context menu:

image

or adding it from the source code as described in the beginning.

Finally, the Toggle Details Pane button shows or hides the details pane.

Some design issues and implementation details

Although the feature is already implemented and if you have the Visual Studio 2010 CTP, you can already play with Call Hierarchy, we're still not quite happy with the current UI design, usability and the user experience.

For example, one issue that we're seeing is that it takes 2 mouseclicks and 2 mousemoves to invoke the Find All References search, but it takes 4 mouseclicks and 4 mousemoves to get the callers list for a given method (1 click - menu invocation, 1 click - menu item selection, 1 click - expand the treeview node for the method, 1 click - expand the "Calls To" folder). Although the search itself will be slightly faster than Find All References, the perceived complexity of invoking the feature is something we definitely want to improve. We want this feature to be at least as good and usable as Find All References, but also provide additional benefits, otherwise people will just not use the feature and continue using Find All References.

I think I'll stop for now and see what kind of feedback you guys might have about this. In the next blog post I plan to share more of our current thinking and what we'd like to change. For now, I'd be really interested to know what you think and if you have any suggestions or ideas. Now it's not too late, and we can change the feature based on your feedback.

Published Saturday, January 10, 2009 6:15 PM by Kirill Osenkov
Filed under: ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: Call Hierarchy Navigation in Visual Studio 2010

Saturday, January 10, 2009 10:08 PM by Joe Enos

This looks awesome.  I've been waiting for this for years - it's unbelievable how much time I waste on "Find All References" when multiple things call multiple things which call what I'm looking for.

Can't wait for VS2010.

# re: Call Hierarchy Navigation in Visual Studio 2010

Sunday, January 11, 2009 2:44 PM by Kris

I have used something similar to this feature in Eclipse, but lately with so many frameworks relying on XML configs and reflection, this feature is becoming less useful. Nevertheless, I would love to see this in VS.

# re: Call Hierarchy Navigation in Visual Studio 2010

Monday, January 12, 2009 3:21 AM by Tom

You didn't mention anything about keyboard shortcuts for Call Hierarchy. Keyboard usage is a crucial aspect of such tools. I can invoke Find All References by pressing SHIFT-F12, and move through references using F8, very convenient. The new feature must be as least as easy to use as this. Better still to keep the same key bindings, so we don't have to get used to new ones.

Perhaps the most common use case of Call Hierarchy can be covered by these keys, with ALL other use cases covered by other keys. Reaching for the mouse is a pain, especially when working on a laptop.

# re: Call Hierarchy Navigation in Visual Studio 2010

Monday, January 12, 2009 9:30 AM by itarapov

Yess! Since my acquaintance with VS 6.0 I was wondering why MS didn't have such an obviously useful feature.

# re: Call Hierarchy Navigation in Visual Studio 2010

Tuesday, January 13, 2009 7:38 AM by Alex Oleynikov

Very nice feature - love it!

Regarding your concern about extra mouse clicks/moves to get the same results as in "Find All References": immediate solution that comes to mind is for the Call Hierarchy operation to highlight the "Calls To" node automatically to display all callers of the method as the default outcome.

How about another category  - "Subscribes", if the "Calls To" is invoked on an event? This is also kind of a call, isn't it?

# Community Convergence XLVIII

Wednesday, January 14, 2009 12:03 AM by Charlie Calvert's Community Blog

Welcome to the 48th Community Convergence. The C# team continues to work hard to get out the next version

# re: Call Hierarchy Navigation in Visual Studio 2010

Thursday, January 15, 2009 4:35 AM by David Fowler

This is like the analyze feature in reflector :)

# Call tree and refactoring

Thursday, January 15, 2009 11:44 AM by Greg

How could I use the call tree explorer tool to find functions declared in one class that are only used in another class?

Same question but how to find functions that are declared in one file and only called from a single other file.

Generally, I'd like to be able to reorganize a project and its classes so that

 a) Functions only called from one class but are declared outside that class can be moved into that class and made private (if it makes sense)

 b) Functions are organized into source code files to minimize the number of cross file function calls (when it makes sense)

I try to make most all functions static without side effects since it is much much easier when dealing with legacy code to modify a static function rather than one that is not static (i.e, because you do not have to worry about object state with a static function since it has not object state).  this makes it easier to refactor since a function without side effects can be moved from one class to another or one source code file to another without any long, detailed analysis needed.

# re: Call Hierarchy Navigation in Visual Studio 2010

Friday, January 30, 2009 9:32 PM by Kirill Osenkov

Thanks everyone for your feedback! I will post another post shortly.

# I can't see the images

Monday, February 02, 2009 3:27 AM by Vasile Minea

# re: Call Hierarchy Navigation in Visual Studio 2010

Monday, February 02, 2009 2:41 PM by Kirill Osenkov

They're back! Was probably an intermittent server issue.

# Should Call Hierarchy display compiler-generated members?

Wednesday, May 20, 2009 2:03 AM by Kirill Osenkov

[A quick reminder, Call Hierarchy is a new IDE feature in VS 2010] In the comments to the previous post

# re: Call Hierarchy Navigation in Visual Studio 2010

Wednesday, June 03, 2009 6:38 PM by Kirill Osenkov

Tom: thanks a lot for the feedback about keyboard navigation. We hope to add the support for F8/Shift+F8 before we ship.

Right now we support Ctrl+Alt+K to set focus to the Call Hierarchy toolwindow, and once you're inside, arrow keys do the navigation, F12 or Return on a member will go back to the editor.

# Call Hierarchy

Thursday, June 11, 2009 12:23 PM by Visual C++ Team Blog

Hello everyone, My name is Raman Sharma and I am a PM on the VC++ IDE team. I want to talk about a new

# re: Call Hierarchy Navigation in Visual Studio 2010

Monday, June 15, 2009 7:12 PM by Andy

Feature looks cool... It would be nice if one could perform a query like "Find all functions in solution that have no callers" or exactly one, etc. We have some legacy code and it would be nice to quickly sort out the dead methods and remove them- I suspect there are hundreds if not thousands in one area of our code base...

# re: Call Hierarchy Navigation in Visual Studio 2010

Monday, June 15, 2009 7:27 PM by Kirill Osenkov

Hi Andy,

you can try a static analysis tool like NDepend or SemmleCode - static analysis tools are specially build for such things.

Thanks,

Kirill

# re: Call Hierarchy Navigation in Visual Studio 2010

Tuesday, June 30, 2009 3:26 AM by rhodmie sagum

whew.. it should have been done years and years ago, eclipse and netbeans had been implementing this for some quite times now.. it really helps a lot during development to see who calls who.. nice article

Leave a Comment

(required) 
required 
(required) 
 
Page view tracker