Search code examples
vscode-extensions

How to obtain a list of installed VS Code extensions using code


I want to get the list of installed extensions for VS Code in code.

Not from the CLI, I want it in code so I can write it to the console for diagnostic purposes in the middle of a unit test that's behaving like things aren't installed. It could be that something isn't yet loaded (or is loaded but isn't ready yet).

I already know how to get a list from the CLI as detailed here How to show the extensions installed in Visual Studio Code?.

Probably there's some command I can use with executeCommand, but I can't find it.


Solution

  • const extensions = vscode.extensions.all;  // returns an array
    

    will give you all enabled extensions (so an extension could be installed but disabled and it wouldn't show up in all, but actual activation of the extension is not required) - it does include built-in extensions, like vscode.xml and all other pre-installed language extensions. Not just the extensions you may have manually installed.

    You could filter those by their id if you wanted. To remove those starting with vscode. for example.

      let extensions = vscode.extensions.all;
      extensions = extensions.filter(extension => !extension.id.startsWith('vscode.'));
    

    That'll get rid of ~80 of the built-ins, but there are more - there are a few starting with 'ms-code' you might not be interested in.