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 (31)

  1. Joe Enos says:

    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.

  2. Kris says:

    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.

  3. Tom says:

    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.

  4. itarapov says:

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

  5. Alex Oleynikov says:

    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?

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

  7. David Fowler says:

    This is like the analyze feature in reflector :)

  8. Greg says:

    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.

  9. Kirill Osenkov says:

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

  10. Kirill Osenkov says:

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

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

  12. Kirill Osenkov says:

    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.

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

  14. Andy says:

    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…

  15. Kirill Osenkov says:

    Hi Andy,

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

    Thanks,

    Kirill

  16. rhodmie sagum says:

    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

  17. Michael Ryan says:

    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

  18. Matt says:

    New? Hasn’t this been available since Call Browser in VS2005?

  19. Kirill Osenkov says:

    You’re right, but this is new for C#. Call Browser was C++ only.

  20. Tharaka says:

    Please Add "Subscribes" also to the tree as in SCSF we publish and events and want to see who subscribes it…

  21. Kirill Osenkov says:

    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

  22. Devnetfx says:

    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.

  23. Kirill Osenkov says:

    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

  24. Johnny American says:

    DOES NOT WORK WITH VB.NET

    IN OTHER WORDS, IT F’ING SUCKS.

  25. Amal says:

    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?

  26. Grant says:

    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.

  27. David Piepgrass says:

    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?"

  28. Tony says:

    Any chance the call heirachy can be dumped to xml?

  29. Kirill Osenkov says:

    Tony – unfortunately not. What do you need it for in XML? Maybe there's a better way?

  30. jean says:

    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?