Skip to content

Commit

Permalink
Fix #138231
Browse files Browse the repository at this point in the history
  • Loading branch information
sandy081 committed Dec 1, 2021
1 parent fad4e14 commit 9fee800
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ export function sortExtensionVersions(versions: IRawGalleryExtensionVersion[], p
return versions;
}

function toExtension(galleryExtension: IRawGalleryExtension, version: IRawGalleryExtensionVersion, allTargetPlatforms: TargetPlatform[], telemetryData?: any): IGalleryExtension {
function toExtension(galleryExtension: IRawGalleryExtension, version: IRawGalleryExtensionVersion, allTargetPlatforms: TargetPlatform[], hasReleaseVersion: boolean, telemetryData?: IStringDictionary<any>): IGalleryExtension {
const latestVersion = galleryExtension.versions[0];
const assets = <IGalleryExtensionAssets>{
manifest: getVersionAsset(version, AssetType.Manifest),
Expand Down Expand Up @@ -428,6 +428,7 @@ function toExtension(galleryExtension: IRawGalleryExtension, version: IRawGaller
isPreReleaseVersion: isPreReleaseVersion(version)
},
hasPreReleaseVersion: isPreReleaseVersion(latestVersion),
hasReleaseVersion,
preview: getIsPreview(galleryExtension.flags),
/* __GDPR__FRAGMENT__
"GalleryExtensionTelemetryData2" : {
Expand Down Expand Up @@ -543,7 +544,8 @@ abstract class AbstractExtensionGalleryService implements IExtensionGalleryServi
};
}
if (await this.isRawExtensionVersionCompatible(rawVersion, includePreRelease, allTargetPlatforms, targetPlatform)) {
return toExtension(rawExtension, rawVersion, allTargetPlatforms);
const hasReleaseVersion = rawExtension.versions.some(version => !isPreReleaseVersion(version));
return toExtension(rawExtension, rawVersion, allTargetPlatforms, hasReleaseVersion);
}
}

Expand Down Expand Up @@ -654,28 +656,29 @@ abstract class AbstractExtensionGalleryService implements IExtensionGalleryServi
return { firstPage: extensions, total, pageSize: query.pageSize, getPage } as IPager<IGalleryExtension>;
}

private async converToGalleryExtensions(rawGalleryExtensions: { rawGalleryExtension: IRawGalleryExtension, version?: string }[], includePreRelease: boolean, targetPlatform: TargetPlatform, telemetryData: (index: number) => any, token: CancellationToken): Promise<IGalleryExtension[]> {
const toExtensionWithLatestVersion = (galleryExtension: IRawGalleryExtension, index: number): IGalleryExtension => {
private async converToGalleryExtensions(rawGalleryExtensions: { rawGalleryExtension: IRawGalleryExtension, version?: string }[], includePreRelease: boolean, targetPlatform: TargetPlatform, telemetryData: (index: number) => IStringDictionary<any> | undefined, token: CancellationToken): Promise<IGalleryExtension[]> {
const toExtensionWithLatestVersion = (galleryExtension: IRawGalleryExtension, index: number, hasReleaseVersion: boolean): IGalleryExtension => {
const allTargetPlatforms = getAllTargetPlatforms(galleryExtension);
let latestVersion = galleryExtension.versions[0];
latestVersion = galleryExtension.versions.find(version => version.version === latestVersion.version && isTargetPlatformCompatible(getTargetPlatformForExtensionVersion(version), allTargetPlatforms, targetPlatform)) || latestVersion;
if (!includePreRelease && isPreReleaseVersion(latestVersion)) {
if (isPreReleaseVersion(latestVersion) && !includePreRelease) {
latestVersion = galleryExtension.versions.find(version => version.version !== latestVersion.version && !isPreReleaseVersion(version)) || latestVersion;
}
return toExtension(galleryExtension, latestVersion, allTargetPlatforms, telemetryData(index));
return toExtension(galleryExtension, latestVersion, allTargetPlatforms, hasReleaseVersion, telemetryData(index));
};
const result: [number, IGalleryExtension][] = [];
const preReleaseVersions = new Map<string, number>();
for (let index = 0; index < rawGalleryExtensions.length; index++) {
const { rawGalleryExtension, version } = rawGalleryExtensions[index];
const hasReleaseVersion = rawGalleryExtension.versions.some(version => !isPreReleaseVersion(version));
if (version) {
const versionAsset = rawGalleryExtension.versions.find(v => v.version === version);
if (versionAsset) {
result.push([index, toExtension(rawGalleryExtension, versionAsset, getAllTargetPlatforms(rawGalleryExtension))]);
result.push([index, toExtension(rawGalleryExtension, versionAsset, getAllTargetPlatforms(rawGalleryExtension), hasReleaseVersion)]);
}
} else {
const extension = toExtensionWithLatestVersion(rawGalleryExtension, index);
if (extension.properties.isPreReleaseVersion && !includePreRelease) {
const extension = toExtensionWithLatestVersion(rawGalleryExtension, index, hasReleaseVersion);
if (extension.properties.isPreReleaseVersion) {
preReleaseVersions.set(extension.identifier.uuid, index);
} else {
result.push([index, extension]);
Expand All @@ -694,8 +697,9 @@ abstract class AbstractExtensionGalleryService implements IExtensionGalleryServi
throw new Error('Not all extensions with latest versions are returned');
}
for (const rawGalleryExtension of galleryExtensions) {
const hasReleaseVersion = rawGalleryExtension.versions.some(version => !isPreReleaseVersion(version));
const index = preReleaseVersions.get(rawGalleryExtension.extensionId)!;
const extension = toExtensionWithLatestVersion(rawGalleryExtension, index);
const extension = toExtensionWithLatestVersion(rawGalleryExtension, index, hasReleaseVersion);
result.push([index, extension]);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ export interface IGalleryExtension {
lastUpdated: number;
preview: boolean;
hasPreReleaseVersion: boolean;
hasReleaseVersion: boolean;
allTargetPlatforms: TargetPlatform[];
assets: IGalleryExtensionAssets;
properties: IGalleryExtensionProperties;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1187,7 +1187,7 @@ class ExtensionsContributions extends Disposable implements IWorkbenchContributi
id: MenuId.ExtensionContext,
group: '0_install',
order: 1,
when: ContextKeyExpr.and(ContextKeyExpr.has('inExtensionEditor'), ContextKeyExpr.has('extensionHasPreReleaseVersion'), ContextKeyExpr.has('showPreReleaseVersion'), ContextKeyExpr.not('isBuiltinExtension'))
when: ContextKeyExpr.and(ContextKeyExpr.has('inExtensionEditor'), ContextKeyExpr.has('extensionHasPreReleaseVersion'), ContextKeyExpr.has('extensionHasReleaseVersion'), ContextKeyExpr.has('showPreReleaseVersion'), ContextKeyExpr.not('isBuiltinExtension'))
},
run: async (accessor: ServicesAccessor, extensionId: string) => {
const extensionWorkbenchService = accessor.get(IExtensionsWorkbenchService);
Expand Down Expand Up @@ -1219,7 +1219,7 @@ class ExtensionsContributions extends Disposable implements IWorkbenchContributi
id: MenuId.ExtensionContext,
group: '0_install',
order: 3,
when: ContextKeyExpr.and(ContextKeyExpr.has('installedExtensionIsPreReleaseVersion'), ContextKeyExpr.has('extensionHasPreReleaseVersion'), ContextKeyExpr.not('inExtensionEditor'), ContextKeyExpr.equals('extensionStatus', 'installed'), ContextKeyExpr.not('isBuiltinExtension'))
when: ContextKeyExpr.and(ContextKeyExpr.has('installedExtensionIsPreReleaseVersion'), ContextKeyExpr.has('extensionHasPreReleaseVersion'), ContextKeyExpr.has('extensionHasReleaseVersion'), ContextKeyExpr.not('inExtensionEditor'), ContextKeyExpr.equals('extensionStatus', 'installed'), ContextKeyExpr.not('isBuiltinExtension'))
},
run: async (accessor: ServicesAccessor, id: string) => {
const extensionWorkbenchService = accessor.get(IExtensionsWorkbenchService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ export abstract class AbstractInstallAction extends ExtensionAction {
this.enabled = false;
if (this.extension && !this.extension.isBuiltin) {
if (this.extension.state === ExtensionState.Uninstalled && await this.extensionsWorkbenchService.canInstall(this.extension)) {
this.enabled = !this.installPreReleaseVersion || this.extension.hasPreReleaseVersion;
this.enabled = this.installPreReleaseVersion ? this.extension.hasPreReleaseVersion : this.extension.hasReleaseVersion;
this.updateLabel();
}
}
Expand Down Expand Up @@ -909,6 +909,7 @@ function getContextMenuActionsGroups(extension: IExtension | undefined | null, c
cksOverlay.push(['installedExtensionIsPreReleaseVersion', !!extension.local?.isPreReleaseVersion]);
cksOverlay.push(['galleryExtensionIsPreReleaseVersion', !!extension.gallery?.properties.isPreReleaseVersion]);
cksOverlay.push(['extensionHasPreReleaseVersion', extension.hasPreReleaseVersion]);
cksOverlay.push(['extensionHasReleaseVersion', extension.hasReleaseVersion]);
}

const menu = menuService.createMenu(MenuId.ExtensionContext, contextKeyService.createOverlay(cksOverlay));
Expand Down Expand Up @@ -1115,7 +1116,7 @@ export class SwitchToReleasedVersionAction extends ExtensionAction {
}

update(): void {
this.enabled = !!this.extension && this.extension.state === ExtensionState.Installed && !!this.extension.local?.isPreReleaseVersion;
this.enabled = !!this.extension && this.extension.state === ExtensionState.Installed && !!this.extension.local?.isPreReleaseVersion && !!this.extension.hasReleaseVersion;
}

override async run(): Promise<any> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ class Extension implements IExtension {
return !!this.gallery?.hasPreReleaseVersion;
}

get hasReleaseVersion(): boolean {
return !!this.gallery?.hasReleaseVersion;
}

private getLocal(preRelease: boolean): ILocalExtension | undefined {
return this.local && !this.outdated && this.local.isPreReleaseVersion === preRelease ? this.local : undefined;
}
Expand Down
1 change: 1 addition & 0 deletions src/vs/workbench/contrib/extensions/common/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export interface IExtension {
readonly version: string;
readonly latestVersion: string;
readonly hasPreReleaseVersion: boolean;
readonly hasReleaseVersion: boolean;
readonly description: string;
readonly url?: string;
readonly repository?: string;
Expand Down

0 comments on commit 9fee800

Please sign in to comment.