From f10dc2a548ea212ef04b433ad411d9d169f90d79 Mon Sep 17 00:00:00 2001 From: Sandeep Somavarapu Date: Thu, 28 Jan 2021 15:06:44 +0100 Subject: [PATCH] more polish --- .../common/extensionManagementCLIService.ts | 18 +++++++++--------- .../api/browser/mainThreadCLICommands.ts | 8 ++++---- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/vs/platform/extensionManagement/common/extensionManagementCLIService.ts b/src/vs/platform/extensionManagement/common/extensionManagementCLIService.ts index 823487ca84c..f14badba524 100644 --- a/src/vs/platform/extensionManagement/common/extensionManagementCLIService.ts +++ b/src/vs/platform/extensionManagement/common/extensionManagementCLIService.ts @@ -176,7 +176,11 @@ export class ExtensionManagementCLIService implements IExtensionManagementCLISer private async installVSIX(vsix: URI, force: boolean, output: CLIOutput): Promise { const manifest = await this.extensionManagementService.getManifest(vsix); - const valid = await this.validate(manifest, force, output) && await this.validateExtensionKind(manifest, output); + if (!manifest) { + throw new Error('Invalid vsix'); + } + + const valid = await this.validateVSIX(manifest, force, output); if (valid) { try { await this.extensionManagementService.install(vsix); @@ -217,7 +221,7 @@ export class ExtensionManagementCLIService implements IExtensionManagementCLISer private async installFromGallery({ id, version, installOptions }: InstallExtensionInfo, galleryExtension: IGalleryExtension, installed: ILocalExtension[], force: boolean, output: CLIOutput): Promise { const manifest = await this.extensionGalleryService.getManifest(galleryExtension, CancellationToken.None); - if (manifest && !await this.validateExtensionKind(manifest, output)) { + if (manifest && !this.validateExtensionKind(manifest, output)) { return null; } @@ -250,15 +254,11 @@ export class ExtensionManagementCLIService implements IExtensionManagementCLISer } } - protected async validateExtensionKind(_manifest: IExtensionManifest, output: CLIOutput): Promise { + protected validateExtensionKind(_manifest: IExtensionManifest, output: CLIOutput): boolean { return true; } - private async validate(manifest: IExtensionManifest, force: boolean, output: CLIOutput): Promise { - if (!manifest) { - throw new Error('Invalid vsix'); - } - + private async validateVSIX(manifest: IExtensionManifest, force: boolean, output: CLIOutput): Promise { const extensionIdentifier = { id: getGalleryExtensionId(manifest.publisher, manifest.name) }; const installedExtensions = await this.extensionManagementService.getInstalled(ExtensionType.User); const newer = installedExtensions.find(local => areSameExtensions(extensionIdentifier, local.identifier) && gt(local.manifest.version, manifest.version)); @@ -268,7 +268,7 @@ export class ExtensionManagementCLIService implements IExtensionManagementCLISer return false; } - return true; + return this.validateExtensionKind(manifest, output); } public async uninstallExtensions(extensions: (string | URI)[], force: boolean, output: CLIOutput = console): Promise { diff --git a/src/vs/workbench/api/browser/mainThreadCLICommands.ts b/src/vs/workbench/api/browser/mainThreadCLICommands.ts index 75c57d85522..bad0881c691 100644 --- a/src/vs/workbench/api/browser/mainThreadCLICommands.ts +++ b/src/vs/workbench/api/browser/mainThreadCLICommands.ts @@ -40,10 +40,10 @@ CommandsRegistry.registerCommand('_remoteCLI.manageExtensions', async function ( const instantiationService = accessor.get(IInstantiationService); const extensionManagementServerService = accessor.get(IExtensionManagementServerService); - if (!extensionManagementServerService.remoteExtensionManagementServer) { + const remoteExtensionManagementService = extensionManagementServerService.remoteExtensionManagementServer?.extensionManagementService; + if (!remoteExtensionManagementService) { return; } - const remoteExtensionManagementService = extensionManagementServerService.remoteExtensionManagementServer.extensionManagementService; const cliService = instantiationService.createChild(new ServiceCollection([IExtensionManagementService, remoteExtensionManagementService])).createInstance(RemoteExtensionCLIManagementService); @@ -84,9 +84,9 @@ class RemoteExtensionCLIManagementService extends ExtensionManagementCLIService super(extensionManagementService, extensionGalleryService, localizationsService); } - protected async validateExtensionKind(manifest: IExtensionManifest, output: CLIOutput): Promise { + protected validateExtensionKind(manifest: IExtensionManifest, output: CLIOutput): boolean { if (!canExecuteOnWorkspace(manifest, this.productService, this.configurationService)) { - output.log(localize('invalidExtensionKind', "Extension {0} can only not be installed. The remote CLI currently only supports installing workbench extensions", getExtensionId(manifest.publisher, manifest.name))); + output.log(localize('cannot be installed', "Cannot install '{0}' because this extension has defined that it cannot run on the remote server.", getExtensionId(manifest.publisher, manifest.name))); return false; } return true;