94

I want to show references count in Visual Studio Code. How can I do it?

Enter image description here

2
  • Just a note to those using VS Community edition - this feature is not available.
    – Jnr
    Oct 6, 2018 at 9:08
  • 5
    CodeLens is available in VS2019 community edition.
    – namg_engr
    May 15, 2020 at 15:51

7 Answers 7

140

This feature is called CodeLens.

In Visual Studio find it in menu OptionsText EditorAll languagesCodeLens.

And in Visual Studio Code it is in menu FilePreferencesSettings → "editor.codeLens": true

6
  • 6
    I cannot find anything about codelens on mac version. Am I missing an extension?
    – savante
    Aug 31, 2019 at 18:26
  • @savante try searching in Settings --> User/Workspace for codelens
    – S.C.
    Sep 26, 2019 at 7:58
  • 5
    In VSCode v1.40.0, search settings for codeLens and check out the TypeScript section.
    – Kon
    Jan 9, 2020 at 17:26
  • Do you know if there's a way to group by file? Like, if an export is only imported once then it shows "1", rather than the number of times it's used in each file?
    – Ziggy
    Mar 10, 2020 at 19:19
  • 1
    I needed to enable all 3 of these settings; "editor.codeLens": true, "typescript.implementationsCodeLens.enabled": true, "typescript.referencesCodeLens.enabled": true,
    – JoshuaTree
    Dec 7, 2020 at 8:26
69

Visual Studio Code version 1.28.2:

You need to add this to User Settings:

Menu FilePreferencesSettings:

"typescript.referencesCodeLens.enabled": true,
1
  • It says "unknown configuration setting" Jul 24, 2021 at 1:38
27

The menu structure ususally changes during years. So in VSCode v.1.43 please follow the next steps:

  1. Click Gear icon and go to Settings

enter image description here

  1. In the "Settings" window in the input field type "reference", click "User" tab, under "Extensions" click "Typescript" and find "Reference Code Lens" checkboxes for javascript/typescript.

enter image description here

Checking/unchecking checkboxes will automatically apply your changes.

3
  • Is this available for Python?
    – Koder101
    Apr 21, 2021 at 12:07
  • @Koder101 is Python support Typescript? Apr 21, 2021 at 12:55
  • VS Code supports Python, and just like other VS code provides this function reference count for C# or typescript, I wanted it for Python too.
    – Koder101
    Apr 21, 2021 at 13:28
12

The simple process for show the reference count.

  1. Step 1: From Settings – Type CodeLens and Enable the Editor: Code Lens and JavaScript > References Code Lens to check the references in JavaScript File.

enter image description here

  1. Step 2: Then open any of your JavaScript file to identify the References of Property or Method in the file.

enter image description here

  • If any case, you can't show the reference, then enable(yes) assets to build and debug in own project.

enter image description here

  • If you'll click to the yes button of assets then, you'll seen the .vscode file

enter image description here

5

Sometimes you don't want to turn it on/off completely, but toggle it on/off with a keyboard shortcut. If so, the following may help:

  1. Install an extension: https://marketplace.visualstudio.com/items?itemName=rebornix.toggle

  2. and configure it for your desires. (Preferences -> Keyboard Shortcuts -> keybindings.json)

For Example for TypeScript:

{
    "key": "F4",
    "command": "toggle",
    "when": "editorTextFocus",
    "args": {
        "id": "myChosenIdWhatEverItIs",
        "value": [
            {
              "typescript.referencesCodeLens.enabled": true,
            },
            {
              "typescript.referencesCodeLens.enabled": false,
            }
        ]
    }
}
1
  • 2
    Huge thanks for this suggestion! Something like this can/will solve a lot of issues I currently have, as well as solve some I didn't realize I had, lol. This is great.
    – MostHated
    Aug 19, 2021 at 15:04
-1

In Visual Studio 2019 Community it's in Tools → Options → Text Editor → All Languages → CodeLens.

1
  • The OP is asking about VS Code, not Visual Studio. Feb 20 at 20:26
-1

On Visual Studio 2019 Community Edition, just hit Ctrl+Q or look for the text box next to Help, enter CodeLens there. That is by far the quickest and easiest.

CodeLens on Search Enable

1
  • The OP is asking about VS Code, not Visual Studio. Feb 20 at 20:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.