Alternative ReSharper functionality within Visual Studio 2017

Visual Studio 2017 is finally here and I’ve been using it since it went public. There’s many features to discover and among them are some improvements in code navigation and refactoring which is what I’m covering in this post.

To me the the thing that stands out the most is the CTRL+T key binding, which is ReSharper’s binding for “Go To Everything”. Whether that’s a nod to the ReSharper team or just a nice feature for developers moving from one environment to another is anyone’s guess. In any case,  it doesn’t matter. Some developers I’ve spoken to have all said the same sort of thing, and that is, Microsoft is “taking on” ReSharper. For me nothing could be further from the truth. For me it’s about making the experience more approachable and if that means getting some inspiration from another product then that’s totally OK. This just makes the out-of-the-box experience more enjoyable, especially for those using the community edition.

Go To Everything aka “Go To All”

The feature I use 99% of the time in ReShraper is “Go To Everything”. A similar feature has existed in Visual Studio since 2010 and was named “Navigate To”. VS2017 now comes with a much better version, named “Go To All” and is bound to the keyboard shortcut CTRL + T as well as CTRL + , and includes inline filtering and “fuzzy search”. Like ReSharper, you can enter in partial names of classes or methods. For example, you could enter something like  “co wri” to search for “Console” and “Writer” and be presented with possible matches.

It’s not exactly centre screen which means it takes your eyes away from the code, but it’s a minor thing. There is one aspect which I like over ReSharper’s implementation, and that is it gives you inline help to filter on what you want to search. In ReSharper you’d typically do a CTRL + SHIFT + T to find Types or SHIFT+ALT+T to find Files. In this interface you can do it all from the one and without a separate shortcut.

Combining those filters with the example I presented above, you can add a filter to that fuzzy search. In this example I’m only interested in types, so I prefix the search with a t.

One thing Go To All can’t do, which ReSharper can, is specify a class name and the line number, such as ProductRepository:25 or even ProductRepository 25. It will then open that file and go to that line number. In Go To All, you can go to a line in the current file by typing :123.

For reference here’s what Navigate To it used to look like in earlier versions of Visual Studio.

Visual Studio 2015

Other ReSharper Goodies

Not an exhaustive list, but my frequently used favourites.

  • Filtered types and members can also include library types
    • If library types are found, clicking on them opens the decompiled source code
  • Go to class or interface with line number
  • Go to member in the current file (CTRL + \)

Visual Studio Features

  • Filtering by prefixing searches with a character
  • Fuzzy searching
  • All in one search across files, types and members

Update 2017-04-25

An update to ReSharper version 2017.1 now implements inline filtering just like Visual Studio by prefixing the search with a forward slash /.

Go To Implementation

Although I covered this in my last post, it’s worth another mention as the UI has been improved. If you press CTRL+F12 on a class or interface in Visual Studio, it will now show you a code snippet of the implementation. In VS2015 it only showed the file, line number and class name of the implementation.

Visual Studio 2017

You can then choose how to group them.

For reference here’s what it used to look like.

Visual Studio 2015

Find all references

This one I also covered in my last post, but once again, the UI has had a face-lift.

Pressing SHIFT+F12 now opens up a listing of types, files or properties. It depends what you’re finding a reference to.

In this example I placed my cursor on the set accessor of an Email property and got nice listing with a code snippet. Awesome. This is closer to how ReSharper displays its detailed find, which is also SHIFT+F12.

One thing to note here is that previous versions of Visual Studio didn’t let you find references based on the set or get accessor of a property, although ReSharper has had this for quite some time.

Visual Studio 2017

You can then choose how to group them.

For reference here’s what it used to look like.

Visual Studio 2015

Extract Method

Covered in my last ReSharper post, the extract method has had a face-lift, and like ReSharper, can be accessed with CTRL+R, CTRL+M.

This one caught me out a little. When you first press the shortcut keys it will instantly extract the code out into a new method called NewMethod but then another dialog appears which allows you to rename the method and then preview changes. From here you can choose to not modify parts of the code with the new method name which is very odd.

In this example I’ve renamed the method to FooMethod but I’ve chosen not to rename the code which calls it, which would generate a compile time error. I might be missing something here but I can only see one or two use cases where I would want to do this.

Visual Studio 2017

For reference here’s what it used to look like.

Visual Studio 2015

Final Words

I’ve only scratched the surface on the improvements in Visual Studio. It definitely gives beginners or people who don’t have the money for a ReSharper license a better out-of-the-box experience.