Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call Hierarchy in Visual Studio Code

I'm trying to find a "View the Call Hierarchy" feature in Visual Studio/VSCodium.

What I want to do is right-click on a method's name (or press a keyboard shortcut), and a new pane opens up, displaying all the methods that call the clicked method, and the call tree of this method.

I found that in Eclipse and PyCharm but I only found "Find all references" in VSCode.

EDIT: I want to do that in Python, but if a such feature exists for all languages, that would be nice.

like image 730
Be Chiller Too Avatar asked May 06 '19 15:05

Be Chiller Too


People also ask

How do I get the call hierarchy code in Visual Studio?

To display the Call Hierarchy window, right-click in the code editor on the name of a method, property, or constructor call, and then select View Call Hierarchy.

How do I display hierarchy in Visual Studio?

Right click on the class in "Class View" and choose "View Class Diagram". If the diagram doesn't show the level of detail you want for the hierarchy, right click on the box for the class in the diagram, and choose "Show Derived Classes".

How do I find the call hierarchy?

Call Hierarchy allows you to quickly see all the places where a function or method is used. How to use: Press Ctrl + Alt + H on Windows/Linux, ⌥ + ^ + H on macOS, and the Call Hierarchy tool window will open up with all the places that the function is called inside.


1 Answers

This is currently (v1.33) a preview feature. See release notes re: call hierarchy.

A call hierarchy view shows all calls from or to a function and allows you to drill into callers of callers and calls of calls. The image below shows that function foo is being called by bar and bang, then bar is being called by bang and fib.

call hierarchy demo picture

This is a preview feature and there aren't any extensions currently providing real data for it. However, if you are an extension author, we invite you to validate our proposed API. If you are interested, there is a sample extension for testing: https://github.com/jrieken/demo-callhierarchy.

There is already a bound command for this, editor.showCallHierarchy. You will have to see whether any python extension has support for this feature.

---------- Update -------------------

v1.43 Release notes: https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_43.md#call-hierarchy-support-for-javascript-and-typescript

call heirarchy


In the v1.50 Insiders' Build is the ability to dismiss/exclude selected entries in the call heirarchy (possibly after you have reviewed that entry). See https://github.com/microsoft/vscode/issues/98155

Note the X dismiss button in the demo:

call hierarchy dismiss demo

[thanks to @VonC for finding this PR and pointing it out]

like image 85
Mark Avatar answered Sep 23 '22 12:09

Mark