{"id":4173,"date":"2009-11-17T10:49:00","date_gmt":"2009-11-17T10:49:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/vcblog\/2009\/11\/17\/improvements-to-find-all-references-in-visual-studio-2010\/"},"modified":"2019-02-18T18:45:44","modified_gmt":"2019-02-18T18:45:44","slug":"improvements-to-find-all-references-in-visual-studio-2010","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cppblog\/improvements-to-find-all-references-in-visual-studio-2010\/","title":{"rendered":"Improvements to Find all references in Visual Studio 2010"},"content":{"rendered":"<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">Hello, my name is Raman Sharma, and I am a Program Manager on the VC++ team.&nbsp; Through this blog post, I wish to highlight some changes we have made to an important feature in the C++ IDE, called \u201cFind all References\u201d.&nbsp; As most of you would know, this feature is used to search for references to any element of your code (classes, class members, functions etc.), inside the entire solution.&nbsp; In Visual Studio 2010, we have made some changes to this feature to provide more flexibility.<\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">Let\u2019s look at these changes through an example.&nbsp; Let\u2019s say you have the following piece of code:<\/font><\/p>\n<p class=\"MsoNormal\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/Far%20blog%20picture%201.png\"><\/p>\n<p class=\"MsoCaption\"><strong><font face=\"Calibri\" color=\"#4f81bd\">Figure 1: Sample Code<\/font><\/strong><\/p>\n<h2><span><font size=\"4\"><font color=\"#4f81bd\"><font face=\"Cambria\">The Old World<\/font><\/font><\/font><\/span><\/h2>\n<p class=\"MsoNormal\"><font size=\"3\"><font face=\"Calibri\">In Visual Studio 2008, if you invoke \u201cFind all References\u201d on the member function <\/font><span>printArea<\/span><font face=\"Calibri\"> of class <\/font><span>Circle<\/span><font face=\"Calibri\"> as in:<\/font><\/font><\/p>\n<p class=\"MsoNormal\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/Far%20Blog%20picture%202.png\"><\/p>\n<p class=\"MsoCaption\"><strong><font face=\"Calibri\" color=\"#4f81bd\">Figure 2: Invoke Find all References<\/font><\/strong><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">You will see the results showing line numbers 7, 20 &amp; 26 as below:<\/font><\/p>\n<p class=\"MsoNormal\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/Far%20blog%20picture%203.png\"><\/p>\n<p class=\"MsoCaption\"><strong><font face=\"Calibri\" color=\"#4f81bd\">Figure 3: Results in VS 2008<\/font><\/strong><\/p>\n<p class=\"MsoNormal\"><font size=\"3\"><font face=\"Calibri\">It is to be noted that the results window <b>does not<\/b> list all the places the word \u201cprintArea\u201d appears.&nbsp; It only lists specifically the places where printArea means the \u201cmember function <\/font><span>printArea<\/span><font face=\"Calibri\"> of class <\/font><span>Circle<\/span><font face=\"Calibri\">\u201d (on which Find all References was invoked).&nbsp; The point is that this is in some sense a compiler-verified-search (I just coined that term but the concept is correct<\/font><span>J<\/span><font face=\"Calibri\">) wherein you will get exactly the C++ symbol you searched for.<\/font><\/font><\/p>\n<h2><span><font size=\"4\"><font color=\"#4f81bd\"><font face=\"Cambria\">The New World<\/font><\/font><\/font><\/span><\/h2>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">In Visual Studio 2010 we have effectively created two modes of search: one that focuses on speed and the other that focuses on accuracy.&nbsp; Needless to say, you can specify the default mode through options and we will remember that setting.&nbsp; More on that later in this post.<\/font><\/p>\n<h3><span><font size=\"3\"><font color=\"#4f81bd\"><font face=\"Cambria\">Speed Mode<\/font><\/font><\/font><\/span><\/h3>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">If you perform the same operation as described above in VS 2010, by default you will get the following results:<\/font><\/p>\n<p class=\"MsoNormal\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/far%20blog%20picture%204.png\"><\/p>\n<p class=\"MsoCaption\"><strong><font face=\"Calibri\" color=\"#4f81bd\">Figure 4: Default results in VS 2010<\/font><\/strong><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">Please note that this time around, the results window <b>does<\/b> list all the places the word \u201cprintArea\u201d appears (including the comments!).&nbsp; Why? Because we wanted to provide the user with an option to search without invoking the compiler.&nbsp; Needless to say, this option will speed up the search significantly, especially for large projects with a lot of hits.<\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">It\u2019s worth mentioning that this search is <b>unlike<\/b> just searching for some text in the entire solution.&nbsp; This is because for this search, the C++ IDE uses an index to narrow the list of files to search.&nbsp; So it doesn\u2019t look through all the files in the solution.&nbsp; The outcome is significantly better performance than just \u201cFind in Files\u201d (or grep), especially for large solutions.<\/font><\/p>\n<h3><span><font size=\"3\"><font color=\"#4f81bd\"><font face=\"Cambria\">Accuracy Mode<\/font><\/font><\/font><\/span><\/h3>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">However, we understand that there can be instances where you want to reduce the ambiguity by filtering the results further.&nbsp; This means you want better accuracy.&nbsp; If you search for a member function of a class, you only want references to that member function of that class.&nbsp; This is even if there are other classes with same named members or other overloads for this function within the same class.&nbsp; To do this, right-click on the results in the results window and invoke \u201cResolve Results\u201d:<\/font><\/p>\n<p class=\"MsoNormal\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/far%20blog%20picture%205.png\"><\/p>\n<p class=\"MsoCaption\"><strong><font face=\"Calibri\" color=\"#4f81bd\">Figure 5: Invoke Resolve Results<\/font><\/strong><\/p>\n<p class=\"MsoNormal\"><font size=\"3\"><font face=\"Calibri\">\u201cResolving results\u201d uses the compiler to actually verify\/confirm the entries and removes references that don\u2019t precisely match.&nbsp; You will be presented with the following results which contain only exact references to <\/font><span>Circle::printArea<\/span><font face=\"Calibri\">:<\/font><\/font><\/p>\n<p class=\"MsoNormal\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/far%20blog%20picture%206.png\"><\/p>\n<p class=\"MsoCaption\"><strong><font face=\"Calibri\" color=\"#4f81bd\">Figure 6: Resolved results in VS 2010<\/font><\/strong><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">If you are feeling more adventurous, there is another part of the accuracy mode which is like asking the following question to the compiler: <i>\u201cFilter out as many extraneous results as you can, and for those you are not sure about, show them anyway\u201d<\/i>.&nbsp; The reason you would want to ask that question is if you want comments, code in different macro states etc. to be included in the search results.<\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">The way to ask this question is to simply right-click on the resolved results in the window and to uncheck \u201cHide Unconfirmed\u201d:<\/font><\/p>\n<p class=\"MsoNormal\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/far%20blog%20picture%207.png\"><\/p>\n<p class=\"MsoCaption\"><strong><font face=\"Calibri\" color=\"#4f81bd\">Figure 7: Uncheck &#8220;Hide Unconfirmed&#8221;<\/font><\/strong><\/p>\n<p class=\"MsoNormal\"><font size=\"3\"><font face=\"Calibri\">Doing this will make sure that search results will exclude only those results which the compiler has verified are <b>definitely not<\/b> references of <\/font><span>Circle::printArea.<\/span><font face=\"Calibri\"> Anything that the compiler verifies is correct and anything it is not sure about will be listed.&nbsp; The results will be as shown below:<\/font><\/font><\/p>\n<p class=\"MsoNormal\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/far%20blog%20picture%208.png\"><\/p>\n<p class=\"MsoCaption\"><strong><font face=\"Calibri\" color=\"#4f81bd\">Figure 8: Resolved and Unconfirmed results in VS 2010<\/font><\/strong><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">Notice this time the results include the comments.&nbsp; It\u2019s worth mentioning that this is the only mode that was supported by VS 2008<\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">The default mode for search is the speed mode.&nbsp; This means, when you invoke Find-all-References, you will see all the places your search item appears.&nbsp; However as with everything else in Visual Studio, there is a way to change this default behavior.&nbsp; If you go to \u201cTools -&gt; Options -&gt; Text Editor-&gt; C\/C++ -&gt;Advanced\u201d, under References you will find two new options \u201cDisable Resolving\u201d and \u201cHide Unconfirmed\u201d:<\/font><\/p>\n<p class=\"MsoNormal\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/far%20blog%20picture%209.png\"><\/p>\n<p class=\"MsoCaption\"><strong><font face=\"Calibri\" color=\"#4f81bd\">Figure 9: Options to set default search mode<\/font><\/strong><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">By default the \u201cDisable Resolving\u201d flag is set to True (means Speed mode).&nbsp; Setting it to False would cause all results to be verified with the compiler (means Accuracy mode).&nbsp; Similarly the default value of \u201cHide Unconfirmed\u201d flag is True.&nbsp; Setting it to False will ensure that search results will contain unconfirmed results in addition to the resolved results.&nbsp; The second flag makes sense only when the first flag is set to False.&nbsp; Also to be noted is that resolving\/unresolving from the results window will not affect the values of these flags.&nbsp; These are global settings meant to specify default behavior.<\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">Overall, we believe that these changes have introduced more flexibility enabling users to optimize their experience based on their own needs.&nbsp; We are excited about this change and hope you will like it.<\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">Thank you.<\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">&nbsp;<\/font><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello, my name is Raman Sharma, and I am a Program Manager on the VC++ team.&nbsp; Through this blog post, I wish to highlight some changes we have made to an important feature in the C++ IDE, called \u201cFind all References\u201d.&nbsp; As most of you would know, this feature is used to search for references [&hellip;]<\/p>\n","protected":false},"author":289,"featured_media":35994,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[64,6],"class_list":["post-4173","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cplusplus","tag-find-all-references","tag-ide"],"acf":[],"blog_post_summary":"<p>Hello, my name is Raman Sharma, and I am a Program Manager on the VC++ team.&nbsp; Through this blog post, I wish to highlight some changes we have made to an important feature in the C++ IDE, called \u201cFind all References\u201d.&nbsp; As most of you would know, this feature is used to search for references [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/4173","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\/289"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/comments?post=4173"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/4173\/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=4173"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/categories?post=4173"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/tags?post=4173"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}