Find code changes and other history with CodeLens
Stay focused on your work while you find out what happened to your code - without leaving the editor (requires Visual Studio Ultimate). Find references and changes to your code, linked bugs, work items, code reviews, and unit tests.
Contact your team about these changes without leaving the editor:
To choose which indicators that you want to see, go to Tools, Options, Text Editor, All Languages, CodeLens.
Find references to your code
You'll need:
Visual Studio Ultimate
Visual C# .NET or Visual Basic .NET code
The most recent Visual Studio 2013 update so that you can work with solutions that share code across multiple apps
Choose the references indicator (Alt + 2):
When you have 0 references, you have no references from Visual C# or Visual Basic code. This doesn't include references from other items, like XAML and ASPX files.
To view the referencing code, move your mouse on top of the reference or double-click it:
To see relationships between this code and its references, create a code map.
Find your code's history and linked items
Review your code's history to find out what happened to your code. Or, review changes before they're merged into your code, so you can better understand how changes in other branches might affect your code.
You'll need:
Visual Studio Ultimate
Team Foundation Server (same version) or Visual Studio Online
Visual C# .NET or Visual Basic .NET code that's checked into Team Foundation Server or Visual Studio Online using Team Foundation version control (TFVC) or Git. If your Git repository is hosted in TfGit, then you can also find links to TFS work items.
The most recent Visual Studio 2013 update so that you can also find changes in other branches and work with solutions that share code across multiple apps
Lync 2013, Lync Basic 2013, or Lync 2010 to contact your team from the editor
Find changes in your code
Find who changed your code (Alt + 4) either in Team Foundation version control (TFVC):
Or in Git where you can also see when changes were last made.
To get more details about a change, right-click that item, then click View Details. Those details appear in Team Explorer.
Find changes in your current branch
Suppose your team has multiple branches - a main branch and a child development - to reduce the risk of breaking stable code:
Find how many changes were made to your code (Alt + 6) in your main branch:
Or how many people changed your code (Alt + 4):
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.
Find when your code was branched
Go to your code in the child branch, for example, the Dev branch here. Choose the changes indicator (Alt + 5):
Find incoming changes from other branches
…like this bug fix in the Dev branch here:
You can review this change without leaving your current branch (Main):
Find when changes got merged
So you can see which changes are included in your branch:
For example, your code in the Main branch now has the bug fix from the Dev branch:
Compare an incoming change with your local version (Shift + F10)
You can also double-click the changeset.
What do the icons mean?
Icon |
Where did the change come from? |
---|---|
The current branch |
|
The parent branch |
|
A child branch |
|
A peer branch |
|
A branch further away than a parent, child, or peer |
|
A merge from the parent branch to a child branch |
|
A merge from a child branch to the parent branch |
|
A merge from an unrelated branch (baseless merge) |
Find linked work items (Alt + 7)
Find linked code reviews (Alt + 8)
Find linked bugs (Alt + 9)
Contact the owner of an item (Shift + F10)
Find unit tests for your code
Find out more about unit tests that exist for your code without opening Test Explorer. You'll need:
Visual Studio Ultimate
Visual C# .NET or Visual Basic .NET code
A unit test project that has unit tests for your application code
The most recent Visual Studio 2013 update so that you can find changes in other branches and work with solutions that share code across multiple apps
Go to application code that has unit tests.
Review the tests for that code (Alt + 3).
If you see a warning icon , run the tests.
To review a test's definition, double-click the test.
Review the test’s results. Choose the test status indicator ( or ), or press Alt + 1.
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.
Q & A
Q: How do I turn CodeLens off or on? Or choose which indicators to see?
A: You can turn indicators off or on, except for the references indicator. Go to Tools, Options, Text Editor, All Languages, CodeLens.
When the indicators are turned on, you can also open the CodeLens options from the indicators.
Q: Where's CodeLens?
A: CodeLens appears only in Visual C# .NET and Visual Basic .NET code at the method, class, indexer, and property level.
Make sure CodeLens is turned on. Go to Tools, Options, Text Editor, All Languages, CodeLens.
If your code is stored in TFS, make sure that code indexing is turned on by using the CodeIndex command with the TFS Config command.
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.
Unit test 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).
Q: Why don't I see the work item details for a commit?
A: 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.
Q: Why don't I see the Lync indicators?
A: They don't appear if you're not signed into Lync, don't have it installed, or don't have a supported Lync configuration. But you can still send mail:
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.
Q: How do I change the font and color for CodeLens?
A: Go to Tools, Options, Environment, Fonts and Colors.
To use the keyboard:
Press Alt + T + O to open the Options box.
Press Up Arrow or Down Arrow to go to the Environment node, then press Left Arrow to expand the node.
Press Down Arrow to go to Fonts and Colors.
Press TAB to go to the Show settings for list, and then press Down Arrow to select CodeLens.
Q: What’s the difference between the authors indicator and changes indicator?
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.
Q: How do I refresh the indicators?
A: This depends on the indicator:
References: This indicator updates automatically when the code changes. If you have this indicator docked as a separate window, refresh the indicator manually here:
Team: Refresh these indicators manually here:
Test: Run all the tests or specific tests to refresh this indicator.
Q: Can I move the CodeLens heads-up display?
A: Yes, choose to dock CodeLens as a window.
Q: What's "Local Version"?
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.
Q: Can I manage how CodeLens processes code to show history and linked items?
A: Yes, if your code is in TFS, use the CodeIndex command with the TFS Config command.