Export (0) Print
Expand All

Find code changes and other history with CodeLens

Visual Studio 2013

Stay focused on your work while you find out more about your code when you use CodeLens in the Visual Studio Ultimate editor. Find code references, changes to your code, linked bugs, work items, code reviews, and unit tests – all without leaving the editor.

CodeLens indicators in the code editor

To discuss the code's history with your team, contact them from inside the editor:

CodeLens - Contact your team

To choose which indicators that you want to see, go to Tools, Options, Text Editor, All Languages, CodeLens.

You'll need:

  1. Choose the references indicator (Alt + 2):

    CodeLens - Choose references indicator

    When there are 0 references, this only means that you have no references from Visual C# or Visual Basic code. This doesn't include references from other items, such as XAML and ASPX files.

  2. To show the referencing code, move your mouse on top of the reference or double-click it:

    CodeLens - Peek reference

  3. To see relationships between this code and its references, create a code map.

    CodeLens - References on code map

To learn how your code got into its current state, review its history. To understand how changes in other branches might affect your code, review those changes before they're merged into your code.

You'll need:

Find who changed your code (Alt + 4) either in Team Foundation version control (TFVC):

Get change history for your code in TFVC

Or in Git where you can also see when changes were last made.

Get change history for your code in Git

To get more details about a change, right-click that item, then click View Details. Those details appear in Team Explorer.

Suppose your team has multiple branches - a main branch and a child development - to reduce the risk of breaking stable code:

CodeLens: Find when your code was branched

Find how many changes were made to your code (Alt + 6) in your main branch:

CodeLens: Find how many changes in your branch

Or how many people changed your code (Alt + 4):

CodeLens: Find how many people changed your code

If a plus sign (+) and another number appear next to the changes indicator or authors indicator, then your code has more recent changes in your current branch of TFS.

Go to your code in the child branch, for example, the Dev branch here. Choose the changes indicator (Alt + 5):

CodeLens: Find when your code was branched

CodeLens: Find code changes in other branches

…like this bug fix in the Dev branch here:

CodeLens: Change checked into another branch

You can review this change without leaving your current branch (Main):

CodeLens: See incoming change from another branch

So you can see which changes are included in your branch:

CodeLens - Merged changes between branches

For example, your code in the Main branch now has the bug fix from the Dev branch:

CodeLens - Merged chagnes between branches


Where did the change come from?

CodeLens: Change from current branch icon

The current branch

CodeLens - Change from parent branch icon

The parent branch

CodeLens - Change from child branch icon

A child branch

CodeLens - Change from peer branch icon

A peer branch

CodeLens - Change from branch further away icon

A branch further away than a parent, child, or peer

CodeLens: Merge from parent icon

A merge from the parent branch to a child branch

CodeLens: Merge from child branch icon

A merge from a child branch to the parent branch

CodeLens: Merge from unrelated branch icon

A merge from an unrelated branch (baseless merge)

To get an idea about the test coverage of your code, find the unit tests for that code. You'll need:

  1. Go to application code that has unit tests.

  2. Review the tests for that code (Alt + 3).

    CodeLens - Choose test status in code editor

  3. If you see a warning icon CodeLens - Unit tests not yet run warning, run the tests.

    CodeLens - View unit tests not run yet

  4. To review a test's definition, double-click the test.

    CodeLens - Choose a unit test

    CodeLens - Go to unit test definition

  5. Review the test’s results. Choose the test status indicator (CodeLens - Unit test failed icon or CodeLens - Unit test passed icon), or press Alt + 1.

    CodeLens - See unit test result

  6. To see how many people changed this test, who changed this test, or how many changes were made to this test, find the code's history.

Yes, you can choose to see or not see any of the indicators, except for the references indicator. Go to Tools, Options, Text Editor, All Languages, CodeLens.

Turn CodeLens on or off

When the indicators are turned on, you can also open the CodeLens options from the indicators.

CodeLens - Turn indicators off or on

A: CodeLens indicators appear only in Visual C# .NET or Visual Basic .NET files and only for methods, types, indexers, and properties.

  • Make sure they're turned on under Tools, Options, Text Editor, All Languages, CodeLens.

  • Make sure that code indexing on your Team Foundation Server is turned on by using the TFSConfig tool and CodeIndex Command. See Managing server configuration with TFSConfig.

  • TFS-related indicators appear only when work items are linked to the code and when you have permissions to open linked work items. Confirm that you have team member permissions.

  • Test status indicators don't appear when application code doesn't have unit tests. Test status indicators appear automatically in test projects. If you know that your application code has unit tests, but the test indicators don't appear, try building the solution (Ctrl + Shift + B).

This might happen because CodeLens can't find the work items in TFS. Check that you're connected to the team project that has those work items and that you have permissions to see those work items. This might also happen if the commit description has incorrect information about the work item IDs in TFS.

A: If you're not signed into Lync, don't have it installed, or don't have a supported Lync configuration, the Lync indicators won't appear, but you can still send mail.

CodeLens - Contact changeset owner by mail

CodeLens - Contact changeset owner by mail

CodeLens - Send mail about a changeset

Which Lync configurations are supported?

  • Lync 2013 (32-bit or 64-bit), either alone or with Office 2013

  • Lync Basic 2013 alone (32-bit or 64-bit, but not with Windows 8.1)

  • Lync 2010 alone (32-bit or 64-bit)

CodeLens doesn't support having different versions of Lync installed. Lync might not be localized for all localized versions of Visual Studio.

A: Go to Tools, Options, Environment, Fonts and Colors.

CodeLens - Change font and color settings

To use the keyboard:

  1. Press Alt + T + O to open the Options box.

  2. Press Up Arrow or Down Arrow to go to the Environment node, then press Left Arrow to expand the node.

  3. Press Down Arrow to go to Fonts and Colors.

  4. Press TAB to go to the Show settings for list, and then press Down Arrow to select CodeLens.

A: The authors indicator shows how many people changed this code. The changes indicator shows how many changes were made to this code. Both indicators show the same change details.

A: The way you refresh the indicators varies by indicator:

  • References: The indicator updates automatically when the code changes but must be refreshed manually when docked in a separate window.

    CodeLens - Dock as window

  • Team: You can update these indicators, which include changes, authors, work items, bugs, and code reviews, directly from the indicator line.

    CodeLens - Refresh indicators

  • Test: To update the test status, run all of the tests or specific tests.

A: Yes, choose CodeLens - Dock as a window to dock CodeLens as a window.

CodeLens - Dock as window

A: The Local Version arrow points at the most recent changeset in your local version of this file. When the server has more recent changesets, they appear above or below the Local Version arrow, depending on the order used to sort the changesets.

© 2014 Microsoft