How to Show Unused References in Visual Studio Code

If you want to learn How to show unused references in Visual Studio Code let me tell you it is more like an inbuilt Visual Studio code feature. Turning this setting on will basically allow you to get a grey label of references at the top of all the functions, variables or containers you are using. This is really helpful in finding out unused variables and getting rid of them.

You might want to show how many references a certain function or variable is making to make your code more concise and crisp. You want to delete unused references to make your code more taut, solid, and error-free.

All you have to do is check those settings out for the language you are using either Typescript or Javascript.

NOTE: Not sure if a similar setting is available for other languages as well but feel free to be a Chomsky and explore.

Steps on How to Show Unused References in Visual Studio Code

The first step is to, of course, get into the settings of things.

Step 1: First you have to open Settings. To do that you can either Navigate to File > Preferences > Settings or simply press the shortcut Ctrl + ,

settings in vsc

Step 2: Once the settings page opens, you can either navigate to Extensions > Typescript and then look for the said options are a better and easy way is to search directly by ‘references’ at the top search bar and then click on Typescript on the left searchbar:

How to show unused references in Visual Studio Code setting in vsc

Doing so narrows down the results further.

Step 3: You can enable disable references for the language you want from here. Recommend turning all four of them since that will not only turn on the References Code Lens but also turn on the ‘Show On All Functions’ setting.

Once these settings are turned on, you will see its immediate effect, if not you can either reload/restart VSC to see it in full effect.

Here’s an example showing it working on functions as well owing to the setting we chose.

How to show unused references in Visual Studio Code final result

If you have been working on Playwright, the above will work even for locators that have not been referenced. This makes it really easy for you to pinpoint dispensable locators and get rid of them.

The next thing to learn is how to delete all the unused references from the code at once like in a single go.

Scottshak

Poet. Author. Blogger. Screenwriter. Director. Editor. Software Engineer. Author of "Songs of a Ruin" and proud owner of four websites and two production houses. Also, one of the geekiest Test Automation Engineers based in Ahmedabad.

You may also like...

1 Response

  1. July 25, 2024

    […] now you have already identified how to find unused references in the code using VSC, you want to be able to delete them, right? Of course, you can delete them one by one. But it can […]

Leave a Reply