.NET Tools Features

Copy Code Reference in ReSharper and Rider 2021.3 EAP

Copy/paste is probably the most used action by anyone using a computer. But how do you copy the thing you want to copy? Say you are in a method in the editor – how do you copy a link to the current line on GitHub? Or copy the current namespace, class name, or method name to the clipboard?

ReSharper and Rider keep you in the flow of coding, without having to jump through hoops to copy this information. With the reworked Copy Code Reference action (previously Copy FQN), you can easily point your fellow teammates to the code you’re talking about and be more productive when writing XML documentation. Most importantly, the action now supports custom URI patterns to integrate with your services of choice. Let’s take a closer look!

Look and Feel

As already mentioned, the action is now available under a new name: Copy Code Reference. If you’re a shortcut person, you can re-apply your keyboard schema (ReSharper | Options | Environment | Keyboard | Shortcut Scheme) and use Ctrl+Shift+Alt+C. Alternatively, you can trigger the action from the Edit menu or by searching the Alt+Enter popup:

Copy Code Reference via Alt+Enter

Since changing muscle memory can be hard, you can still find it using ‘FQN’ in Alt+Enter!

The first item in the list is immediately copied to the clipboard, so you can confirm either by pressing Enter or Escape. More importantly, the items now have dedicated icons to reflect what information they represent. There are icons for namespaces, types, members, and files.

Now you have the choice to pick the format that works best for your use case. For instance, when you want to point your fellow developers to a symbol, you can pick either the fully-qualified name or File:Line item to allow them to navigate with Search Everywhere in ReSharper and Rider. If they should just take a quick look or are on their phone and don’t have their IDE available, the GitHub links based on the branch or commit SHA may also work. Last but not least, when you’re writing XML documentation, you can copy the fully-qualified XML-Doc ID and paste it where it belongs:

Copy XML-Doc ID

Also good to know for Rider users – you can start typing to filter the result set:

Filtering in Copy Code Reference

Adding Custom URI Patterns

Not all repositories are hosted on GitHub, so we have also added a new Source Browsing options page that allows you to add custom URIs to the list of targets to pick from. The options page can be opened via the last item from the Copy Code Reference action, or through the ReSharper options (Environment | Search & Navigation). The following image provides a few examples:

Custom URIs for Source Browsing

For custom URI patterns and their titles, you are free to use any number of macros that we provide, including:

$PATH_SLN$Path to file relative to the solution
$PATH_PROJECT$Path to file relative to the project
$GIT_PATH$Git: Path to file relative to the Git root
$GIT_REVISION$Git: Revision
$GIT_BRANCH$Git: Branch
$FILENAME$Filename with extension
$LINE$Current line
$COL$Current column
$LINE_START$First selected line
$LINE_END$Last selected line
$OUTPUT_NAME$Output assembly name of the current project
$UPSOURCE_RANGE$JetBrains Upsource selection range

Remember that it’s a good idea to save your custom URIs to the team-shared layer and commit them to the repository to let your whole team benefit from them!

Saving custom URIs to the team-shared layer

We hope that you will make good use of the new Copy Code Reference action to be more flexible when sharing your context or writing any kind of documentation! Give it a go with the latest ReSharper or Rider EAP and let us know what you think!

Discover more