Skip to content

Commit 9fee800

Browse files
committed
1 parent fad4e14 commit 9fee800

File tree

6 files changed

+25
-14
lines changed

6 files changed

+25
-14
lines changed

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ export function sortExtensionVersions(versions: IRawGalleryExtensionVersion[], p
384384
return versions;
385385
}
386386

387-
function toExtension(galleryExtension: IRawGalleryExtension, version: IRawGalleryExtensionVersion, allTargetPlatforms: TargetPlatform[], telemetryData?: any): IGalleryExtension {
387+
function toExtension(galleryExtension: IRawGalleryExtension, version: IRawGalleryExtensionVersion, allTargetPlatforms: TargetPlatform[], hasReleaseVersion: boolean, telemetryData?: IStringDictionary<any>): IGalleryExtension {
388388
const latestVersion = galleryExtension.versions[0];
389389
const assets = <IGalleryExtensionAssets>{
390390
manifest: getVersionAsset(version, AssetType.Manifest),
@@ -428,6 +428,7 @@ function toExtension(galleryExtension: IRawGalleryExtension, version: IRawGaller
428428
isPreReleaseVersion: isPreReleaseVersion(version)
429429
},
430430
hasPreReleaseVersion: isPreReleaseVersion(latestVersion),
431+
hasReleaseVersion,
431432
preview: getIsPreview(galleryExtension.flags),
432433
/* __GDPR__FRAGMENT__
433434
"GalleryExtensionTelemetryData2" : {
@@ -543,7 +544,8 @@ abstract class AbstractExtensionGalleryService implements IExtensionGalleryServi
543544
};
544545
}
545546
if (await this.isRawExtensionVersionCompatible(rawVersion, includePreRelease, allTargetPlatforms, targetPlatform)) {
546-
return toExtension(rawExtension, rawVersion, allTargetPlatforms);
547+
const hasReleaseVersion = rawExtension.versions.some(version => !isPreReleaseVersion(version));
548+
return toExtension(rawExtension, rawVersion, allTargetPlatforms, hasReleaseVersion);
547549
}
548550
}
549551

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

657-
private async converToGalleryExtensions(rawGalleryExtensions: { rawGalleryExtension: IRawGalleryExtension, version?: string }[], includePreRelease: boolean, targetPlatform: TargetPlatform, telemetryData: (index: number) => any, token: CancellationToken): Promise<IGalleryExtension[]> {
658-
const toExtensionWithLatestVersion = (galleryExtension: IRawGalleryExtension, index: number): IGalleryExtension => {
659+
private async converToGalleryExtensions(rawGalleryExtensions: { rawGalleryExtension: IRawGalleryExtension, version?: string }[], includePreRelease: boolean, targetPlatform: TargetPlatform, telemetryData: (index: number) => IStringDictionary<any> | undefined, token: CancellationToken): Promise<IGalleryExtension[]> {
660+
const toExtensionWithLatestVersion = (galleryExtension: IRawGalleryExtension, index: number, hasReleaseVersion: boolean): IGalleryExtension => {
659661
const allTargetPlatforms = getAllTargetPlatforms(galleryExtension);
660662
let latestVersion = galleryExtension.versions[0];
661663
latestVersion = galleryExtension.versions.find(version => version.version === latestVersion.version && isTargetPlatformCompatible(getTargetPlatformForExtensionVersion(version), allTargetPlatforms, targetPlatform)) || latestVersion;
662-
if (!includePreRelease && isPreReleaseVersion(latestVersion)) {
664+
if (isPreReleaseVersion(latestVersion) && !includePreRelease) {
663665
latestVersion = galleryExtension.versions.find(version => version.version !== latestVersion.version && !isPreReleaseVersion(version)) || latestVersion;
664666
}
665-
return toExtension(galleryExtension, latestVersion, allTargetPlatforms, telemetryData(index));
667+
return toExtension(galleryExtension, latestVersion, allTargetPlatforms, hasReleaseVersion, telemetryData(index));
666668
};
667669
const result: [number, IGalleryExtension][] = [];
668670
const preReleaseVersions = new Map<string, number>();
669671
for (let index = 0; index < rawGalleryExtensions.length; index++) {
670672
const { rawGalleryExtension, version } = rawGalleryExtensions[index];
673+
const hasReleaseVersion = rawGalleryExtension.versions.some(version => !isPreReleaseVersion(version));
671674
if (version) {
672675
const versionAsset = rawGalleryExtension.versions.find(v => v.version === version);
673676
if (versionAsset) {
674-
result.push([index, toExtension(rawGalleryExtension, versionAsset, getAllTargetPlatforms(rawGalleryExtension))]);
677+
result.push([index, toExtension(rawGalleryExtension, versionAsset, getAllTargetPlatforms(rawGalleryExtension), hasReleaseVersion)]);
675678
}
676679
} else {
677-
const extension = toExtensionWithLatestVersion(rawGalleryExtension, index);
678-
if (extension.properties.isPreReleaseVersion && !includePreRelease) {
680+
const extension = toExtensionWithLatestVersion(rawGalleryExtension, index, hasReleaseVersion);
681+
if (extension.properties.isPreReleaseVersion) {
679682
preReleaseVersions.set(extension.identifier.uuid, index);
680683
} else {
681684
result.push([index, extension]);
@@ -694,8 +697,9 @@ abstract class AbstractExtensionGalleryService implements IExtensionGalleryServi
694697
throw new Error('Not all extensions with latest versions are returned');
695698
}
696699
for (const rawGalleryExtension of galleryExtensions) {
700+
const hasReleaseVersion = rawGalleryExtension.versions.some(version => !isPreReleaseVersion(version));
697701
const index = preReleaseVersions.get(rawGalleryExtension.extensionId)!;
698-
const extension = toExtensionWithLatestVersion(rawGalleryExtension, index);
702+
const extension = toExtensionWithLatestVersion(rawGalleryExtension, index, hasReleaseVersion);
699703
result.push([index, extension]);
700704
}
701705
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ export interface IGalleryExtension {
257257
lastUpdated: number;
258258
preview: boolean;
259259
hasPreReleaseVersion: boolean;
260+
hasReleaseVersion: boolean;
260261
allTargetPlatforms: TargetPlatform[];
261262
assets: IGalleryExtensionAssets;
262263
properties: IGalleryExtensionProperties;

src/vs/workbench/contrib/extensions/browser/extensions.contribution.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,7 +1187,7 @@ class ExtensionsContributions extends Disposable implements IWorkbenchContributi
11871187
id: MenuId.ExtensionContext,
11881188
group: '0_install',
11891189
order: 1,
1190-
when: ContextKeyExpr.and(ContextKeyExpr.has('inExtensionEditor'), ContextKeyExpr.has('extensionHasPreReleaseVersion'), ContextKeyExpr.has('showPreReleaseVersion'), ContextKeyExpr.not('isBuiltinExtension'))
1190+
when: ContextKeyExpr.and(ContextKeyExpr.has('inExtensionEditor'), ContextKeyExpr.has('extensionHasPreReleaseVersion'), ContextKeyExpr.has('extensionHasReleaseVersion'), ContextKeyExpr.has('showPreReleaseVersion'), ContextKeyExpr.not('isBuiltinExtension'))
11911191
},
11921192
run: async (accessor: ServicesAccessor, extensionId: string) => {
11931193
const extensionWorkbenchService = accessor.get(IExtensionsWorkbenchService);
@@ -1219,7 +1219,7 @@ class ExtensionsContributions extends Disposable implements IWorkbenchContributi
12191219
id: MenuId.ExtensionContext,
12201220
group: '0_install',
12211221
order: 3,
1222-
when: ContextKeyExpr.and(ContextKeyExpr.has('installedExtensionIsPreReleaseVersion'), ContextKeyExpr.has('extensionHasPreReleaseVersion'), ContextKeyExpr.not('inExtensionEditor'), ContextKeyExpr.equals('extensionStatus', 'installed'), ContextKeyExpr.not('isBuiltinExtension'))
1222+
when: ContextKeyExpr.and(ContextKeyExpr.has('installedExtensionIsPreReleaseVersion'), ContextKeyExpr.has('extensionHasPreReleaseVersion'), ContextKeyExpr.has('extensionHasReleaseVersion'), ContextKeyExpr.not('inExtensionEditor'), ContextKeyExpr.equals('extensionStatus', 'installed'), ContextKeyExpr.not('isBuiltinExtension'))
12231223
},
12241224
run: async (accessor: ServicesAccessor, id: string) => {
12251225
const extensionWorkbenchService = accessor.get(IExtensionsWorkbenchService);

src/vs/workbench/contrib/extensions/browser/extensionsActions.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ export abstract class AbstractInstallAction extends ExtensionAction {
297297
this.enabled = false;
298298
if (this.extension && !this.extension.isBuiltin) {
299299
if (this.extension.state === ExtensionState.Uninstalled && await this.extensionsWorkbenchService.canInstall(this.extension)) {
300-
this.enabled = !this.installPreReleaseVersion || this.extension.hasPreReleaseVersion;
300+
this.enabled = this.installPreReleaseVersion ? this.extension.hasPreReleaseVersion : this.extension.hasReleaseVersion;
301301
this.updateLabel();
302302
}
303303
}
@@ -909,6 +909,7 @@ function getContextMenuActionsGroups(extension: IExtension | undefined | null, c
909909
cksOverlay.push(['installedExtensionIsPreReleaseVersion', !!extension.local?.isPreReleaseVersion]);
910910
cksOverlay.push(['galleryExtensionIsPreReleaseVersion', !!extension.gallery?.properties.isPreReleaseVersion]);
911911
cksOverlay.push(['extensionHasPreReleaseVersion', extension.hasPreReleaseVersion]);
912+
cksOverlay.push(['extensionHasReleaseVersion', extension.hasReleaseVersion]);
912913
}
913914

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

11171118
update(): void {
1118-
this.enabled = !!this.extension && this.extension.state === ExtensionState.Installed && !!this.extension.local?.isPreReleaseVersion;
1119+
this.enabled = !!this.extension && this.extension.state === ExtensionState.Installed && !!this.extension.local?.isPreReleaseVersion && !!this.extension.hasReleaseVersion;
11191120
}
11201121

11211122
override async run(): Promise<any> {

src/vs/workbench/contrib/extensions/browser/extensionsWorkbenchService.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,10 @@ class Extension implements IExtension {
222222
return !!this.gallery?.hasPreReleaseVersion;
223223
}
224224

225+
get hasReleaseVersion(): boolean {
226+
return !!this.gallery?.hasReleaseVersion;
227+
}
228+
225229
private getLocal(preRelease: boolean): ILocalExtension | undefined {
226230
return this.local && !this.outdated && this.local.isPreReleaseVersion === preRelease ? this.local : undefined;
227231
}

src/vs/workbench/contrib/extensions/common/extensions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export interface IExtension {
5050
readonly version: string;
5151
readonly latestVersion: string;
5252
readonly hasPreReleaseVersion: boolean;
53+
readonly hasReleaseVersion: boolean;
5354
readonly description: string;
5455
readonly url?: string;
5556
readonly repository?: string;

0 commit comments

Comments
 (0)