четверг, 4 декабря 2014 г.

My three real use cases of Type Dependency Diagram in ReSharper 9.0

Hi all!

As you may know, the new 9.0 version of ReSharper has the ability to show the dependencies between different types (classes, structs, interfaces, both from the source code or from assemblies) in a nicely layouted diagram. Frankly speaking, I'm not a big fan of diagrams, but it turned out that some cases can be really displayed in a diagram much more efficiently than via some old-school tools (tree presentation, or a plain list). For instance - 'Project Dependecny Diagram' in ReSharper 8 which can be really efficient in observing the architecture of my solution.

Lots of stuff can be done, by using new ReSharper type dependency diagram, but in this short article I want to share my 3 real use cases of how the Type Dependency Diagram can be used. Used for a real software engineering tasks, not for useless formal reports.

1. Observing

First of all this feature allows me to understand others code much more easily. Most often the specific subsystem's source code is located in a separate project or in a folder, or even in a bunch of projects located in a special solution folder. In all this cases I can build type dependency diagram easily from the Solution Explorer context menu.

If my initial scope of types is not big (~15 types) the diagram can really help with understanding what is going on here. It shows usages, aggregation and inheritance dependencies by default and I can also include so called 'Return type' and 'Ctor injection' usages.

If the scope of types I'm going to investigate is too big, there is no sense to display all these in on diagram - it would be just a useless mess. However, what might be useful is to group the big diagram by project structure, so the diagram will show me which folders depends on which.

The popup on the screenshot above is shown just after I hover the mouse on a folded edge. It can show me briefly what types are referencing each other, but of course I can expand folded node and see whole overview.
There are several ways to add more types to the diagram
1. Drag n drop files, folders, projects from Solution Explorer to the Diagram
2. Embedded Go-to-type that either navigates to already displayed types or adds new ones. Btw, I don't need even to place a caret there. Just start typing and that's it.
3. Rich Popup UI that allows me to add all related types to the specified node (both type's and project folder's nodes)
4. Drag'n'drop from text. For instance I can select the text with a type's name and drop it to the canvas.

2. Understanding the usage of external modules

Actually you might already knew about 'Show Modules External to Scope' ReSharper's feature and used it to investigate external usages of a module. The problem with this feature is its representation. You cannot really display many-to-many relations in a tree view. So on diagram I can explore such relations much more easily. To do that I can open a context menu on assembly reference(s) in Solution Explorer and click 'Show Usages On Diagram' button

For instance, I would like to see how do I use WPF libraries in my project. And ReSharper 9.0 solves this task pretty well. The following screenshot illustrates what I've got on the diagram:

Observing such diagrams is super easy for me and definitely much easier that exploring a tree view based UI.

3. Move to folder refactoring via Drag'n'Drop

ReSharper's 'Move to folder refactoring' is one of my favorites. It's priceless when I have to move lots of code between the projects in a big solution. In brief, ReSharper automatically analyzes and displays all possible conflicts for the desired move, then physically moves and updates all usages across the whole solution. So it turned out for me that this powerful refactoring is super efficient on a diagram!  Mostly because I don't need to look through a huge Solution Explorer's tree to find a specific project folder - all needed project folders are already on the diagram.
In the following example the class ReSharperDaemonVsBulbRemover is located in VB language folder - which is incorrect, it should be move up. Instead of searching the name of a parent folder, now I can perform a refactoring just with a single move.

ReSharper will notice me on any refactoring to avoid unnecessary drops :) I can also uncheck the toggle button to disable this functionality at all. In this case move a dragged node will just expand the container which might be useful for layouting purposes.

These are the most used cases for me personally. However I think that this tool might be useful for other real use cases. If you have some - please share!:)

суббота, 24 декабря 2011 г.

Optimizing assembly references with ReSharper 6.1


Today I'm going to talk about new features of ReSharper 6.1th version, which allow you to easily manage your existing assembly references, see referenced assemblies usages, and remove unused references.

Three new features are coming along with a new 6.1 version of ReSharper:

1. Optimize References

Optimize References is a main feature for analyzing your referenced assemblies. This feature can be called on a single project and displays this module's unused and used assembly references. It does not require your project to be compiled, so you can call it even if your project is currently broken.

One of the coolest things about this feature is that it allows you to see usages of a concrete referenced assembly, namespace or type, filter them by their kind, group them and navigate from them directly to your source code. On the screenshot below is illustrated why exactly my project references System.Drawing.dll and what types of that assembly are used and where.

Different icons mean different usage kinds like read, write, attribute, invocation and other kinds of usages familiar to you from ReSharper's navigation features. However, one kind of usages is unique for Optimize References. This kind of usage is called 'compiler related usage' and indicates implicit (non-direct) assembly reference usages required for compiler.
The simplest case is the case when related usages are caused by a type's hierarchy. That is, if you use a type, then you have to reference all assemblies containing this type's supertypes. Unfortunately, this is just one example of many other much more complicated ones... :)

Besides just observing, you can delete unused assembly references directly from this tool window. You just need two buttons to remove all unused references or just selected.

Note that this feature will also delete all redundant C#, VB.NET or XAML namespace import directives, which reference namespaces from the removed referenced assemblies.

2. Remove Unused References refactoring

This refactoring quickly detects unused assembly references without displaying their usages. It works faster than Optimize References. It is very useful if you do not want to analyze usages but just want to quickly clean up your project references.

'Analye Used References...' button will open Optimize References tool window.

3. Safe delete on assembly references refactoring
That is, now you can press Alt+Del on the selected assembly references from Solution Explorer. They will be either silently removed, or you will get a window indicating that some of the selected references are used.

These three features introduced in ReSharper 6.1 will definitely help you to manage your references. By the way, if you want to observe code referenced in the scope, other than project (for example, folder or method's body), you can use ReSharper's 'Find Symbols External To Scope' and 'Find Dependent Code' features.

понедельник, 30 мая 2011 г.

New 'Go To ...' features in ReSharper 6 and dotPeek

Hi all!

If you are familiar with R# then you probably use its powerful navigation features - sophisticated context navigation (just look at 'Navigate To' dialog) and powerful 'Go To ...' navigation. All these features make you almost forget about Solution Explorer, allowing to instantly move through your solution.
Today I'm writing about the new concept of 'Go To ...' navigation in R# 6, that will make your navigation even more precise and powerful.
To be simple, in R# 6 you can type multiple words in 'Go To ...' dialogs.  In different dialogs semantics of words is different, but the main idea remains the same : now you can search something inside something inside something and so on.

Let's start with 'Go To Symbol' dialog. In this dialog words correspond with entities in your code model: namespaces, type elements (classes, structs, delegates) and type members. The words you type in a dialog match all of these entities in hierarchical order (from left to right).

You can search type members even inside namespace without typing an extra word for a type element. For example, this might be very useful in case you have a huge hierachy with a lot of clients overriding  method with the same name.

Advanced users maybe know that in 5.1 version they could use a whitespace for 'tail matching'. Since in R#6 whitespace has other semantics, you can use '\' symbol for tail matching.

Another productivity hint that for me personally saves a lot of time:  often you want to navigate to a type's member, but you don't know the exact method's of file's name in that class. The common behaviour in R# 5.1 would be: Go to type -> Navigate to your type -> Go to File Member -> Navigate to your member. In R# 6, since you have combos, you can  just type your type's name and add a whitespace after. You will get all type members without first navigating to a type.

Combos work for external sources as well, and you can use absolutely the same features in dotPeek - new .net Decompiler from JetBrains.

'Go To Type' dialog uses the same idea, but without navigating to your type members, words correspond to namespaces and type elements.
Both in 'Go To Symbol' and 'Go To Symbol' you can use either ' ' or '.' as a delimiter. This means that these dialogs will find results by FQN.

'Go To File' dialog searches through your project model, allowing you to find files, projects and all kinds of folders inside each other. You can use ' ' or slashes ('\', '/') as a delimiters.

All of these features improve global 'Go To ...' navigation and make it even more powerful than before.
Stay tuned!

среда, 4 мая 2011 г.


Hi all!
My name is Kirill, I am working in JetBrains company in ReSharper team as a software developer. Mostly here I will try to post something about our great products but will write some stuff about zombies as well:)
Hope this will be interesting!