Peter Wone
Peter Wone

Reputation: 18755

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.

Upvotes: 4

Views: 2762

Answers (2)

Mark
Mark

Reputation: 180755

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.

Upvotes: 2

Serious Angel
Serious Angel

Reputation: 1555

Just in case, it seems that in VS Code v1.89.0 (2024-05) it should be also possible to find local installed extensions via method in vscode.context object - resolveConfiguration.

  1. Open DevTools;

  2. Execute in DevTools Console:

vscode.context.resolveConfiguration()
  .then(a => {
    console.log(a.profiles.profile.extensionsResource.path);
  });

// /home/user/.vscode/extensions/extensions.json
  1. Execute in terminal/shell:
cat -- '/home/user/.vscode/extensions/extensions.json' \
    | jq '.[] | .identifier.id + " (v" + .version + ")"';

// Result example

"ms-vscode.makefile-tools (v0.9.10)"
"timonwong.shellcheck (v0.37.1)"
"vue.volar (v2.0.10)"
"prograhammer.tslint-vue (v1.5.6)"
"idered.npm (v1.7.4)"
...

Upvotes: 1

Related Questions