Dela via


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.

CodeLens indicators in the code editor

Contact your team about these changes without leaving the editor:

CodeLens - Contact your team

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

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

    CodeLens - Choose references indicator

    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.

  2. To view 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

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):

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.

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:

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.

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):

CodeLens: Find when your code was branched

Find incoming changes from other branches

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

Find when changes got merged

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

Compare an incoming change with your local version (Shift + F10)

CodeLens: Compare incoming change with local

You can also double-click the changeset.

What do the icons mean?

Icon

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)

Find linked work items (Alt + 7)

CodeLens - Find work items for specific code

Find linked code reviews (Alt + 8)

CodeLens - View code review requests

Find linked bugs (Alt + 9)

CodeLens - Find bugs linked to changesets

Contact the owner of an item (Shift + F10)

CodeLens - Contact your team

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

  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.

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.

CodeLens - Turn indicators off or on

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:

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.

Q: How do I change the font and color for CodeLens?

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.

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:

    CodeLens - Dock as window

  • Team: Refresh these indicators manually here:

    CodeLens - Refresh indicators

  • Test: Run all the tests or specific tests to refresh this indicator.

Q: Can I move the CodeLens heads-up display?

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

CodeLens - Dock as 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.