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:
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.
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.
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.
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.
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.
0 comments