Microsoft has previewed a new search feature for Visual Studio 2022 – but still with no way to search code while excluding comments. Developers have been requesting such a feature since 2018.
The revamped tool is described by product manager Denizhan Yigitbas as “a brand-new all-in-one search experience.” Code search is important to developers, helping them with code navigation, comprehension, and refactoring. Microsoft must also believe (as with the Office applications) that developers need assistance finding their way around the IDE itself, so feature search is also built into the product.
All-one-search is not as new as it first appears. The production version of Visual Studio 2022 already has a search icon in its top menu bar, with options for “All”, “Code” and “Features”. The preview version opens in a separate floating window though, with an option to keep it open as an always-on-top tool. It also supports filtering searches to include only files, types, or members. This kind of filtered search was also available before, but perhaps not as well-known as it deserved to be, since it can be more efficient than plain text search.
One point of possible confusion is that Visual Studio has search options on its Edit menu as well as the Search icon in the top bar, including the venerable Find in files, Quick find, and Quick Replace.
Some developers are unsure whether Microsoft is hitting the right spot. A comment to the Yigitbas post asks the company to “please stop wasting time with new searches and provide an option to search only code” – the point being that there is still no easy way to exclude text in comments. A feature request from 2018 identified this need, which has been “under review” since July 2019.
This IDE is called “Visual Studio” but command-line searches can be a good alternative to using the graphical tools. The grep command line, too – most familiar on Unix-like operating systems – is fast and efficient. Developer Ben Hanson has created a free utility, gram_grep, which combines grep with user-defined grammars for refined searches, at the price of some complexity, but enabling features like ignoring results in comments. Some developers would prefer a simple checkbox that lets them exclude comments from searches without having to use third-party tools.