Visual Studio 2015 Feature series: #3 code Editor Enhancements

September 3rd, 2015 | Posted by Vidya Vrat in .NET | Visual Studio 2015

Visual Studio 2015 Feature Series #1 Account Management
Visual Studio 2015 Feature Series #2 Window Layouts
Abstract
An IDE’s Code Editor is every developer’s playground. Being a developer requires a lot of seeing, thinking and coding of course. This is the place where most of our time is spent in various activities. I learned that small things make big difference. This article will explain some of the code editor enhancements made in Visual Studio 2015 to improve developer’s productivity; which will help the developers to code better, to see better and even have better touch support if you are working on a touch enabled device.
Colored Tool Tips
Tool tip is a useful feature when a developer want to look at preview of a code segment; by placing mouse pointer over the collapsed construct such as class definitions, structure definitions, and method bodies. Visual Studio 2015 enhances the too tip view by showing colors as per the usage of code, keywords and types etc. If you hover mouse on a type and observe the preview generated then you will notice that code is hard to read and figure out the type, keywords and code etc. are in plain black color as shown below in Figure-1.

Figure-1: Plain Black Tool tip preview in Visual Studio 2013 This has served the purpose for many years but it doesn’t give proper visual clues on types, keywords and code used. Now let’s have a look at Visual Studio 2015 Tool tip as shown in Figure-2 below.

Figure-2: Colored Tool tip preview in Visual Studio 2015

Light Bulb and Quick Actions

Writing code is not easy and at times, some small productivity enhancement tips have big impact and give you some free time and take you away from thinking through of everything in terms of solving every error. What if Visual Studio code editor can itself suggest some actions; to resolve the issue? For instance, have a look at the Figure-3 shown below in which Visual Studio 2013 is showing an error when used ITest; which requires to explore some possible options to fix the issue on your own.

Figure-3 Visual Studio 2013 Now, consider the same scenario in Visual Studio 2015, when you hover mouse on ITest then you will see a “Light Bulb” which will lead you to possible solutions, and this is really productive way of programming.  Figure-4 Visual Studio 2015, Light Bulb

Removing Un-used Using

One of the best coding practice is to remove all un-used using statements from your code. The easiest way for a developer has always been to use the option “Organize Usings” because Visual Studio code editor was not telling you while coding; that which using is not being used. I.e. as shown in Figure-5 below shows that all using are being used until a developer try to invoke “Organize Usings”.

Figure-5 using in Visual Studio 2013 Visual Studio 2015 made this using business very institutive and developer friendly, so as soon as you start adding using statements you will know immediately if that is being used or not and you can remove those very quickly with much fewer steps in comparison to prior Visual Studio code editors.

Figure – 6 Greyed out using statements in Visual Studio 2015 Now, it’s also easy to remove un-used using statements. Just hover mouse on using statements and click on the “Light Bulb”.

Figure – 7 Using Light Bulb to remove un-used using statements

Inline Rename

I have personally found that “Rename” is the most widely used Refactoring option as many times you want to rename something in your code either due to self-realization or to address a code reviewer comment. Before Visual Studio 2015, the “Rename Workflow” was quite tedious and lengthy workflow, let’s quickly have a look via Visual Studio 2013. Let’s say in the code below; we want to rename msg variable to message and preview the changes before it’s applied on the code. static void Main(string[] args) { string msg = “Hello from C# Console App”; Console.WriteLine(msg); } In Visual Studio 2013, you need to hover on msg, Right-click and select Refacor à Rename then a dialog will pop-up as shown in Figure-8 below.

Figure-8 Visual Studio 2013 Refactor à Rename Now when you proceed by clicking on OK button, the workflow continues and you will see a screen as shown in Figure-9 below, highlighting all potential changes to be made if you choose to Apply rename on those.

Figure-9 Visual Studio 2013 Preview Changes (Rename) After changes are applied across the code, the code will now appear as shown below classProgram { static void Main(string[] args) { // msg Renamed to message string message = “Hello from C# Console App”; Console.WriteLine(message); } } Now let’s review this Rename process through Visual Studio 2015, in Visual Studio 2015 Rename option is available right away in the context menu as shown in Figure 10 below.

 

Rename from context menu Now when you click on the Rename it will highlight all the msg instances in code as shown in Figure-11 below.

Figure – 11 Preview of rename in action

Now click on msg (First green selected instance) and start renaming it to message for instance as shown in Figure-12 below. 

Figure – 12 Inlined Rename in action

If you want to proceed with the code changes then click “Apply” on the dialog shown in code editor window and now code will be shown as below. classProgram { staticvoid Main(string[] args) { // msg Renamed to message string message = “Hello from C# Console App”; Console.WriteLine(message); } }

Touch Gestures

Touch Gestures is a powerful feature and can come handy occasionally; especially when you are either doing some R&D or reviewing a code or thinking of code enhancements using a touch-enabled device. If you are not coding and want to read through code and performs some basic operations then following touch gestures are supported by Visual Studio 2015 on a touch-enabled device.

  • Pinch and zoom; to zoom in and out with thumb and index fingers.
  • Single tap the margin of the code editor to select the line of code where you tapped.
  • Double-tap a word or an identifier to select it.
  • Press and hold on empty screen area to open the context menu.
  • Tap and hold anywhere on the code editor’s surface to scroll up and down.

 

 

You can follow any responses to this entry through the RSS 2.0 You can leave a response, or trackback.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.