📜 ⬆️ ⬇️

Search and code navigation in VS 2010

image
Developers should be able to easily search, navigate and understand the code in which they work. We studied usability and came to the conclusion that the developer spends a lot of time reading, revising and examining existing code, instead of writing new code.

VS 2010 editor adds new features that allow you to more productively search and navigate the code, as well as easier to understand how the code is used in the project.

Search and navigate the source code ASP.NET MVC

For this article, I will use the source code of the ASP.NET MVC framework, which has many thousands of lines of code, to demonstrate some of the new features in search and navigation in VS 2010. If you have VS 2010 Beta 2 installed, you can download ASP.NET MVC framework
')
image

You will find that the performance, below the possibilities presented, is really high, despite a large piece of code of several thousand lines. All features that I will describe are already integrated into VS 2010 and work for all projects in C # or VB.

“Navigate To” Support

It is very important for small or large projects to be able to quickly search and navigate through the code.

Visual Studio 2010 now supports the new hot key combination (Ctrl + Comma), when you click on it, the new “Navigate To” window opens, which allows you to quickly find types, files, variables and members in your project and navigate to their declaration.

image

Thanks to the output of results in the course of entering a request, “Navigate To” gives an increase in search through the UI

image

Type a few more letters and you will see an automatically filtered list that matches the “controller” query:

image

You can use the scroll bar to move around the search result or use the alternative - press Tab and then use the arrows if you do not want to take your hands off the keyboard. The “Navigate To” list includes all types of results that match the search query, including the names of types, methods, properties, files and the declaration of fields.

image

Selecting any result from the list will open the desired source file in VS 2010 (if it is not already open) and drop you to the right place in the code, highlighting the relevant name.

image

Fuzzy search capabilities

The search field in “Navigate To” is able to do tricky things, it allows you to savorly filter and search without knowing the name of the thing you are looking for. It allows you to filter your searches and receive information in real time, while typing.

To test this feature, let's first look for the word “cache”. Note that the result includes not only elements that begin with the word “cache”, but also any elements that contain the word “cache”:

image

We can add a few words to the search field to further filter the results. For example, below, I filter the list by elements that contain both the words “cache” and “action” in the name:

image

Types and members in the .NET Framework use a naming rule called “Pascal Casing”, which means that the first letters of each word in a type or member name must be capitalized. The “Navigate To” window allows you to optionally use the “Pascal Casing” agreement for quick type filtering. It is enough to write in capital letters the first names of the types / members, and it will automatically filter out the results that comply with this agreement.

For example, by writing “AMS” you will see the result below (only those types and terms that contain words that start with A, then M, then S):

image

The “Navigate To” window allows you to quickly filter and navigate through the code using a minimum of clicks and saves you from using the mouse, opening the Solution Explorer and clicking directly on the file.

View Call Hierarchy

Of course, being able to quickly navigate and search by code is great, but being able to see how the code is being used is even better! VS 2010 introduces a new feature - “View Call Hierarchy”, which allows you to quickly find places in the code from which your methods or properties are called and navigate the call tree without starting or debugging an application.

To use this feature, simply highlight the name of the method or property in the code, press Ctrl + K, Ctrl + T or right-click and select “View Call Hierarchy” from the context menu:

image

This will open a new window of the “Call Hierarchy” tool, which by default appears under the code editor. Below, you can see how “Call Hierarchy” displays two methods in our project that call the ViewPage.RenderView () method, highlighted above.

image

Next, we can go into the hierarchy of the first method “RenderViewAndRestoreContentType” to see the call queue:

image

For virtual methods / properties, you can also call the hierarchy window to see what the subclass shows and to overload them.

Double clicking on any member in the “Call Hierarchy” window will open the corresponding source file and move it to the right place in the code.

image

This will allow you to quickly navigate through the code and better understand the relationships between classes and methods while working.

Highlighted references

D VS 2010, when you select or highlight variables / parameters / declaration fields in the code editor, all places with them are automatically highlighted for you in the editor. This makes it easy to determine where and how a variable or parameter is used.

For example, when we select the “controllerContext” parameter in the editor that is passed to the ControllerActionInvoker.GetParameterValue () method below, its four places of use in this method are also highlighted:

image

If I select a local variable in the method, all places of its use will also automatically be highlighted:

image

If several places of use are highlighted, you can navigate through them using Ctrl-Shift- ↑ and Ctrl-Shift- ↓

Source: https://habr.com/ru/post/73199/


All Articles