Navigating code with ease

Visual Studio provides lots of features to speed up the process of code navigation; at the same time, these features allow Visual Studio to have a streamlined coding process with a more holistic view of the project. This is particularly useful when you need to switch to a module to see the actual implementation or to update some parts of it, even when it is located somewhere else in the project. Some of the most important features for code navigation are reachable from the context menu in the coding panel:

Navigating code with ease

As shown in the preceding screenshot, when the cursor is over a method and the contextual menu is opened, the command Go To Definition can be found. The Go To Definition command moves the view to the implemented code of the method inside the referenced module.

Another useful debugging function is the Find All References command (the Shift + F12 shortcut). It shows all the points inside the project where the method is used:

Navigating code with ease

The result of the execution of the Find All References command will be shown in a new tool window, Find Symbol Results. It shows both the definition of the method and the actual references inside the project in which the method is actually used.

Furthermore, the code panel provides tools to quickly navigate to any given point of the code. Because of the fact that Visual Studio dynamically analyzes the code when a Python file is opened in the code editor panel, the IDE automatically creates a hierarchal index of it. To navigate the index, use the two comboboxes with the navigation bar that are located at the top of the window.

The first one shows all the global reachable elements in the file, while the second one shows all the inner elements of the item selected in the first combobox. The selection of an element in comboboxes controls the view of the code editor and jumps to the referenced code.

In the following screenshot, we can see how navigation of the comboboxes works, showing the hierarchal view by displaying all the inner components of the html2text class in the second combobox:

Navigating code with ease

To easily go back and forward while navigating the code, especially when jumping between modules, there are two useful buttons in the toolbar that allow you to jump back to the starting point. Look for the two arrow-shaped buttons at the very left-hand side of the toolbar. The arrow pointing to the left is to move backward, which is accessible through the Ctrl + - shortcut; the arrow pointing to the right is used to move forward, which is accessible through the Shift + Ctrl + - shortcut.

Navigating code with ease

The navigation buttons in blue on the left side of the toolbar, are a good way to quickly navigate through the code

The editor window provides a way to navigate the files that are already opened through the file tabs located at the top of the window. As of the time of writing this book, Visual Studio has refined the features available for this. So now, even for PTVS, there are many possibilities to do so. You can close the tabs and move them around. A single tab can be shown in an independent window or side-by-side with another one.

Navigating code with ease

Visual Studio offers a powerful window management, providing a full set of alignment option on every window in the IDE by simply dragging them from the tab

Tabs can be pinned to the leftmost position of the tab bar so they can be easily reached when many files are opened in the code editor. The tab itself has a contextual menu with more commands for the file:

Navigating code with ease

From the tab contextual menu, you are able to manage the tabs or directly execute the code inside the tabs. The Copy Full Path and Open Containing Folder options are very handy during the coding process.

It is also possible to navigate through the files of the project through the Solution Explorer window. Clicking on the file of interest will open the file in the code editor window. A single click opens the file in a temporary state, which means that the file will be opened in a tab at the right end of the tab bar. This is really useful when going through various files without working with them.

Unlike a permanent tab, the temporary tab will remain open until you navigate to another file through the Solution Explorer window. This trims down the amount of tabs open in the code editor. As we all know, it will become difficult to manage and navigate a huge number of open tabs.

Double-clicking on a file in the Solution Explorer window opens it in a permanent tab in the code editor, which is indicated with a pin icon:

Navigating code with ease

The "Solution Explorer" window, on the right, is a powerful tool to navigate through the files of the projects. Open a file in temporary tab by clicking on it. Double-click opens a permanent tab which is indicated with a pin icon

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.41.229