C++ Extension in VS Code 1.16 Release: Call Hierarchy & more

Alexandra Kemper

The 1.16 version of the C++ Extension in VS Code has now been shipped. With this version of the extension, we are releasing one of our most upvoted GitHub feature requests – Call Hierarchy. We also added new functionality when creating declarations and definitions that allows you to copy the declaration/definition and specify its placement in code, as well as adding other code enhancements. For the full list of changes, please reference the 1.16 release notes.  

Call Hierarchy  

With call hierarchy, you can now easily navigate your codebase, especially when trying to understand the complex calling relationships between functions. This might be a familiar experience if you have used call hierarchy in Visual Studio. Here you can see it in action:  

The gif shows a user navigating to their call hierarchy by right clicking a function with a Quick Fix available, then selecting "Show Call Hierarchy". This opens a side bar with all the calls. The user then clicks on the phone icon in the menu of the side bar to toggle between calls from and calls to for that function.

How can you view the call hierarchy?  

To view the call hierarchy, right-click a function to display the context menu and select Show Call Hierarchy. This will populate the call tree in the side bar with all of the functions called by your selected function. Toggle the phone icon in the side bar menu to switch to incoming calls. Incoming calls will show whenever your function is referenced by another function.

Image showing that the command in the context menu to look for is called "show call hierarchy"

You can also invoke the command palette (Ctrl + Shift + P) and run the command Calls: Show Call Hierarchy to display the call hierarchy side bar.  

Image that shows that the command for call hierarchy in the command palette is called "show call hierarchy".

Additionally, you can explore nested calls by selecting a function already shown in the call tree and right-clicking on that function to view the available commands.

Image shows that if you right click on a function displayed in the call hierarchy call tree, you will be able access another menu which gives you the option to find incoming/outgoing calls for that sub function


Copy Declaration/Definition 

After releasing the Create Declaration/Definition feature in version 1.13.6, you can now also copy that declaration or definition. Rather than using “Create Declaration/Definition” to automatically add a generated declaration or definition to a location chosen by the extension, “Copy Declaration/Definition” will copy the declaration or definition to your clipboard instead. This gives you the option to decide where exactly in your code you would like to paste the copied declaration or definition.   

To copy a definition or declaration, select a function that has a Quick Fix available (three dots under the function name), then select the Code Action (lightbulb icon) on the left. This will open the Code Action options, where you can select “Copy definition of ‘YourFunctionName’” or “Copy declaration of ‘YourFunctionName’” depending on which is being created.  

Gif showing that when you are creating a declaration/definition, when you click on the function, rather than selecting "create declaration" you will select "copy declaration" and vice versa for declarations.

If the Declaration/Definition is not formatted for you when you paste, you can turn on auto formatting by navigating to the settings editor (Ctrl + ,) and searching for Format On Paste. Enabling this will automatically formal all items you paste into the editor.     

What do you think?  

Download the C/C++ extension for Visual Studio Code  today, give it a try, and let us know what you think.  

If you have any questions around this release, feel free to start a discussion in our GitHub repository. Otherwise, if you run into any issues, please report them in the  issues section. We can be reached via the comments below, per email at  visualcpp@microsoft.com, or through our team on Twitter at  @VisualC.  

Posted in C++


Discussion is closed.

Feedback usabilla icon