共用方式為


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.

Comments

  • Anonymous
    January 10, 2009
    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.

  • Anonymous
    January 11, 2009
    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.

  • Anonymous
    January 11, 2009
    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.

  • Anonymous
    January 12, 2009
    Yess! Since my acquaintance with VS 6.0 I was wondering why MS didn't have such an obviously useful feature.

  • Anonymous
    January 12, 2009
    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?

  • Anonymous
    January 13, 2009
    Welcome to the 48th Community Convergence. The C# team continues to work hard to get out the next version

  • Anonymous
    January 14, 2009
    This is like the analyze feature in reflector :)

  • Anonymous
    January 15, 2009
    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.

  • Anonymous
    January 30, 2009
    Thanks everyone for your feedback! I will post another post shortly.

  • Anonymous
    February 01, 2009
    Sorry, but on http://blogs.msdn.com/kirillosenkov/archive/2009/01/10/call-hierarchy-navigation-in-visual-studio-2010.aspx the images dissapeared.

  • Anonymous
    February 02, 2009
    They're back! Was probably an intermittent server issue.

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

  • Anonymous
    June 03, 2009
    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.

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

  • Anonymous
    June 15, 2009
    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...

  • Anonymous
    June 15, 2009
    Hi Andy, you can try a static analysis tool like NDepend or SemmleCode - static analysis tools are specially build for such things. Thanks, Kirill

  • Anonymous
    June 29, 2009
    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

  • Anonymous
    August 17, 2009
    I just want to say a clear "Thank You" for this useful contribution to the industry's best platform for the best library set=.Net4

  • Anonymous
    August 26, 2009
    New? Hasn't this been available since Call Browser in VS2005?

  • Anonymous
    August 27, 2009
    You're right, but this is new for C#. Call Browser was C++ only.

  • Anonymous
    September 14, 2009
    Please Add "Subscribes" also to the tree as in SCSF we publish and events and want to see who subscribes it...

  • Anonymous
    September 14, 2009
    Hi Tharaka - yes, subscribes and delegate creation are the things we'd love to track as well (also all base implementations up the chain, all derived implementations down the chain, etc)... However I'm afraid we probably won't have time to add this in VS 2010 (I can't be sure, but chances are slight) because it's already pretty late in the cycle. We already passed "visual freeze", which is a point in the Visual Studio development cycle where we're not allowed to change the UI anymore. But definitely, this will be our top priority for the Call Hierarchy improvements after 2010. Thanks, Kirill

  • Anonymous
    October 21, 2009
    Playing with call hierarchy and after creating three methods to test it, I immediately tried to find how can I get all calls FROM a method and in expanded form. I was thinking to use it more like sequence viz to understand code more easily. So far disappointed because of the UI issue you mentioned at the end of your blog.

  • Anonymous
    October 21, 2009
    Devnetfx: I don't quite understand - there are Calls To and Calls From for every method in Call Hierarchy. What do you mean "get all calls FROM a method and in expanded form?" What issue in particular is this? I'd like to follow up to make sure we've fixed it. Thanks! Kirill

  • Anonymous
    February 24, 2010
    The comment has been removed

  • Anonymous
    August 28, 2010
    This feature is very good for browsing the code, was desperately looking this feature since it was taken off in VS 2003. It is ULTRA slow which makes it not usable at all. There are many other tools in the market which provides a similar functionality, they are pretty faster. Can VS team improve the performance of this feature?

  • Anonymous
    January 05, 2011
    I'm looking for the old C++ Call Browser functionality in Visual Studio 2010, but can't find it. Specifically, I am trying to locate any function that contains a sub-string as part of its name.  This new version in 2010 doesn't appear to affer a way to enter search text, like 2008's call browser.

  • Anonymous
    March 24, 2011
    I'm surprised no one suggested separate menu options (or at least separate shortcut keys) for "what calls this method" and "what does this method call". This feature would have also been more useful if there were analogous options for fields: "what reads this field" and "what modifies this field". These two options could have been integrated into the call hierarchy the same way as a property call, so you could drill down to find out what functions call the functions that modify a given variable. This would help answer two questions: "what causes this field to change?" and "what are the dependencies of this field?"

  • Anonymous
    April 23, 2012
    Any chance the call heirachy can be dumped to xml?

  • Anonymous
    April 24, 2012
    Tony - unfortunately not. What do you need it for in XML? Maybe there's a better way?

  • Anonymous
    December 21, 2014
    with vc6, when 'creating brow into file' is selected, you acces all the references immediatly. its incredible that the new compiler is Worth than vc6 vc6 was made by developpers for developpers. They wanted the best experience. Now they want what?