C++ Extension in VS Code 1.18 Release: Quick Fixes for missing header files, Extract to Function & More 

Alexandra Kemper

The 1.18 version of the C++ Extension in Visual Studio Code has been released. With this version of the extension, we have added several new features such as:  

  • Quick Fixes for missing header files 
  • Extract to function/member function 
  • Assistance acquiring a compiler 

 For the full list of changes, please reference the 1.18 release notes 

Quick Fixes for missing header files 

Have you ever written C++ code and forgotten to add the right header? Gotten frustrated because of an IntelliSense error that turns out to just be a missing header file? We have now added a quick fix suggestion (lightbulb) to make the process of adding the correct header files to C++ files easier. If there is an unknown symbol in your C++ code and the C/C++ Extension identifies the correct header file in your workspace, you will now have a quick fix available. Select the quick fix and the necessary header file include will be added to the top of your current C++ file.  

a user selecting a variable with an underline, selecting the fixit and then selecting insert header. This adds the header to the top of their file.

Extract to Function/Member Function 

One of the most highly requested features for C++ in VS Code is support for extracting functions or member functions from code. With the 1.18 release, you can now select a section of your code, extract it into a separate function, and place a reference to the new function in the old location.  

To try this feature, select the C++ code you would like to extract. A code action (lightbulb) will appear with the option Extract to Function. Otherwise, right click on the code and select Refactor > Extract or use the keyboard command Ctrl + Shift + R, Ctrl + E to get more information. As you can see below, you will then have the option to name the new function that has been created. The new function containing your highlighted code will be placed above the current function. 

Image ExtractMethodwithoutexperimentation

Upcoming improvements will further streamline the extraction process, such as being able to extract to a free function. Any feedback you have would be very valuable to share through our GitHub issues to help us build the best experience 

New C++ Compiler Acquisition Process 

To streamline the C++ setup process, we have created an easier C++ compiler installation experience.  

For Mac and Linux users, you can now use the Install Compiler button to install a C++ compiler quickly and easily. The button will install a default C++ compiler on your system through the VS Code command line. This compiler will be automatically configured for IntelliSense. On a Mac, the default compiler installed is clang, while for supported Linux distros it is gcc and g++.  To access this experience, you can use the C++ walkthrough or configuration quickpick. 

Image install a compiler mac, shows that for the configure intellisense command you can select install compiler

To access the walkthrough, use the Open Walkthrough command in the command palette and select the Get Started with C++ Development option. Under the Set Up your C++ Environment, if you do not have a compiler already installed, you will see an Install Compiler button.  

To access the IntelliSense configuration quick pick, enter the Select IntelliSense configuration command in the command palette. From the list, select the Install a Compiler option. A notification will open asking you to confirm the installation process. Select Install, which will open a terminal in VS Code and run the command line commands on your system to install the compiler.  

Image compiler acquisition. Screenshot of the pop up notification that asks you to verify you are installing

Note, you might need to enter your credentials in the command line to install the compiler on your system.   

On a Windows machine, we have added a new IntelliSense configuration menu option called Help me install a compiler. This option will provide you with the command needed to install the Microsoft Visual C++ compiler (MSVC) on your system. Once you attest to having a valid Visual Studio license, then copy this command to your command line to run.  

command to install msvc, find through the walkthrough.

Catching up: Adding Markdown support  

Want to try out more C++ features? We recently added support for markdown when using the hover tooltip on comments. By default, the C++ Extension will now support showing a subset of markdown in your editor. This subset supports all markdown comments except the symbols “_” and “*”. Toggle the new Markdown in Comments setting to enable all markdown, keep this subset of markdown, or disable markdown support.  

Image markdownsupport

We also added a number of other enhancements such as extending support for gcc 13 features, additional compiler detection for MSYS compilers, and support for additional compiler wrappers. See the full release notes here 

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 X/Twitter at  @VisualC. 

 

 

 

 

1 comment

Discussion is closed. Login to edit/delete existing comments.

  • Georgi Hadzhigeorgiev 0

    Nice ones, thanks!

Feedback usabilla icon