{"id":18645,"date":"2018-03-27T11:21:18","date_gmt":"2018-03-27T18:21:18","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/vcblog\/?p=18645"},"modified":"2019-02-18T17:48:00","modified_gmt":"2019-02-18T17:48:00","slug":"configuring-c-intellisense-and-browsing","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cppblog\/configuring-c-intellisense-and-browsing\/","title":{"rendered":"Configuring C++ IntelliSense and Browsing"},"content":{"rendered":"<p>Whether you are creating a new (or modifying an existing) C++ project using a Wizard, or importing an project into Visual Studio from another IDE, it\u2019s important to configure the project correctly for the IntelliSense and Browsing features to provide accurate information.\u00a0 This article provides some tips on configuring the projects and describes a few ways that you can investigate configuration problems.<\/p>\n<h3>Include Paths and Preprocessor Macros<\/h3>\n<p>The two settings that have the greatest effect on the accuracy of IntelliSense and Browsing operations are the Include Paths and the Preprocessor macros.\u00a0 This is especially important for projects that are built outside of Visual Studio: such a project may build without any errors, but show squiggles in Visual Studio IDE.<\/p>\n<p>To check the project\u2019s configuration, open the Properties for your project.\u00a0 By default, All Configurations and All Platforms will be selected, so that the changes will be applied to all build configurations:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/Project_Properties_All_Configurations.png\"><\/a><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/Project_Properties_All_Configurations.png\"><img decoding=\"async\" width=\"449\" height=\"154\" class=\"alignnone wp-image-18675 size-full\" alt=\"\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/Project_Properties_All_Configurations.png\" \/><\/a><\/p>\n<p>If some configurations do not have the same values as the rest, then you will see <strong>&lt;different options&gt;<\/strong>. If your project is a Makefile project, then you will see the following properties dialog. In this case, the settings controlling IntelliSense and Browsing will be under NMake property page, IntelliSense category:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/Project_Properties_All_Configurations.png\"><\/a><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/Makefile_Project_Properties_IntelliSense.png\"><\/a><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/Makefile_Project_Properties_IntelliSense.png\"><img decoding=\"async\" width=\"484\" height=\"249\" class=\"alignnone wp-image-18685 size-full\" alt=\"\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/Makefile_Project_Properties_IntelliSense.png\" \/><\/a><\/p>\n<h3>Error List<\/h3>\n<p>If IntelliSense is showing incorrect information (or fails to show anything at all), the first place to check is the Error List window.\u00a0 It could happen that earlier errors are preventing IntelliSense from working correctly.\u00a0 To see all the errors for the current source file together with all included header files, enable showing IntelliSense Errors in the Error List Window by making this selection in the dropdown:<\/p>\n<p><figure id=\"attachment_18795\" aria-labelledby=\"figcaption_attachment_18795\" class=\"wp-caption alignnone\" ><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/Error_List_IntelliSense1.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/Error_List_IntelliSense1.png\" alt=\"Error List IntelliSense Dropdown\" width=\"591\" height=\"78\" class=\"wp-image-18795\" \/><\/a><figcaption id=\"figcaption_attachment_18795\" class=\"wp-caption-text\">Error List IntelliSense Dropdown<\/figcaption><\/figure><\/p>\n<p>IntelliSense limits the number of errors it produces to 1000. If there are over 1000 errors in the header files included by a source file, then the source file will show only a single error squiggle at the very start of the source file.<\/p>\n<h3>Validating Project Settings via Diagnostic Logging<\/h3>\n<p>To check whether IntelliSense compiler is using correct compiler options, including Include Paths and Preprocessor macros, turn on Diagnostic Logging of IntelliSense command lines in Tools &gt; Options &gt; Text Editor &gt; C\/C++ &gt; Advanced &gt; Diagnostic Logging. Set Enable Logging to True, Logging Level to 5 (most verbose), and Logging Filter to 8 (IntelliSense logging):<\/p>\n<p><figure id=\"attachment_18695\" aria-labelledby=\"figcaption_attachment_18695\" class=\"wp-caption alignnone\" ><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/IntelliSense_Diagnostic_Logging.png\"><img decoding=\"async\" width=\"596\" height=\"322\" class=\"wp-image-18695 size-full\" alt=\"Enabling the Diagnostic Logging in Tools &gt; Options &gt; Text Editor &gt; C\/C++ &gt; Advanced\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/IntelliSense_Diagnostic_Logging.png\" \/><\/a><figcaption id=\"figcaption_attachment_18695\" class=\"wp-caption-text\">Enabling Diagnostic Logging in Tools &gt; Options<\/figcaption><\/figure><\/p>\n<p>The Output Window will now show the command lines that are passed to the IntelliSense compiler. Here is a sample output that you may see:<\/p>\n<pre> [IntelliSense] Configuration Name: Debug|Win32\n [IntelliSense] Toolset IntelliSense Identifier:\n [IntelliSense] command line options:\n \/c\n \/I.\n \/IC:\\Repo\\Includes\n \/DWIN32\n \/DDEBUG\n \/D_DEBUG\n \/Zc:wchar_t-\n \/Zc:forScope\n \/Yustdafx.h<\/pre>\n<p>This information may be useful in understanding why IntelliSense is providing inaccurate information. One example is unevaluated project properties. If your project\u2019s Include directory contains $(MyVariable)\\Include, and the diagnostic log shows \/I\\Include as an Include path, it means that $(MyVariable) wasn\u2019t evaluated, and was removed from the final include path.<\/p>\n<h3>IntelliSense Build<\/h3>\n<p>In order to evaluate the command lines used by the IntelliSense compiler, Visual Studio launches an IntelliSense-only build of each project in the solution. MSBuild performs the same steps as the project build, but stops short of executing any of the build commands: it only collects the full command line.<\/p>\n<p>If your project contains some custom .props or .targets files, it\u2019s possible for the IntelliSense-only build to fail before it finishes computing the command lines. Starting with Visual Studio 2017 15.6, errors with IntelliSense-only build are logged to the Output window, Solution Pane.<\/p>\n<p><figure id=\"attachment_18745\" aria-labelledby=\"figcaption_attachment_18745\" class=\"wp-caption alignnone\" ><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/Output_Window_Solution.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/Output_Window_Solution.png\" alt=\"Output Window, Solution Pane\" width=\"434\" height=\"59\" class=\"size-full wp-image-18745\" \/><\/a><figcaption id=\"figcaption_attachment_18745\" class=\"wp-caption-text\">Output Window, Solution Pane<\/figcaption><\/figure><\/p>\n<pre>An example error you may see is:\n error: Designtime build failed for project 'E:\\src\\MyProject\\MyProject.vcxproj',\n configuration 'Debug|x64'. IntelliSense might be unavailable.\n Set environment variable TRACEDESIGNTIME=true and restart\n Visual Studio to investigate.<\/pre>\n<p>If you set the environment variable TRACEDESIGNTIME to true and restart Visual Studio, you will see a log file in the %TEMP% directory which will help diagnose this error:<\/p>\n<pre>C:\\Users\\me\\AppData\\Local\\Temp\\MyProject.designtime.log :\n error : Designtime build failed for project 'E:\\src\\MyProject\\MyProject.vcxproj',\n configuration 'Debug|x64'. IntelliSense might be unavailable.<\/pre>\n<p>To learn more about TRACEDESIGNTIME environment variable, please see the articles from the <a href=\"https:\/\/github.com\/dotnet\/roslyn\/wiki\/Diagnosing-Project-System-Build-Errors\">Roslyn<\/a>\u00a0and <a href=\"https:\/\/github.com\/dotnet\/project-system\/blob\/master\/docs\/design-time-builds.md\">Common Project System<\/a>\u00a0projects. C++ Project System is based on the Common Project System, so the information from the articles is applicable to all C++ projects.<\/p>\n<h3>Single File IntelliSense<\/h3>\n<p>Visual Studio allows you to take advantage of IntelliSense and Browsing support of files that are not part of any existing projects. By default, files opened in this mode will not display any error squiggles but will still provide IntelliSense; so if you don\u2019t see any error squiggles under incorrect code, or if some expected preprocessor macros are not defined, check whether a file is opened in Single-File mode. To do so, look at the Project node in the Navigation Bar: the project name will be Miscellaneous Files:<\/p>\n<p><figure id=\"attachment_18735\" aria-labelledby=\"figcaption_attachment_18735\" class=\"wp-caption alignnone\" ><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/Miscellaneous_Files_NavBar.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/Miscellaneous_Files_NavBar.png\" alt=\"Navigation Bar showing Miscellaneous Files project\" width=\"335\" height=\"133\" class=\"size-full wp-image-18735\" \/><\/a><figcaption id=\"figcaption_attachment_18735\" class=\"wp-caption-text\">Navigation Bar showing Miscellaneous Files project<\/figcaption><\/figure><\/p>\n<h3>Investigating Open Folder Issues<\/h3>\n<p>Open Folder is a new command in Visual Studio 2017 that allows you to open a collection of source files that doesn\u2019t contain any Project or Solution files recognized by Visual Studio. To help configure IntelliSense and browsing for code opened in this mode, we\u2019ve introduced a configuration file CppProperties.json. Please refer to <a href=\"https:\/\/aka.ms\/openfolder\/cpp\">this article<\/a> for more information.<\/p>\n<h3>CppProperties.json Syntax Error<\/h3>\n<p>If you mistakenly introduce a syntax error into the CppProperties.json file, IntelliSense in the affected files will be incorrect. Visual Studio will display the error in the Output Window, so be sure to check there.<\/p>\n<h3>Project Configurations<\/h3>\n<p>In Open Folder mode, different configurations may be selected using the Project Configurations toolbar.<\/p>\n<p><figure id=\"attachment_18755\" aria-labelledby=\"figcaption_attachment_18755\" class=\"wp-caption alignnone\" ><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/Project_Configuration_Dropdown.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/Project_Configuration_Dropdown.png\" alt=\"Project Configurations Dropdown\" width=\"362\" height=\"152\" class=\"size-full wp-image-18755\" \/><\/a><figcaption id=\"figcaption_attachment_18755\" class=\"wp-caption-text\">Project Configurations Dropdown<\/figcaption><\/figure><\/p>\n<p>Please note that if multiple CppProperties.json files provide differently-named configurations, then the selected configuration may not be applicable to the currently-opened source file. To check which configuration is being used, turn on Diagnostic Logging to check for IntelliSense switches.<\/p>\n<h3>Single-File IntelliSense<\/h3>\n<p>When a solution is open, Visual Studio will provide IntelliSense for files that are not part of the solution using the Single-File mode.\u00a0 Similarly, in Open Folder mode, Single-File IntelliSense will be used for all files outside of the directory cone.\u00a0 Check the Project name in the Navigation Bar to see whether the Single-File mode is used instead of CppProperties.json to provide IntelliSense for your source code.<\/p>\n<h3>Investigating Tag Parser Issues<\/h3>\n<p>Tag Parser is a \u2018fuzzy\u2019 parser of C++ code, used for Browsing and Navigation.\u00a0 (Please check out <a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/tag-parsing-c\/\">this blog post<\/a> for more information.)<\/p>\n<p>Because Tag Parser doesn\u2019t evaluate preprocessor macros, it may stumble while time parsing code that makes heavy use of them. When the Tag Parser encounters an unfamiliar code construct, it may skip a large region of code.<\/p>\n<p>There are two common ways for this problem to manifest itself in Visual Studio. The first way is by affecting the results shown in the Navigation Bar. If instead of the enclosing function, the Navigation Bar shows an innermost macro, then the current function definition was skipped:<\/p>\n<p><figure id=\"attachment_18715\" aria-labelledby=\"figcaption_attachment_18715\" class=\"wp-caption alignnone\" ><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/Cpp_File_Macro_Usage.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/Cpp_File_Macro_Usage.png\" alt=\"Navigation Bar shows incorrect scope\" width=\"418\" height=\"303\" class=\"size-full wp-image-18715\" \/><\/a><figcaption id=\"figcaption_attachment_18715\" class=\"wp-caption-text\">Navigation Bar shows incorrect scope<\/figcaption><\/figure><\/p>\n<p>The second way the problem manifests is by showing a suggestion to create a function definition for a function that is already defined:<\/p>\n<p><figure id=\"attachment_18705\" aria-labelledby=\"figcaption_attachment_18705\" class=\"wp-caption alignnone\" ><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/Cpp_File_Green_Squiggle.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/Cpp_File_Green_Squiggle.png\" alt=\"Spurious Green Squiggle\" width=\"309\" height=\"291\" class=\"size-full wp-image-18705\" \/><\/a><figcaption id=\"figcaption_attachment_18705\" class=\"wp-caption-text\">Spurious Green Squiggle<\/figcaption><\/figure><\/p>\n<p>In order to help the parser understand the content of macros, we have introduced the concept of hint files. (Please see <a href=\"https:\/\/docs.microsoft.com\/en-us\/cpp\/ide\/hint-files\">the documentation<\/a> for more information.) Place a file named cpp.hint to the root of your solution directory, add to it all the code-altering preprocessor definitions (i.e. #define do_if(condition) if(condition)) and invoke the Rescan Solution command, as shown below, to help the Tag Parser correctly understand your code.<\/p>\n<p>Coming soon: Tag Parser errors will start to appear in the Error List window. Stay tuned!<\/p>\n<h3>Scanning for Library Updates<\/h3>\n<p>Visual Studio periodically checks whether files in the solution have been changed on disk by other programs.\u00a0 As an example, when a \u2018git pull\u2019 or \u2018git checkout\u2019 command completes, it may take up to an hour before Visual Studio becomes aware of any new files and starts providing up-to-date information.\u00a0 In order to force a rescan of all the files in the solution, select the <strong>Rescan Solution<\/strong> command from the context menu:<\/p>\n<p><figure id=\"attachment_18785\" aria-labelledby=\"figcaption_attachment_18785\" class=\"wp-caption alignnone\" ><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/Rescan_Solution_Context_Menu.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/Rescan_Solution_Context_Menu.png\" alt=\"Rescan Solution Context Menu\" width=\"385\" height=\"187\" class=\"size-full wp-image-18785\" \/><\/a><figcaption id=\"figcaption_attachment_18785\" class=\"wp-caption-text\">Rescan Solution Context Menu<\/figcaption><\/figure><\/p>\n<p>The <strong>Rescan File<\/strong> command, seen in the screenshot above, should be used as the last diagnostic step.\u00a0\u00a0In the rare instance that the IntelliSense engine loses track of changes and stops providing correct information, the <strong>Rescan File<\/strong> command will restart the engine for the current file.<\/p>\n<h3>Send us Feedback!<\/h3>\n<p>We hope that these starting points will help you diagnose any issues you encounter with IntelliSense and Browsing operations with Visual Studio. For all issues you discover, please report them by using the Help &gt; Send Feedback&gt; Report A Problem command. All reported issues can be viewed at the <a href=\"https:\/\/developercommunity.visualstudio.com\/\">Developer Community<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Whether you are creating a new (or modifying an existing) C++ project using a Wizard, or importing an project into Visual Studio from another IDE, it\u2019s important to configure the project correctly for the IntelliSense and Browsing features to provide accurate information.\u00a0 This article provides some tips on configuring the projects and describes a few [&hellip;]<\/p>\n","protected":false},"author":332,"featured_media":35994,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[216,280],"tags":[],"class_list":["post-18645","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-documentation","category-new-user"],"acf":[],"blog_post_summary":"<p>Whether you are creating a new (or modifying an existing) C++ project using a Wizard, or importing an project into Visual Studio from another IDE, it\u2019s important to configure the project correctly for the IntelliSense and Browsing features to provide accurate information.\u00a0 This article provides some tips on configuring the projects and describes a few [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/18645","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\/332"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/comments?post=18645"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/18645\/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=18645"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/categories?post=18645"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/tags?post=18645"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}