Today’s preview of Visual Studio 2017 version 15.6 Preview 2 includes two IntelliSense improvements to streamline code editing for C++ Open Folder and CMake. We added a new type of IntelliSense squiggle to C++ Open Folder and CMake to streamline cross-platform development. We also now support a new heuristic and wildcard syntax to the include path for C++ Open Folder.
If you are new to CMake or Open Folder in Visual Studio, check out how to get started with CMake or other C++ projects.
Cross-Platform IntelliSense Squiggles
If you do cross-platform development in Visual Studio with CMake or C++ Open Folder you already know that by defining multiple configurations you get high-fidelity IntelliSense for each of the platforms that you’re targeting. As you switch between these configurations you will immediately see red squiggles for any code that is unsupported or otherwise invalid for that platform.
In the latest preview, you might notice a new kind of IntelliSense squiggle:
These purple squiggles indicate that while the code is valid for the currently selected configuration (in this picture, targeting a remote Linux machine), the line would cause an error for other configurations. In the example above, the usleep function is not available when targeting Windows. This IntelliSense feature will give you an early heads-up that you need to introduce platform-specific implementation.
By default, Visual Studio will check up to four configurations defined in either CppProperties.json for C++ Open Folder or CMakeSettings.json for CMake. One thing to keep in mind with CMake, however, is that you will need to generate the cache for a configuration at least once for it to be considered by the IntelliSense engine. This can easily be done by selecting that configuration in the dropdown to the left of the “start debugging” button.
This feature can be turned on and off under the advanced C++ options page:
Note: These options also apply to the purple squiggles in MSBuild based shared code projects. C++ shared code projects can be used to share code between UWP and other platforms such as iOS and Android and between Windows and Linux.
Include Path Wildcards for Open Folder
Until today, when you opened a folder in Visual Studio, all include paths had to be manually configured in CppProperties.json. What this meant in practice was that many codebases would see IntelliSense errors due to missing headers even when those headers were readily available in the codebase itself.
The latest preview of Visual Studio automatically adds all folders under the workspace root to the include path to streamline the detection of header files. It does this by adding newly introduced wildcard syntax to the default include path:
"includePath": ["${workspaceRoot}/**"]
This behavior is driven by the CppProperties.json file just like the rest of C++ IntelliSense for Open Folder. As such, opting out of this new behavior is as simple as removing the new wildcard from CppProperties.json. Keep in mind, though, if you generated a CppPropertie.json file prior to today’s preview, you will need to manually add the syntax above to take advantage of this new behavior.
For example, the heuristic can be enabled and disabled by adding or removing line 10 to the snippet below:
{ "configurations": [ { "inheritEnvironments": [ "msvc_x64" ], "name": "windows-x64", "includePath": [ "${env.INCLUDE}", "${workspaceRoot}/**" ], "defines": [ "WIN32", "UNICODE", "_UNICODE" ], "intelliSenseMode": "windows-msvc-x64" } ] }
While this new wildcard syntax can be used to recursively include folders other than the workspace root as well, there are a few caveats to keep in mind. Today, only the IntelliSense include path (which is set with “includePath” in the example above) supports this feature. For instance, wildcards will not be expanded in custom variables. You should also use care when including large folders, especially if they contain ambiguously named headers. It is possible to resolve ambiguously named headers by adding explicit paths earlier in the include path lookup.
Send Us Feedback
We would love to hear about how these features are working for you. As always, we welcome your feedback. Feel free to send any comments through email at visualcpp@microsoft.com, through Twitter @visualc, or Facebook at Microsoft Visual Cpp.
If you encounter other problems with Visual Studio 2017 please let us know via Report a Problem, which is available in both the installer and the IDE itself.
0 comments