Give option to search only in uncommented code
When searching for a string in a project's source code, I often find myself wasting time examining lines that have been commented out. it would be useful to offer an option to return only lines that are not commented out, so as not to confuse the results.
'Use Find References' and 'delete commented code' are (good) solutions to *different* problems. This suggestion is about searching for arbitrary text when you know that the results you want are definitely not in comments or doc-comments. For example, find all "= null" in your code so you can check them. Or find all mentions of "para" (e.g. "firstPara", "lastPara", "Paragraph") without hitting all the <param> entries in your doc comments. Or a bug causes an error message to be reported, "out of memory", so you want to find the code that emitted that text to locate the buggy code - but Find in Files returns 350 matches even though there are only 2 lines of *code* in your codebase that include that text.
Campbell Wild commented
Where is this "Find References" option? Or do you mean right-click on a variable and Find All References? Because whilst that is useful, there are still many times when you need to search for something that isn't an object, for example, a string value or a line of code.
Ben Voigt [Visual C++ MVP] commented
Instead of a textual search, use "Find References". That will exclude commented code, remarks in comments, appearances inside quoted strings, and similarly named but unrelated items.
Campbell Wild commented
I totally agree with this, but it's not just commented out code. Valid comments can quite easily contain the same content as a bit of code you are searching for.
There really needs to be an option to search in comments, defaulted to off. How often do people actually need to search comments?!
Michael Paterson commented
I agree that if code is commented out, delete it. That's what source control is for.
Tim Burris commented
@Boogaloo: It's obvious in the code view. Colorization does not apply to find results, so especially in the case of multi-line comments, it's not all all obvious whether the line is commented out.
Mark Hurd commented
I think this is a good idea, but it must separately allow/deny single line comments, multi-line comments, XML comments, and, importantly, #IFed out code.
Justin Chase commented
I would recommend deleting commented out code. Use source control to preserve history of old code.
It should be pretty obvious that the code you are looking at is commented out. If not, try changing your "Comment" color to something less like your actual code color.