mu88 Developer Blog Buy me a coffee

Source Browsing in Rider and R#

Have you ever spotted something in your codebase that either feels odd or that you don’t understand and want to share it quickly with your colleague? Of course, you could call him/her right away and share your screen, but sometimes this doesn’t feel appropriate, and you’d prefer doing it asynchronously (e. g. via Teams or Slack): Hey buddy, could you please have a look at this particular piece of code?

Both Rider and R# (for Visual Studio) allow you creating a URL for the source file so that you can send your colleague e. g. a link to Bitbucket for opening the code in the browser. So let’s see how this can be configured.

Configure Source Browsing

The relevant feature is called Source Browsing and can be used in both R# and Rider. However, R# is necessary for configuration because the corresponding dialog doesn’t yet exist in Rider. Please vote here if you’d like to see it as well ♥

Open the R# settings in Visual Studio and navigate to Environment → Search & Navigation → Source Browsing. Click Add and enter the following values:

  • TitleBitbucket link to $PATH_PROJECT$:$LINE$ (branch '$GIT_BRANCH_NE$')
  • URI patternhttps://my.bitbucket.instance.com/projects/myProject/repos/myRepo/browse/$GIT_PATH$?at=refs%2Fheads%2F$GIT_BRANCH$#$LINE$

As you can see in the dialog, there are a couple of macros/placeholders available. The previous template uses:

  • $LINE$ → the current line within the source file.
  • $GIT_PATH$ → the path of the current file in the Git file system, relative to the Git repo’s root directory.
  • $PATH_PROJECT$ → the path of the current file, relative to the project’s root directory.
  • $GIT_BRANCH_NE$ → the Git branch name, where NE stands for not escaped, i. e. the value for the Git branch feature/my-current-feature remains feature/my-current-feature.
  • $GIT_BRANCH$ → the Git branch name with escaped URL-safe characters, i. e. the value for the Git branch feature/my-current-feature becomes feature$2Fmy-current-feature.

After saving the template, it becomes active in both Rider and R#:

Executing the action copies the following URL into the clipboard:
https://my.bitbucket.instance.com/projects/myProject/repos/myRepo/src/BusinessCore/Extensions/JsonConvertExtensions.cs?at=refs%2Fheads%2Fmaster#8

Another tiny but very helpful JetBrains feature - learning never stops!

Buy me a coffee