Skip to content

Commit 5a04b14

Browse files
authored
1 parent 8716df3 commit 5a04b14

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

src/vs/platform/extensionManagement/common/abstractExtensionManagementService.ts

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -494,33 +494,46 @@ export abstract class AbstractExtensionManagementService extends Disposable impl
494494
}
495495

496496
private async checkAndGetCompatibleVersion(extension: IGalleryExtension, sameVersion: boolean, installPreRelease: boolean): Promise<{ extension: IGalleryExtension; manifest: IExtensionManifest }> {
497+
let compatibleExtension: IGalleryExtension | null;
498+
497499
const extensionsControlManifest = await this.getExtensionsControlManifest();
498500
if (extensionsControlManifest.malicious.some(identifier => areSameExtensions(extension.identifier, identifier))) {
499501
throw new ExtensionManagementError(nls.localize('malicious extension', "Can't install '{0}' extension since it was reported to be problematic.", extension.identifier.id), ExtensionManagementErrorCode.Malicious);
500502
}
501503

502-
if (!await this.canInstall(extension)) {
503-
const targetPlatform = await this.getTargetPlatform();
504-
throw new ExtensionManagementError(nls.localize('incompatible platform', "The '{0}' extension is not available in {1} for {2}.", extension.identifier.id, this.productService.nameLong, TargetPlatformToString(targetPlatform)), ExtensionManagementErrorCode.IncompatibleTargetPlatform);
504+
const deprecationInfo = extensionsControlManifest.deprecated[extension.identifier.id.toLowerCase()];
505+
if (deprecationInfo?.extension?.autoMigrate) {
506+
this.logService.info(`The '${extension.identifier.id}' extension is deprecated, fetching the compatible '${deprecationInfo.extension.id}' extension instead.`);
507+
compatibleExtension = (await this.galleryService.getExtensions([{ id: deprecationInfo.extension.id, preRelease: deprecationInfo.extension.preRelease }], { targetPlatform: await this.getTargetPlatform(), compatible: true }, CancellationToken.None))[0];
508+
if (!compatibleExtension) {
509+
throw new ExtensionManagementError(nls.localize('notFoundDeprecatedReplacementExtension', "Can't install '{0}' extension since it was deprecated and the replacement extension '{1}' can't be found.", extension.identifier.id, deprecationInfo.extension.id), ExtensionManagementErrorCode.Deprecated);
510+
}
505511
}
506512

507-
const compatibleExtension = await this.getCompatibleVersion(extension, sameVersion, installPreRelease);
508-
if (!compatibleExtension) {
509-
/** If no compatible release version is found, check if the extension has a release version or not and throw relevant error */
510-
if (!installPreRelease && extension.properties.isPreReleaseVersion && (await this.galleryService.getExtensions([extension.identifier], CancellationToken.None))[0]) {
511-
throw new ExtensionManagementError(nls.localize('notFoundReleaseExtension', "Can't install release version of '{0}' extension because it has no release version.", extension.identifier.id), ExtensionManagementErrorCode.ReleaseVersionNotFound);
513+
else {
514+
if (!await this.canInstall(extension)) {
515+
const targetPlatform = await this.getTargetPlatform();
516+
throw new ExtensionManagementError(nls.localize('incompatible platform', "The '{0}' extension is not available in {1} for {2}.", extension.identifier.id, this.productService.nameLong, TargetPlatformToString(targetPlatform)), ExtensionManagementErrorCode.IncompatibleTargetPlatform);
517+
}
518+
519+
compatibleExtension = await this.getCompatibleVersion(extension, sameVersion, installPreRelease);
520+
if (!compatibleExtension) {
521+
/** If no compatible release version is found, check if the extension has a release version or not and throw relevant error */
522+
if (!installPreRelease && extension.properties.isPreReleaseVersion && (await this.galleryService.getExtensions([extension.identifier], CancellationToken.None))[0]) {
523+
throw new ExtensionManagementError(nls.localize('notFoundReleaseExtension', "Can't install release version of '{0}' extension because it has no release version.", extension.identifier.id), ExtensionManagementErrorCode.ReleaseVersionNotFound);
524+
}
525+
throw new ExtensionManagementError(nls.localize('notFoundCompatibleDependency', "Can't install '{0}' extension because it is not compatible with the current version of {1} (version {2}).", extension.identifier.id, this.productService.nameLong, this.productService.version), ExtensionManagementErrorCode.Incompatible);
512526
}
513-
throw new ExtensionManagementError(nls.localize('notFoundCompatibleDependency', "Can't install '{0}' extension because it is not compatible with the current version of {1} (version {2}).", extension.identifier.id, this.productService.nameLong, this.productService.version), ExtensionManagementErrorCode.Incompatible);
514527
}
515528

516529
this.logService.info('Getting Manifest...', compatibleExtension.identifier.id);
517530
const manifest = await this.galleryService.getManifest(compatibleExtension, CancellationToken.None);
518531
if (manifest === null) {
519-
throw new ExtensionManagementError(`Missing manifest for extension ${extension.identifier.id}`, ExtensionManagementErrorCode.Invalid);
532+
throw new ExtensionManagementError(`Missing manifest for extension ${compatibleExtension.identifier.id}`, ExtensionManagementErrorCode.Invalid);
520533
}
521534

522535
if (manifest.version !== compatibleExtension.version) {
523-
throw new ExtensionManagementError(`Cannot install '${extension.identifier.id}' extension because of version mismatch in Marketplace`, ExtensionManagementErrorCode.Invalid);
536+
throw new ExtensionManagementError(`Cannot install '${compatibleExtension.identifier.id}' extension because of version mismatch in Marketplace`, ExtensionManagementErrorCode.Invalid);
524537
}
525538

526539
return { extension: compatibleExtension, manifest };

0 commit comments

Comments
 (0)