Visual Studio Code C/C++ extension May 2018 Update – IntelliSense configuration just got so much easier!
This morning we shipped the May 2018 update of the C/C++ extension for Visual Studio Code, the most significant update to this extension in its 2-year history! The team has been working extremely hard for the past month to bring many new features into this release. We are super excited about it and hope you would like it too!
In this update, we primarily focused on drastically reducing the amount of configuration you have do to gain a great IntelliSense experience, and also added a few other features to boost your productivity. This update includes:
- Recursive search of includePath
- Auto-detection of system includes and defines for WSL, MinGW, and Cygwin
- Global IntelliSense settings
- Auto-detection of libraries installed by Vcpkg for IntelliSense
- Auto-complete for #include
- C/C++ code snippets
- Support for WSL on Windows builds 17110 and higher
You can find the full list of changes in the release notes.
Recursive search of includePath
With this update, you can now specify the IntelliSense includePath to be searched recursively by appending “**” at the end of paths. This eliminates the need of listing individual paths each header lives in, which is especially useful when headers are located in different sub-directories.
The following is an example of using the new syntax “**” for recursive search in the configuration file.
Simply append “**” to the paths to opt in recursive search, or remove “**” to opt out.
During recursive search, IntelliSense will automatically resolve headers when there’s no ambiguity. You should use with care when search large folders recursively, especially when they contain ambiguously named headers. It is recommended to add explicit paths earlier in the include path lookup to help IntelliSense resolve headers to the desired location.
Also, this new syntax doesn’t apply to the “browse.path” setting, which performs recursive search by default when no wildcards are appended.
Auto-detection of system includes and defines for WSL, MinGW, and Cygwin
The March 2018 update added auto-detection of system includes and defines for Mac and Linux. This update extended this feature to the Windows platform. If you develop on Windows targeting a Windows subsystem, such as WSL (Windows subsystem for Linux), MinGW, and Cygwin, the extension now automatically searches for compilers installed in common locations on these systems and queries for its default includes and defines to resolve system headers.
In the following example, the compiler is auto-detected on WSL at the location of “/use/bin/gcc”. System headers will be automatically resolved with no manual configuration needed, unless you would like to change any of the default settings.
On Windows, the compiler auto-detection logic first searches for MSVC, followed by WSL, MinGW, and then Cygwin.
Global IntelliSense settings
This release allows you to set any of the IntelliSense settings in your user or workspace settings.json file. What this means is that these settings would automatically apply to any project (if set as user setting) or any projects in the same workspace (if set as workspace setting). This comes in handy when multiple projects share a common set of includes, defines, or compiler, etc.
For example, the following user setting, will ensure that for all folders and workspaces opened on your system, “c:/users/me/mylibs/include” is searched for headers.
Note that settings defined in c_cpp_properties.json will still be honored and override any user or workspace settings. To use the defaults specified in the user or workspace setting, include “${default}” in the includePath setting in c_cpp_properties.json files.
Vcpkg integration
Vcpkg is a C++ library manager for Linux, macOS and Windows with over 350 open sourced libraries already supported. If your apps use 3rd party libraries, vcpkg provides an easy way to acquire them (see instructions on github). Once libraries are installed through vcpkg, run “vcpkg integrate install” command to make vcpkg visible to VS Code, and then the extension will automatically use the headers for IntelliSense.
Auto-complete for #include
The extension now provides auto-complete suggestions for #include statements, including system headers and user headers.
Here is an example:
C and C++ code snippets
We added a set of C/C++ snippets that make it quicker to type C or C++ constructs like class definitions or long if-then-elseif-else statements.
You can use the “editor.snippetSuggestions” setting to change where the snippets show up in the suggestion list.
Support for WSL on Windows builds 17110 and higher
Last but not least, we updated the extension to work with Windows Update for April 2018, which introduced case-sensitive file naming in a Windows environment for the very first time.
Tell us what you think
Download the C/C++ extension for Visual Studio Code, try it out and let us know what you think. File issues and suggestions on GitHub. If you haven’t already provided us feedback, please take this quick survey to help shape this extension for your needs.