Skip to content

Commit 8e7b278

Browse files
authored
Merge pull request microsoft#139176 from microsoft/sandy081/fix139013
Bring back the fix for microsoft#139013
2 parents b8b1f00 + c5a4e53 commit 8e7b278

File tree

3 files changed

+58
-22
lines changed

3 files changed

+58
-22
lines changed

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

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { URI } from 'vs/base/common/uri';
1616
import { IHeaders, IRequestContext, IRequestOptions } from 'vs/base/parts/request/common/request';
1717
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
1818
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
19-
import { DefaultIconPath, getFallbackTargetPlarforms, getTargetPlatform, IExtensionGalleryService, IExtensionIdentifier, IExtensionIdentifierWithVersion, IGalleryExtension, IGalleryExtensionAsset, IGalleryExtensionAssets, IGalleryExtensionVersion, InstallOperation, IQueryOptions, IExtensionsControlManifest, isIExtensionIdentifier, isNotWebExtensionInWebTargetPlatform, isTargetPlatformCompatible, ITranslation, SortBy, SortOrder, StatisticType, TargetPlatform, toTargetPlatform, WEB_EXTENSION_TAG } from 'vs/platform/extensionManagement/common/extensionManagement';
19+
import { DefaultIconPath, getFallbackTargetPlarforms, getTargetPlatform, IExtensionGalleryService, IExtensionIdentifier, IExtensionIdentifierWithVersion, IGalleryExtension, IGalleryExtensionAsset, IGalleryExtensionAssets, IGalleryExtensionVersion, InstallOperation, IQueryOptions, IExtensionsControlManifest, isIExtensionIdentifier, isNotWebExtensionInWebTargetPlatform, isTargetPlatformCompatible, ITranslation, SortBy, SortOrder, StatisticType, TargetPlatform, toTargetPlatform, WEB_EXTENSION_TAG, IExtensionIdentifierWithPreRelease } from 'vs/platform/extensionManagement/common/extensionManagement';
2020
import { adoptToGalleryExtensionId, areSameExtensions, getGalleryExtensionId, getGalleryExtensionTelemetryData } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
2121
import { IExtensionManifest } from 'vs/platform/extensions/common/extensions';
2222
import { isEngineValid } from 'vs/platform/extensions/common/extensionValidator';
@@ -506,9 +506,39 @@ abstract class AbstractExtensionGalleryService implements IExtensionGalleryServi
506506
const { galleryExtensions } = await this.queryGallery(query, CURRENT_TARGET_PLATFORM, CancellationToken.None);
507507
const galleryExtensionsByVersion = galleryExtensions.map(rawGalleryExtension => {
508508
const id = getGalleryExtensionId(rawGalleryExtension.publisher.publisherName, rawGalleryExtension.extensionName);
509-
return { rawGalleryExtension, version: (<IExtensionIdentifierWithVersion | undefined>identifiers.find(identifier => areSameExtensions(identifier, { id })))?.version };
509+
return { rawGalleryExtension, version: (<IExtensionIdentifierWithVersion | undefined>identifiers.find(identifier => areSameExtensions(identifier, { id })))?.version, preRelease: includePreRelease };
510510
});
511-
return this.converToGalleryExtensions(galleryExtensionsByVersion, includePreRelease, CURRENT_TARGET_PLATFORM, () => undefined, token);
511+
return this.converToGalleryExtensions(galleryExtensionsByVersion, CURRENT_TARGET_PLATFORM, () => undefined, token);
512+
}
513+
514+
async getExtensions2(identifiers: ReadonlyArray<IExtensionIdentifierWithPreRelease>): Promise<IGalleryExtension[]> {
515+
const names: string[] = []; const ids: string[] = [];
516+
for (const identifier of identifiers) {
517+
if (identifier.uuid) {
518+
ids.push(identifier.uuid);
519+
} else {
520+
names.push(identifier.id.toLowerCase());
521+
}
522+
}
523+
let query = new Query()
524+
.withFlags(Flags.IncludeAssetUri, Flags.IncludeStatistics, Flags.IncludeCategoryAndTags, Flags.IncludeFiles, Flags.IncludeVersionProperties, Flags.IncludeLatestVersionOnly)
525+
.withPage(1, identifiers.length)
526+
.withFilter(FilterType.Target, 'Microsoft.VisualStudio.Code');
527+
if (ids.length) {
528+
query = query.withFilter(FilterType.ExtensionId, ...ids);
529+
}
530+
if (names.length) {
531+
query = query.withFilter(FilterType.ExtensionId, ...names);
532+
}
533+
534+
const { galleryExtensions: rawGalleryExtensions } = await this.queryGallery(query, CURRENT_TARGET_PLATFORM, CancellationToken.None);
535+
const rawGalleryExtensionsInput = rawGalleryExtensions.map(rawGalleryExtension => {
536+
const id = getGalleryExtensionId(rawGalleryExtension.publisher.publisherName, rawGalleryExtension.extensionName);
537+
const identifier = identifiers.find(identifier => areSameExtensions(identifier, { id, uuid: rawGalleryExtension.extensionId }));
538+
return { rawGalleryExtension, preRelease: !!identifier?.preRelease };
539+
});
540+
541+
return this.converToGalleryExtensions(rawGalleryExtensionsInput, CURRENT_TARGET_PLATFORM, () => undefined, CancellationToken.None);
512542
}
513543

514544
async getCompatibleExtension(arg1: IExtensionIdentifier | IGalleryExtension, includePreRelease: boolean, targetPlatform: TargetPlatform): Promise<IGalleryExtension | null> {
@@ -653,43 +683,43 @@ abstract class AbstractExtensionGalleryService implements IExtensionGalleryServi
653683

654684
const { galleryExtensions, total } = await this.queryGallery(query, CURRENT_TARGET_PLATFORM, token);
655685
const telemetryData = (index: number) => ({ index: ((query.pageNumber - 1) * query.pageSize) + index, querySource: options.source });
656-
const extensions = await this.converToGalleryExtensions(galleryExtensions.map(rawGalleryExtension => ({ rawGalleryExtension })), !!options.includePreRelease, CURRENT_TARGET_PLATFORM, telemetryData, token);
686+
const extensions = await this.converToGalleryExtensions(galleryExtensions.map(rawGalleryExtension => ({ rawGalleryExtension, preRelease: !!options.includePreRelease })), CURRENT_TARGET_PLATFORM, telemetryData, token);
657687
const getPage = async (pageIndex: number, ct: CancellationToken) => {
658688
if (ct.isCancellationRequested) {
659689
throw canceled();
660690
}
661691
const nextPageQuery = query.withPage(pageIndex + 1);
662692
const { galleryExtensions } = await this.queryGallery(nextPageQuery, CURRENT_TARGET_PLATFORM, ct);
663-
return await this.converToGalleryExtensions(galleryExtensions.map(rawGalleryExtension => ({ rawGalleryExtension })), !!options.includePreRelease, CURRENT_TARGET_PLATFORM, telemetryData, token);
693+
return await this.converToGalleryExtensions(galleryExtensions.map(rawGalleryExtension => ({ rawGalleryExtension, preRelease: !!options.includePreRelease })), CURRENT_TARGET_PLATFORM, telemetryData, token);
664694
};
665695

666696
return { firstPage: extensions, total, pageSize: query.pageSize, getPage } as IPager<IGalleryExtension>;
667697
}
668698

669-
private async converToGalleryExtensions(rawGalleryExtensions: { rawGalleryExtension: IRawGalleryExtension, version?: string }[], includePreRelease: boolean, targetPlatform: TargetPlatform, telemetryData: (index: number) => IStringDictionary<any> | undefined, token: CancellationToken): Promise<IGalleryExtension[]> {
670-
const toExtensionWithLatestVersion = (galleryExtension: IRawGalleryExtension, index: number, hasReleaseVersion: boolean): IGalleryExtension => {
699+
private async converToGalleryExtensions(rawGalleryExtensions: { rawGalleryExtension: IRawGalleryExtension, preRelease: boolean, version?: string }[], targetPlatform: TargetPlatform, telemetryData: (index: number) => IStringDictionary<any> | undefined, token: CancellationToken): Promise<IGalleryExtension[]> {
700+
const toExtensionWithLatestVersion = (galleryExtension: IRawGalleryExtension, index: number, hasReleaseVersion: boolean, preRelease: boolean): IGalleryExtension => {
671701
const allTargetPlatforms = getAllTargetPlatforms(galleryExtension);
672702
let latestVersion = galleryExtension.versions[0];
673703
latestVersion = galleryExtension.versions.find(version => version.version === latestVersion.version && isTargetPlatformCompatible(getTargetPlatformForExtensionVersion(version), allTargetPlatforms, targetPlatform)) || latestVersion;
674-
if (isPreReleaseVersion(latestVersion) && !includePreRelease) {
704+
if (isPreReleaseVersion(latestVersion) && !preRelease) {
675705
latestVersion = galleryExtension.versions.find(version => version.version !== latestVersion.version && !isPreReleaseVersion(version)) || latestVersion;
676706
}
677707
return toExtension(galleryExtension, latestVersion, allTargetPlatforms, hasReleaseVersion, telemetryData(index));
678708
};
679709
const result: [number, IGalleryExtension][] = [];
680-
const preReleaseVersions = new Map<string, number>();
710+
const preReleaseVersions = new Map<string, { index: number, preRelease: boolean }>();
681711
for (let index = 0; index < rawGalleryExtensions.length; index++) {
682-
const { rawGalleryExtension, version } = rawGalleryExtensions[index];
712+
const { rawGalleryExtension, version, preRelease } = rawGalleryExtensions[index];
683713
const hasReleaseVersion = rawGalleryExtension.versions.some(version => !isPreReleaseVersion(version));
684714
if (version) {
685715
const versionAsset = rawGalleryExtension.versions.find(v => v.version === version);
686716
if (versionAsset) {
687717
result.push([index, toExtension(rawGalleryExtension, versionAsset, getAllTargetPlatforms(rawGalleryExtension), hasReleaseVersion)]);
688718
}
689719
} else {
690-
const extension = toExtensionWithLatestVersion(rawGalleryExtension, index, hasReleaseVersion);
720+
const extension = toExtensionWithLatestVersion(rawGalleryExtension, index, hasReleaseVersion, preRelease);
691721
if (extension.properties.isPreReleaseVersion) {
692-
preReleaseVersions.set(extension.identifier.uuid, index);
722+
preReleaseVersions.set(extension.identifier.uuid, { index, preRelease });
693723
} else {
694724
result.push([index, extension]);
695725
}
@@ -713,8 +743,8 @@ abstract class AbstractExtensionGalleryService implements IExtensionGalleryServi
713743
}
714744
for (const rawGalleryExtension of galleryExtensions) {
715745
const hasReleaseVersion = rawGalleryExtension.versions.some(version => !isPreReleaseVersion(version));
716-
const index = preReleaseVersions.get(rawGalleryExtension.extensionId)!;
717-
const extension = toExtensionWithLatestVersion(rawGalleryExtension, index, hasReleaseVersion);
746+
const { index, preRelease } = preReleaseVersions.get(rawGalleryExtension.extensionId)!;
747+
const extension = toExtensionWithLatestVersion(rawGalleryExtension, index, hasReleaseVersion, preRelease);
718748
result.push([index, extension]);
719749
}
720750
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,10 @@ export interface IExtensionIdentifierWithVersion extends IExtensionIdentifier {
228228
version: string;
229229
}
230230

231+
export interface IExtensionIdentifierWithPreRelease extends IExtensionIdentifier {
232+
preRelease: boolean;
233+
}
234+
231235
export interface IGalleryExtensionIdentifier extends IExtensionIdentifier {
232236
uuid: string;
233237
}
@@ -268,7 +272,7 @@ export interface IGalleryMetadata {
268272
id: string;
269273
publisherId: string;
270274
publisherDisplayName: string;
271-
isPreReleaseVersion: boolean,
275+
isPreReleaseVersion: boolean,
272276
}
273277

274278
export type Metadata = Partial<IGalleryMetadata & { isMachineScoped: boolean; isBuiltin: boolean; preRelease: boolean, installedTimestamp: number }>;
@@ -338,6 +342,7 @@ export interface IExtensionGalleryService {
338342
query(options: IQueryOptions, token: CancellationToken): Promise<IPager<IGalleryExtension>>;
339343
getExtensions(identifiers: ReadonlyArray<IExtensionIdentifier | IExtensionIdentifierWithVersion>, token: CancellationToken): Promise<IGalleryExtension[]>;
340344
getExtensions(identifiers: ReadonlyArray<IExtensionIdentifier | IExtensionIdentifierWithVersion>, includePreRelease: boolean, token: CancellationToken): Promise<IGalleryExtension[]>;
345+
getExtensions2(identifiers: ReadonlyArray<IExtensionIdentifierWithPreRelease>): Promise<IGalleryExtension[]>;
341346
download(extension: IGalleryExtension, location: URI, operation: InstallOperation): Promise<void>;
342347
reportStatistic(publisher: string, name: string, version: string, type: StatisticType): Promise<void>;
343348
getReadme(extension: IGalleryExtension, token: CancellationToken): Promise<string>;

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ class Extensions extends Disposable {
379379
private installed: Extension[] = [];
380380

381381
constructor(
382-
private readonly server: IExtensionManagementServer,
382+
readonly server: IExtensionManagementServer,
383383
private readonly stateProvider: IExtensionStateProvider<ExtensionState>,
384384
@IExtensionGalleryService private readonly galleryService: IExtensionGalleryService,
385385
@IWorkbenchExtensionEnablementService private readonly extensionEnablementService: IWorkbenchExtensionEnablementService,
@@ -1018,21 +1018,22 @@ export class ExtensionsWorkbenchService extends Disposable implements IExtension
10181018
.then(undefined, err => null);
10191019
}
10201020

1021-
private syncWithGallery(): Promise<void> {
1022-
const ids: string[] = [], names: string[] = [];
1021+
private async syncWithGallery(): Promise<void> {
1022+
const identifiers: (IExtensionIdentifier & { preRelease: boolean })[] = [], names: string[] = [];
10231023
for (const installed of this.local) {
10241024
if (installed.type === ExtensionType.User) {
10251025
if (installed.identifier.uuid) {
1026-
ids.push(installed.identifier.uuid);
1026+
identifiers.push({ ...installed.identifier, preRelease: !!installed.local?.isPreReleaseVersion || !!installed.local?.preRelease });
10271027
} else {
10281028
names.push(installed.identifier.id);
10291029
}
10301030
}
10311031
}
10321032

1033-
const promises: Promise<IPager<IExtension>>[] = [];
1034-
if (ids.length) {
1035-
promises.push(this.queryGallery({ ids, pageSize: ids.length }, CancellationToken.None));
1033+
const promises: Promise<any>[] = [];
1034+
if (identifiers.length) {
1035+
const extensionsControlManifest = await this.extensionManagementService.getExtensionsControlManifest();
1036+
promises.push(this.galleryService.getExtensions2(identifiers).then(galleryExtensions => galleryExtensions.forEach(gallery => this.fromGallery(gallery, extensionsControlManifest))));
10361037
}
10371038
if (names.length) {
10381039
promises.push(this.queryGallery({ names, pageSize: names.length }, CancellationToken.None));

0 commit comments

Comments
 (0)