microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
162.63k stars 28.67k forks source link

Install specific version of extension using workbench.extensions.installExtension #136313

Closed jeanp413 closed 2 years ago

jeanp413 commented 2 years ago

Would be great if we can install a specific version of an extension using workbench.extensions.installExtension

vscode.commands.executeCommand('workbench.extensions.installExtension', 'publisher.my-extension@0.1.0');
sandy081 commented 2 years ago

May I know the use case? And what happens if user has auto update enabled?

jeanp413 commented 2 years ago

@sandy081 I have an extension that reads a file where the user can specify extensions id (maybe with version specified) required for his workspace. My extension provides diagnostics and a quick action to install missing extensions using workbench.extensions.installExtension command. If the user has auto update enabled, then sure the extension will be updated, but this could be easily detected and show a notification teling the user if he's installing a specific version of an extension, he probably would want to disable auto update. Also, the cli already supports installing a specific version of an extension with --install-extension argument, so it would be good to have the same behavior for workbench.extensions.installExtension

sandy081 commented 2 years ago

Yes, one can install a specific version using CLI. But there is an open issue - that extension gets auto updated - this is due to the current limitation that storage is not accessible in CLI. We shall not surface the same here. So can you please update the PR to disable auto update when version is passed to the above command?

Here is the method that does that

https://github.com/microsoft/vscode/blob/45fdad3a10d437fb0a45cc008eecca7c35021fb2/src/vs/workbench/contrib/extensions/browser/extensionsWorkbenchService.ts#L1391

You can make this as a service method that can be accessible from above command invocation.

TylerLeonhardt commented 2 years ago
vscode.commands.executeCommand('workbench.extensions.installExtension', 'christian-kohler.npm-intellisense@1.3.1');

works as expected!

image