{"id":18005,"date":"2018-01-10T12:05:35","date_gmt":"2018-01-10T20:05:35","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/vcblog\/?p=18005"},"modified":"2019-02-18T17:48:07","modified_gmt":"2019-02-18T17:48:07","slug":"intellisense-enhancements-for-cpp-open-folder-and-cmake","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cppblog\/intellisense-enhancements-for-cpp-open-folder-and-cmake\/","title":{"rendered":"IntelliSense Enhancements for C++ Open Folder and CMake"},"content":{"rendered":"<p>Today\u2019s <a href=\"https:\/\/www.visualstudio.com\/vs\/preview\/\">preview of Visual Studio 2017<\/a> 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.\u00a0 We also now support a new heuristic and wildcard syntax to the include path for C++ Open Folder.<\/p>\n<p><em>If you are new to CMake or Open Folder in Visual Studio, check out how to <\/em><a href=\"https:\/\/aka.ms\/cmake\"><em>get started with CMake<\/em><\/a><em> or <\/em><a href=\"https:\/\/aka.ms\/openfolder\/cpp\"><em>other C++ projects<\/em><\/a><em>.<\/em><\/p>\n<h3>Cross-Platform IntelliSense Squiggles<\/h3>\n<p>If you do cross-platform development in Visual Studio with CMake or C++ Open Folder you already know that <a href=\"https:\/\/blogs.msdn.microsoft.com\/vcblog\/2017\/08\/25\/visual-c-for-linux-development-with-cmake\/\">by defining multiple configurations<\/a> you get high-fidelity IntelliSense for each of the platforms that you\u2019re targeting.\u00a0 As you switch between these configurations you will immediately see red squiggles for any code that is unsupported or otherwise invalid for that platform.<\/p>\n<p>In the latest preview, you might notice a new kind of IntelliSense squiggle:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/Purple-Squiggle-Example.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/Purple-Squiggle-Example.png\" alt=\"Purple IntelliSense Squiggles\" class=\"size-full wp-image-18075 aligncenter\" width=\"403\" height=\"124\" \/><\/a><\/p>\n<p>These purple squiggles indicate that while the code is valid for the currently selected configuration (in this picture,\u00a0<a href=\"https:\/\/blogs.msdn.microsoft.com\/vcblog\/2017\/08\/25\/visual-c-for-linux-development-with-cmake\/\">targeting a remote Linux machine<\/a>), the line would cause an error for other configurations.\u00a0 In the example above, the usleep function is not available when targeting Windows.\u00a0 This IntelliSense feature will give you an early heads-up that you need to introduce platform-specific implementation.<\/p>\n<p>By default, Visual Studio will check up to four configurations defined in either CppProperties.json for C++ Open Folder or CMakeSettings.json for CMake.\u00a0 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.\u00a0 This can easily be done by selecting that configuration in the dropdown to the left of the \u201cstart debugging\u201d button.<\/p>\n<p>This feature can be turned on and off under the advanced C++ options page:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/Background-IntelliSense-Configuration.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/Background-IntelliSense-Configuration.png\" alt=\"IntelliSense for Inactive Platform Options\" class=\"size-full wp-image-18085 aligncenter\" width=\"744\" height=\"647\" \/><\/a><\/p>\n<p><em>Note: These options also apply to the purple squiggles in MSBuild based shared code projects.\u00a0 C++ shared code projects can be used to <a href=\"https:\/\/blogs.msdn.microsoft.com\/vcblog\/2015\/07\/30\/cross-platform-code-sharing-with-visual-c\/\">share code between UWP and other platforms such as iOS and Android<\/a> and <a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/linux-cross-platform-and-type-visualization\/\">between Windows and Linux<\/a>.<\/em><\/p>\n<h3>Include Path Wildcards for Open Folder<\/h3>\n<p>Until today, when you opened a folder in Visual Studio, all include paths had to be manually configured in CppProperties.json.\u00a0 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.<\/p>\n<p>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.\u00a0 It does this by adding newly introduced wildcard syntax to the default include path:<\/p>\n<pre class=\"prettyprint js\">\n&quot;includePath&quot;: [&quot;${workspaceRoot}\/**&quot;]\n<\/pre>\n<p>This behavior is driven by the CppProperties.json file just like the rest of C++ IntelliSense for Open Folder.\u00a0 As such, opting out of this new behavior is as simple as removing the new wildcard from CppProperties.json.\u00a0 Keep in mind, though, if you generated a CppPropertie.json file prior to today\u2019s preview, you will need to manually add the syntax above to take advantage of this new behavior.<\/p>\n<p>For example, the heuristic can be enabled and disabled by adding or removing line 10 to the snippet below:<\/p>\n<pre class=\"prettyprint js\">\n{\n  &quot;configurations&quot;: [\n    {\n      &quot;inheritEnvironments&quot;: [\n        &quot;msvc_x64&quot;\n      ],\n      &quot;name&quot;: &quot;windows-x64&quot;,\n      &quot;includePath&quot;: [\n        &quot;${env.INCLUDE}&quot;,\n        &quot;${workspaceRoot}\/**&quot;\n      ],\n      &quot;defines&quot;: [\n        &quot;WIN32&quot;, &quot;UNICODE&quot;, &quot;_UNICODE&quot;\n      ],\n      &quot;intelliSenseMode&quot;: &quot;windows-msvc-x64&quot;\n    }\n  ]\n}\n<\/pre>\n<p>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.\u00a0 Today, only the IntelliSense include path (which is set with \u201cincludePath\u201d in the example above) supports this feature.\u00a0 For instance, wildcards will not be expanded in <a href=\"https:\/\/blogs.msdn.microsoft.com\/vcblog\/2017\/11\/02\/customizing-your-environment-with-visual-c-and-open-folder\/\">custom variables<\/a>.\u00a0 You should also use care when including large folders, especially if they contain ambiguously named headers.\u00a0 It is possible to resolve ambiguously named headers by adding explicit paths earlier in the include path lookup.<\/p>\n<h3>Send Us Feedback<\/h3>\n<p>We would love to hear about how these features are working for you.\u00a0 As always, we welcome your feedback.\u00a0 Feel free to send any comments through email at <a href=\"mailto:visualcpp@microsoft.com\">visualcpp@microsoft.com<\/a>, through\u00a0<a href=\"https:\/\/twitter.com\/visualc\">Twitter @visualc<\/a>, or Facebook at\u00a0<a href=\"https:\/\/www.facebook.com\/Microsoft-Visual-Cpp-222043184527264\/\">Microsoft Visual Cpp<\/a>.<\/p>\n<p>If you encounter other problems with Visual Studio 2017 please let us know via\u00a0<a href=\"https:\/\/docs.microsoft.com\/en-us\/visualstudio\/ide\/how-to-report-a-problem-with-visual-studio-2017\">Report a Problem<\/a>, which is available in both the installer and the IDE itself.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today\u2019s 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.\u00a0 We also now support a new heuristic and wildcard syntax to the include [&hellip;]<\/p>\n","protected":false},"author":326,"featured_media":35994,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[266,269],"tags":[8,140,252,233,6,268],"class_list":["post-18005","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cmake","category-openfolder","tag-announcement","tag-c","tag-cmake","tag-cross-platform","tag-ide","tag-openfolder"],"acf":[],"blog_post_summary":"<p>Today\u2019s 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.\u00a0 We also now support a new heuristic and wildcard syntax to the include [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/18005","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/users\/326"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/comments?post=18005"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/18005\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media\/35994"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media?parent=18005"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/categories?post=18005"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/tags?post=18005"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}