ReSharper, day 11: Code navigation
Welcome to day 11 of my 31 Days of ReSharper.
Today’s topic is navigation through the code. I’ll cover three ReSharper features: the Navigate From Here context menu; the gutter icons; and Go To Declaration.
Navigate From Here context menu
One of the cool things about ReSharper is that they have more than one context menu. They have a couple of keystrokes that bring up targeted context menus, so instead of “everything you might possibly want to do here”, you can see “everything you might want to do related to code navigation” or “everything you might want to do related to refactoring”. (The kitchen-sink context menu is, of course, still available.)
These targeted context menus are a great compromise between brain capacity and coding speed. It’s easy to get started, because you only need to learn one keystroke for a whole group of features. But since each item in the context menu is just another command, and many of them have their own shortcut keys (which are shown on the targeted context menus, unlike the main context menu), you can gradually learn the specific shortcut keys for the features you use all the time, and can access those features even faster.
Here’s an example of the “Navigate from Here” context menu, which you can access with Ctrl+Shift+G:
Being a context menu, it only shows you the commands that make sense based on the current cursor position. So if you’re on a class name, it will show you different options than it would if you were on a method name or a namespace name.
I haven’t used all of these options, but my current favorite is Inheritor. When you’re in code that’s calling a method on an interface, this will show you a list of all the classes that implement that interface method:
It’s even cool enough that if those interface implementations are virtual, it’ll include the descendant classes that override that method. First-level overrides (classes that implement the interface) are shown in bold. Second- and later-level overrides (descendants that further override the method) are non-bold.
Gutter icons
I don’t use this one very often, because it only goes upstream, which is easy enough anyway; and you can do the same stuff with Navigate From Here. But it’s worth noting.
ReSharper shows gutter icons next to method declarations that have something to do with the base class (or an implemented interface). So if method Foo overrides a method in the base class, there’ll be one sort of icon. If it shadows, there’ll be a different icon. If it implements an interface, there’s an icon for that too.
ReSharper’s gutter icons. Shown are an interface implementation, an override, and a shadowed method.
(Come to think of it, I should start looking at these icons. The green “I” is a good visual indicator of which methods on a class come from an interface — not something you can otherwise tell just by looking.)
You can also click these gutter icons to jump to the relevant ancestor method. Sounds nice, but I hardly ever use it; I usually end up at the base class without trying! (Template methods are nice for removing duplication, but they can be a hassle for navigation.)
Go To Declaration
This is one of the keystrokes that changed when you installed ReSharper. What used to be F12 is now Ctrl+B; you can also Ctrl+Click on an identifier.
Apart from the keystroke, this works exactly like the Visual Studio version (jump to the interesting bit of code), with one difference. The difference comes up when you’re on an identifier that you don’t have source code for, such as something from a Microsoft assembly. VS and R# both show you a representation of the defining code, but…
ReSharper shows you the old Class Browser, which is klunky and a real pain to use:
It actually does this for all its code-navigation features, not just Ctrl+click. For example, clicking a gutter icon can also land you in the Class Browser.
Visual Studio 2005, on the other hand, has a nifty new feature to show the class’s metadata as code (the “[from metadata]” feature), which replaces the Object Browser in all cases except those relating to ReSharper:
I think Visual Studio’s code view is far superior, for two reasons:
-
The Class Browser sucks for navigation. For example, suppose I’m looking at Graphics.DrawImage (see the Class Browser screenshot, above) and I see that it takes a parameter of type Image. What if I want to jump to the Image class to see what methods it has? In the code view, it would be just a Ctrl+click away. But since ReSharper sticks us with the Class Browser, where the important information is split across three different panes, you have to know to first click on the right overload in the top-right pane, and then find the parameter type in the XML doc comments in the lower-right corner and click the hyperlink there. (For a long time, I didn’t even realize there was a way to jump to the parameter type using the Class Browser; I just figured it out while I was writing this.)
-
The code view looks like code. It’s familiar; I’m used to it; I know exactly how to get around in it. Code is what I work with every day. Why on earth would a productivity tool like ReSharper choose to make me less productive by forcing me to learn another GUI for the exact same thing, when there’s already a better alternative?
I wish ReSharper used the new code view, and I’ve sent in a feature request to that effect. Their response was that, since you can still access VS’s “Go to Definition” from the context menu, they’re going to leave it the way it is. I find this disappointing, especially since it’s not just “Go to Declaration” that’s stuck with the klunky Object Browser — it’s everything in ReSharper related to code navigation.
(If you use ReSharper and this has been frustrating you too, let them know.)
</rant>



![Visual Studio shows you the metadata as code, in a '[from metadata]' window](http://blog.excastle.com/images/resharper/FromMetadata.png)
February 12th, 2007 at 2:55 am
I’ve create request for [from metadata] support, thanks for suggestion. You can track its status here:
http://jetbrains.net/jira/browse/RSRP-35547
February 12th, 2007 at 11:11 am
Just added my vote to jira and a comment that adds a link to this blog post.
Christian
February 12th, 2007 at 12:06 pm
Strange.. I find the Class browser better than the metadata view.. the classbrowser also shows you the doc.. and I like Reflector’s way of showing this information, easy to navigate with, Class browser is closer to that, than the metadataview..
February 13th, 2007 at 5:13 am
The code view also shows you the doc, just in a different form (as comments instead of a separate pane).
I guess "easy to navigate with" is in the eye of the navigator. I find code easier to think about than treeviews, given a choice, especially since I’ve already learned how to navigate around code.
June 12th, 2008 at 6:02 am
Has the issue with the object browser been fixed? Is this settable? I thought it was, but I can’t remeber. Object browser sucks!
June 12th, 2008 at 6:31 am
I just looked through the options and couldn’t see anything for using the code view instead of the Class Browser. I’m still on the 4.0 beta, not the 4.0 release that came out a few days ago, but I expect it’s the same.
Send them a ReSharper enhancement request! The more people they hear from, the more likely they are to fix it.
June 12th, 2008 at 8:33 am
I hate it when something I was using before is removed because Resharper decides it should be so.
What I want to see when I use F12 or Go to Declaration is the pseudo source code based on metadata. If Resharper wants to offer something else, such as quick access to the object browser, then it should use another keyboard shortcut, and at any rate it should not remove the Visual Studio feature, as is the case now.
I wish they’d provided a quick-fix for this for Resharper 3.1. But unfortunately, it seems that it’s not fixed in 4.0 either.
June 12th, 2008 at 10:50 pm
I’m with ya. Make sure you’ve sent them feedback to let them know.
June 23rd, 2008 at 8:10 am
I am with those in favour of the ‘from metadata’ style, or at least the option. With resharper installed and overidden context items shown even selecting Goto Definition still shows the object browser.
My particular problem was trying to extract an interface to a 3rd party concrete class with a lot of methods that I want to abstract away by enclosing it in a wrapper class so that I can substitute it for a mock in unit tests where I interface with the 3rd party object.
Since even resharper does not enable Extract Interface when right clicking in the object browser or on the class name of the 3rd party class I was stuck.
At least the metadata code view gives me the option of copying and pasting the code into my own class which I can then extact the interface from.
I have already sent the my feedback to JetBrains, including the suggestion of being able to generate a wrapper class as well as the interface.
June 25th, 2008 at 5:53 am
Chris W: Have you tried creating a class, adding
: TheInterface, and then putting the cursor inside the method body and pressing Alt+Ins to implement the interface members? Does that get you what you were looking for?July 5th, 2008 at 8:46 pm
This request has my vote.
August 1st, 2008 at 12:26 pm
This request definitely has my vote. Metadata is a lot more useful than the object browser, especially in .NET 3.0. Hopefully Resharper will not block “F12″ and “Go to Definition” menus, but at least give us a shortcut.