C++ Extension in VS Code 1.18 Release: Quick Fixes for missing header files, Extract to Function & More
C++ Extension in VS Code 1.18 Release: Quick Fixes for missing header files, Extract to Function & More Alexandra Kemper November 15th, 20231 1 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. 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. 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. 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. […]
