Rory Becker - DevExpress CodeRush Blog

June 2016 - Posts

  • CodeRush for Roslyn: The Navigation Menu

    Every symbol in your code has significance. Every symbol is a jumping off point for all sorts of investigation.

    Typically you’ll be used to being able to see “All References” to a variable or class, and determine exactly how heavily used it is within your code.

    This is a great way to get a general feel for where your code is used within your project\solution, but what happens if you need to ask some more specific questions? What if you wanted to find something more focused than “every reference” to your chosen symbol?

    Enter the Navigation Menu

    The Navigation menu (AKA the JumpTo menu) is your one stop shop for all sorts of navigation goodies.

    Place your caret on any symbol in your code and hit Ctrl+Alt+N (or Num Decimal if you’ve enabled numeric keypad bindings)

    NavigateFromClassReference

    I’ve chosen to place my caret on an instantiation of a StringBuilder in the source of OpenLiveWriter. As a result I’m being offered the choice of locating related Base Types, Declaration, Derived Types, Instantiations, Parent Types and more.

    All I have to do to choose one of these options, is highlight one (using Arrow keys) and select it (using Enter).

    Once selected, the Navigation menu will delegate to the appropriate NavigationProvider, which will then list all of the qualifying code elements.

    In my case I’ve chosen ‘Instantiations’ because I’m interested in finding a particular piece of code I was looking at earlier which I know created a StringBuilder.

    When I pick ‘Instantiations’ from the list I get the following window:

    InstantiationsOfStringBuilder

    It looks like OpenLiveWriter uses quite a few StringBuilders within it’s code. However I remember that the code I was looking at, created it’s StringBuilder using the length of a buffer as a parameter.

    So I type ‘buffer’ into the search window at the top of the list, and CodeRush narrows it’s list down from over 100 items, to only 6.

    InstantiationsOfStringBuilderFilteredByBuffer

    From here it was very easy to locate the code I was looking for. Once I found the correct entry, I simply hit [Enter]  and CodeRush positioned me right where I wanted to be.

    Navigation Providers

    As you can see from our worked example, the Navigation menu can be very useful. However I’ve only scratched the surface. I worked through an example with the instantiations entry which, as you saw, provides a list of places where your chosen symbol is instantiated.

    However if you recall the Navigation menu offered me 7 other choices to help us navigate to the code of our choice.

    The last 2 of these are fixed items. Symbols and Files will take us to the Quick Nav and Quick File Nav features respectively.

    The others are Navigation Providers each dedicated to locating a specific type of related code.

    At the time of writing there are 11 NavigationProviders and counting. Each dedicated to a specific type of code relationship. The reason we only saw 6 of them in the previous example is that they are context sensitive. They only appear when appropriate.

    They are:

    • Declaration
    • Base Types
    • Derived Types
    • Parent Type
    • Members
    • Overridden Members
    • Instantiations
    • Implementations
    • Assignments
    • Overloads
    • Overrides

    While all of these providers are useful, I feel it’s worth drawing attention to a few of them in particular.

    Firstly the Assignments provider. How often have you wondered about all the places in your code where a field is altered? The Assignments navigation provider will let you locate all the statements that assign a value to your chosen symbol.

    The Base Types provider will provide you with a list, not just of immediate base types, but of the entire ancestral hierarchy of your nominated type, including interfaces.

    The Implementations provider is particularly useful.
    You can use this one on references to interfaces or abstract classes
    Place your caret on the reference to the interface and ask to see all implementations. Immediately you’ll be presented with a list of classes which implement the interface in question.

    Ordinarily you might think to use the “All References” functionality to locate these classes. However the All References feature does exactly what it says. It returns ALL references and sometimes this can be a bit excessive. For example: Users of VB.net will be used to asking for All References to a given interface, and then having to deal with more results than they might want to. This is because the default interface implementation technique is explicit. As such the name of the interface is mentioned (and thus creates a ‘reference’) for each and every member in that interface. Implementations makes this a non-issue.

    You can also use it on references to interfaces or abstract members
    Imagine you have a variable of type IFoo and are calling it’s Bar method. If you place your caret on the call to Bar and invoke the Implementations Navigation provider, you’ll be provided with a list of every class that implements IFoo and more specifically, the methods that implement IFoo.Bar. You’ll then be able to navigate directly to any one of them.

    Options

    Naturally each Navigation Provider has it’s own custom set of options. These are typically used to filter the available list of items: Source Code vs Meta, Open Files vs All Files

    Just tap Ctrl to reveal the options for any given Navigation provider

    The Navigation Menu is so full of functionality that it’s starting to become the first place I go for almost any form of navigation. I highly recommend you check it out, whatever you’re looking for.

    Can you think of an additional Navigation Provider you’d like to see? Let us know in the comments and we’ll see what we can do to help.

    Oh and one more thing

    The NavigationProvider user interface leaves things simple in the interests of speed. If at any point you’d like to examine the hierarchy of your result set, you can transfer it to the References interface in a new tab by pressing Ctrl+P or clicking the icon in the upper right of the NavigationProvider. Since the References tool window can host multiple tabs, you can maintain several lists of interest at the same time.

    So if you’ve not already got your copy of CodeRush for Roslyn, head on over to the visual studio gallery and grab a copy of our preview now

  • CodeRush for Roslyn: The References Toolwindow

    The CodeRush References tool window is a wonderful thing.

    Place your caret on a symbol and press Shift+F12 asking the question: “Where else is this used?”.
    Next: Navigate the results with the Arrow Keys and Hit Enter to visit the selected reference.

    Consider an example search for all the references to LightweightControlCollection in OpenLiveWriter:

    The VS version of this is ok, but it’s very black and white and isn’t exactly very configurable. 50% of the screenshot below is taken up with the name of the file the code was found in.

    image

    Compare this with CodeRush version and I think you’ll agree, we improved things a lot.

    A Brighter Outlook

    The first thing you’ll notice about CodeRush’s presentation is the introduction of color. In the image below I have stripped away all the hierarchical feature of CodeRush. Even without all of that useful information, you’ll note that it is still easy to pick out XML Doc comments from class declarations, instantiations and constructors. These days we code in color because it helps us discern additional information about the code and the way the compiler sees it. Why should our search be limited to just black and white?

    image

    Hierarchy

    Despite the addition of color, there is still a lot of information to absorb in a list like this. Wouldn’t it be better if we could group the information in some sensible way?

    Well CodeRush has you covered there as well. These 5 toolbar buttons imageallow you to specify which levels to group your references by. From left to right they are: Project, File, Namespace, Type and Member. They can all be toggled independently and provide additional collapsible parent nodes for your results.

    ReferencesWithProjectAndType

    You have complete control over the level of hierarchy you use. See above how I have chosen to use Project and Type nodes in my hierarchy. This immediately expands the amount of horizontal space allocated to the code, rather than the naming of the file in which it sits. Just take a moment to compare this image with the first one.

    Preview

    You can also elect to view a preview of the location of the selected item. Use the following icons image to select between a preview on the right of your results, one beneath or no preview.

    ReferencesWithPreview

    Filter by Usage

    The icons next to each result reflect the type of usage. Either Reads, Writes or New Instances. If you so choose, you can filter your results by the type of their usage. The drop down box in the toolbar will allow you to filter by ‘Reads’, ‘Writes’, ‘New Instances’, or ‘All Usages

    image

    See how the ‘New Instances’ choice reduces my previous list to only 2 entries.

    ReferencesFilteredByNewInstances

    Filter by Text

    You may also filter the items in your results by text. Text entered in the Search box image will cause CodeRush to remove all items that do not contain that text within their entry. See below how I have filtered by the word ‘index’ and removed all but those with this text present.

    image

    Refresh and New Search

    There are 2 final icons that should be explained. image

    The first of these is Refresh. The entries in the References tool window do not update as you alter code. They reflect the state of the code at the moment you engaged the feature. Pressing the Refresh button will execute the original search update the results in the current Tab.

    The second icon is New Search. When pressed, it will leave the existing results in place, and create a new Tab based on the original search criteria. This means that in the new Tab, the Usages drop down will be reset to ‘All Usages’ and the ‘Search’ box will be cleared.

    Each new activation of the References tool window via the Shift+F12 key will cause an additional Tab to be created, allowing you to keep many sets of results active at once.

    The References ToolWindow has never been better. It’s fast, clear and colorful in a meaningful way. With the ability to filter it’s results as well as arranging those results with the hierarchical elements you choose.

    If you’ve not already got your copy of CodeRush, you can find a preview here on the Visual Studio Gallery

LIVE CHAT

Chat is one of the many ways you can contact members of the DevExpress Team.
We are available Monday-Friday between 7:30am and 4:30pm Pacific Time.

If you need additional product information, write to us at info@devexpress.com or call us at +1 (818) 844-3383

FOLLOW US

DevExpress engineers feature-complete Presentation Controls, IDE Productivity Tools, Business Application Frameworks, and Reporting Systems for Visual Studio, along with high-performance HTML JS Mobile Frameworks for developers targeting iOS, Android and Windows Phone. Whether using WPF, ASP.NET, WinForms, HTML5 or Windows 10, DevExpress tools help you build and deliver your best in the shortest time possible.

Copyright © 1998-2017 Developer Express Inc.
All trademarks or registered trademarks are property of their respective owners