Earlier today we shipped the April 2017 update to the C/C++ extension for Visual Studio Code. We are excited to introduce the following new features in this update:
- Error Squiggles
- Quick Info
- Go to Declaration
- Bash on Windows debugging support
The original blog post has been updated with these changes. If you have this extension installed already, Visual Studio Code sends a notification for the update and installs the update for you automatically. If you haven’t installed it before, download the C/C++ extension for Visual Studio Code to try it out.
Error Squiggles and Quick Info
Enabling the features
In this update, we’re shipping Error Squiggles and Quick Info as “experimental features”. What this means is that they are turned on by default only for those using VSCode Insiders, and off by default for anyone else. You can enable or disable the features by toggling the setting in the settings.json file (File->Preferences->Settings). In the settings file, search for “intellisense” to locate the C_Cpp.intelliSenseEngine setting, and set it to “Default” to enable the new IntelliSense Engine (see the following screenshot). “Default” will become the true default for everyone when these features exit their experimental state. 🙂
The “C_cpp.errorSquiggles” setting in the same file allows turning on or off the squiggle feature when the default IntelliSense engine is used.
We encourage you to turn on the features, try them out, and send us feedback so we can further polish these features and turn them on by default soon.
A while back we enabled showing error squiggles for the #include statements. This update adds support for showing squiggles under any program element, including variables, keywords, and braces, if a workspace exists. In other words, squiggles are not enabled when only single files are open.
For example, in the following screenshot, Vector3 has a red squiggly underline, indicating this type can’t be found in the specified include paths.
Clicking on Vector3 in the code, you will see a light bulb on the left side of the line. The “Add include path to settings” menu on the light bulb will take you to the c_cpp_properties.json file in which you can specify the include paths for IntelliSense. If the c_cpp_properties.json file does not already exist, it will be created and populated with the following default include paths:
- On Windows, we default to the workspace root, the VC include path if Visual Studio 2017 or 2015 is installed, and the latest Windows SDK if found.
- On Linux, we default to the workspace root, the highest version of the includes found in /usr/include/c++, 64-bit specific headers if they are present, and headers found under /usr/lib/clang if present.
- On Mac, we default to the workspace root and the Xcode default toolchain if present or the same paths as Linux if Xcode is not found.
You can add, remove, or modify the paths in the includePath setting to fit your scenario. In this example, I added another path (highlighted with the red underline) for the IntelliSense engine to look for types.
Note that there’s a newly-added “path” setting under “browse”, which is used by the tag parser for performing fuzzy search results. The “includePath” setting, which was formerly used by the tag parser, now controls the include paths for the new IntelliSense engine. On opening any existing c_cpp_properties.json files, the value in the “includePath” is automatically copied into the “browse.path” setting.
You can also configure the “defines” setting in the c_cpp_properties.json file to define preprocessor symbols.
Now if I save the change in the json file and switch back to the previous header file, the types are now resolved and the red squiggles are gone.
Quick Info enables viewing the type information or function’s signature when hovering the mouse cursor over a variable or a function. In this extension, this used to be performed by the tag parser, which provides quick but fuzzy results – sometimes inaccurate. With the new IntelliSense engine, we can provide more accurate results for local and global variables, functions, and symbols. In the following screenshot, hovering over the local variable “it” displays its accurate type information.
Go to Declaration
With this extension, you can already perform “Go to Definition” (F12) on variables or functions to open the document where the object is defined. This update added “Go to Declaration” (Ctrl+F12) for navigating to the file where the object is declared. To use this feature, simply right click on any variable or function and select “Go to Declaration” from the menu.
In this example in the following screenshot, I selected “Text.DrawString” function and clicked on “Go to Declaration”.
In the next screenshot, you can see that the “TextRenderer.h” file is open and the two DrawString function declarations are being highlighted.
Bash on Windows debugging support
With the release of Windows 10 Creators Update, you are now able to use VSCode and this extension to debug your Windows Subsystem for Linux (WSL) Bash on Ubuntu projects. You can use VSCode to write code on Windows, and debug through bash.exe to the Bash on Windows layer. Please see these instructions on how to use VSCode C/C++ extension to debug Windows 10’s Subsystem for Linux.
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.