Skip to content

Commit fb26bec

Browse files
committed
#139015 refactor gallery service
- unify apis in IExtensionGalleryService
1 parent 9f96093 commit fb26bec

File tree

11 files changed

+53
-77
lines changed

11 files changed

+53
-77
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ export abstract class AbstractExtensionManagementService extends Disposable impl
394394
let compatibleExtension: IGalleryExtension | null = null;
395395

396396
if (fetchCompatibleVersion && extension.hasPreReleaseVersion && extension.properties.isPreReleaseVersion !== includePreRelease) {
397-
compatibleExtension = await this.galleryService.getCompatibleExtension(extension.identifier, includePreRelease, targetPlatform);
397+
compatibleExtension = (await this.galleryService.getExtensions([{ ...extension.identifier, preRelease: includePreRelease }], { targetPlatform, compatible: true }, CancellationToken.None))[0] || null;
398398
}
399399

400400
if (!compatibleExtension && await this.galleryService.isExtensionCompatible(extension, includePreRelease, targetPlatform)) {

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

+30-43
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, IExtensionIdentifierWithPreRelease } from 'vs/platform/extensionManagement/common/extensionManagement';
19+
import { DefaultIconPath, getFallbackTargetPlarforms, getTargetPlatform, IExtensionGalleryService, IExtensionIdentifier, IExtensionInfo, IGalleryExtension, IGalleryExtensionAsset, IGalleryExtensionAssets, IGalleryExtensionVersion, InstallOperation, IQueryOptions, IExtensionsControlManifest, isNotWebExtensionInWebTargetPlatform, isTargetPlatformCompatible, ITranslation, SortBy, SortOrder, StatisticType, TargetPlatform, toTargetPlatform, WEB_EXTENSION_TAG } 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';
@@ -278,8 +278,8 @@ type GalleryServiceAdditionalQueryEvent = {
278278
interface IExtensionCriteria {
279279
readonly targetPlatform: TargetPlatform;
280280
readonly compatible: boolean;
281-
readonly preRelease: boolean | IExtensionIdentifierWithPreRelease[];
282-
readonly versions?: IExtensionIdentifierWithVersion[];
281+
readonly preRelease: boolean | (IExtensionIdentifier & { preRelease: boolean })[];
282+
readonly versions?: (IExtensionIdentifier & { version: string })[];
283283
}
284284

285285
class Query {
@@ -562,65 +562,52 @@ abstract class AbstractExtensionGalleryService implements IExtensionGalleryServi
562562
return !!this.extensionsGalleryUrl;
563563
}
564564

565-
getExtensions(identifiers: ReadonlyArray<IExtensionIdentifier | IExtensionIdentifierWithVersion>, token: CancellationToken): Promise<IGalleryExtension[]>;
566-
getExtensions(identifiers: ReadonlyArray<IExtensionIdentifier | IExtensionIdentifierWithVersion>, includePreRelease: boolean, token: CancellationToken): Promise<IGalleryExtension[]>;
567-
async getExtensions(identifiers: ReadonlyArray<IExtensionIdentifier | IExtensionIdentifierWithVersion>, arg1: any, arg2?: any): Promise<IGalleryExtension[]> {
568-
const preRelease = isBoolean(arg1) ? arg1 : false;
569-
const token: CancellationToken = isBoolean(arg1) ? arg2 : arg1;
570-
const versions: IExtensionIdentifierWithVersion[] = (identifiers as ReadonlyArray<IExtensionIdentifierWithVersion>).filter(identifier => !!identifier.version);
571-
const query = new Query()
572-
.withPage(1, identifiers.length)
573-
.withFilter(FilterType.ExtensionName, ...identifiers.map(({ id }) => id.toLowerCase()));
574-
575-
const { extensions } = await this.queryGalleryExtensions(query, { targetPlatform: CURRENT_TARGET_PLATFORM, preRelease, versions, compatible: false }, token);
576-
return extensions;
577-
}
578-
579-
async getCompatibleExtensions(identifiers: ReadonlyArray<IExtensionIdentifierWithPreRelease>, targetPlatform: TargetPlatform): Promise<IGalleryExtension[]> {
580-
const names: string[] = []; const ids: string[] = [];
581-
for (const identifier of identifiers) {
582-
if (identifier.uuid) {
583-
ids.push(identifier.uuid);
565+
getExtensions(extensionInfos: ReadonlyArray<IExtensionInfo>, token: CancellationToken): Promise<IGalleryExtension[]>;
566+
getExtensions(extensionInfos: ReadonlyArray<IExtensionInfo>, options: { targetPlatform: TargetPlatform, compatible?: boolean }, token: CancellationToken): Promise<IGalleryExtension[]>;
567+
async getExtensions(extensionInfos: ReadonlyArray<IExtensionInfo>, arg1: any, arg2?: any): Promise<IGalleryExtension[]> {
568+
const options = CancellationToken.isCancellationToken(arg1) ? { targetPlatform: CURRENT_TARGET_PLATFORM } : arg1 as { targetPlatform: TargetPlatform, compatible?: boolean };
569+
const token = CancellationToken.isCancellationToken(arg1) ? arg1 : arg2 as CancellationToken;
570+
const names: string[] = []; const ids: string[] = [], preRelease: (IExtensionIdentifier & { preRelease: boolean })[] = [], versions: (IExtensionIdentifier & { version: string })[] = [];
571+
for (const extensionInfo of extensionInfos) {
572+
if (extensionInfo.uuid) {
573+
ids.push(extensionInfo.uuid);
584574
} else {
585-
names.push(identifier.id.toLowerCase());
575+
names.push(extensionInfo.id);
576+
}
577+
preRelease.push({ ...extensionInfo, preRelease: !!extensionInfo.preRelease });
578+
if (extensionInfo.version) {
579+
versions.push({ ...extensionInfo, version: extensionInfo.version });
586580
}
587581
}
588582

589583
if (!ids.length && !names.length) {
590584
return [];
591585
}
592586

593-
let query = new Query().withPage(1, identifiers.length);
587+
let query = new Query().withPage(1, extensionInfos.length);
594588
if (ids.length) {
595589
query = query.withFilter(FilterType.ExtensionId, ...ids);
596590
}
597591
if (names.length) {
598592
query = query.withFilter(FilterType.ExtensionName, ...names);
599593
}
600594

601-
const { extensions } = await this.queryGalleryExtensions(query, { targetPlatform, compatible: true, preRelease: [...identifiers] }, CancellationToken.None);
595+
const { extensions } = await this.queryGalleryExtensions(query, { targetPlatform: options.targetPlatform, preRelease, versions, compatible: !!options.compatible }, token);
602596
return extensions;
603597
}
604598

605-
async getCompatibleExtension(arg1: IExtensionIdentifier | IGalleryExtension, includePreRelease: boolean, targetPlatform: TargetPlatform): Promise<IGalleryExtension | null> {
606-
const extension: IGalleryExtension | null = isIExtensionIdentifier(arg1) ? null : arg1;
607-
608-
if (extension) {
609-
if (isNotWebExtensionInWebTargetPlatform(extension.allTargetPlatforms, targetPlatform)) {
610-
return null;
611-
}
612-
if (await this.isExtensionCompatible(extension, includePreRelease, targetPlatform)) {
613-
return extension;
614-
}
615-
const query = new Query()
616-
.withFlags(Flags.IncludeVersions)
617-
.withPage(1, 1)
618-
.withFilter(FilterType.ExtensionId, extension.identifier.uuid);
619-
const { extensions } = await this.queryGalleryExtensions(query, { targetPlatform, compatible: true, preRelease: includePreRelease }, CancellationToken.None);
620-
return extensions[0] || null;
599+
async getCompatibleExtension(extension: IGalleryExtension, includePreRelease: boolean, targetPlatform: TargetPlatform): Promise<IGalleryExtension | null> {
600+
if (isNotWebExtensionInWebTargetPlatform(extension.allTargetPlatforms, targetPlatform)) {
601+
return null;
621602
}
622-
623-
const extensions = await this.getCompatibleExtensions([{ ...(<IExtensionIdentifier>arg1), preRelease: includePreRelease }], targetPlatform);
603+
if (await this.isExtensionCompatible(extension, includePreRelease, targetPlatform)) {
604+
return extension;
605+
}
606+
const query = new Query()
607+
.withFlags(Flags.IncludeVersions)
608+
.withPage(1, 1)
609+
.withFilter(FilterType.ExtensionId, extension.identifier.uuid);
610+
const { extensions } = await this.queryGalleryExtensions(query, { targetPlatform, compatible: true, preRelease: includePreRelease }, CancellationToken.None);
624611
return extensions[0] || null;
625612
}
626613

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

+8-15
Original file line numberDiff line numberDiff line change
@@ -222,14 +222,9 @@ export interface IExtensionIdentifier {
222222
uuid?: string;
223223
}
224224

225-
export interface IExtensionIdentifierWithVersion extends IExtensionIdentifier {
226-
id: string;
227-
uuid?: string;
228-
version: string;
229-
}
230-
231-
export interface IExtensionIdentifierWithPreRelease extends IExtensionIdentifier {
232-
preRelease: boolean;
225+
export interface IExtensionInfo extends IExtensionIdentifier {
226+
version?: string;
227+
preRelease?: boolean;
233228
}
234229

235230
export interface IGalleryExtensionIdentifier extends IExtensionIdentifier {
@@ -340,20 +335,18 @@ export interface IExtensionGalleryService {
340335
readonly _serviceBrand: undefined;
341336
isEnabled(): boolean;
342337
query(options: IQueryOptions, token: CancellationToken): Promise<IPager<IGalleryExtension>>;
343-
getExtensions(identifiers: ReadonlyArray<IExtensionIdentifier | IExtensionIdentifierWithVersion>, token: CancellationToken): Promise<IGalleryExtension[]>;
344-
getExtensions(identifiers: ReadonlyArray<IExtensionIdentifier | IExtensionIdentifierWithVersion>, includePreRelease: boolean, token: CancellationToken): Promise<IGalleryExtension[]>;
338+
getExtensions(extensionInfos: ReadonlyArray<IExtensionInfo>, token: CancellationToken): Promise<IGalleryExtension[]>;
339+
getExtensions(extensionInfos: ReadonlyArray<IExtensionInfo>, options: { targetPlatform: TargetPlatform, compatible?: boolean }, token: CancellationToken): Promise<IGalleryExtension[]>;
340+
isExtensionCompatible(extension: IGalleryExtension, includePreRelease: boolean, targetPlatform: TargetPlatform): Promise<boolean>;
341+
getCompatibleExtension(extension: IGalleryExtension, includePreRelease: boolean, targetPlatform: TargetPlatform): Promise<IGalleryExtension | null>;
342+
getAllCompatibleVersions(extension: IGalleryExtension, includePreRelease: boolean, targetPlatform: TargetPlatform): Promise<IGalleryExtensionVersion[]>;
345343
download(extension: IGalleryExtension, location: URI, operation: InstallOperation): Promise<void>;
346344
reportStatistic(publisher: string, name: string, version: string, type: StatisticType): Promise<void>;
347345
getReadme(extension: IGalleryExtension, token: CancellationToken): Promise<string>;
348346
getManifest(extension: IGalleryExtension, token: CancellationToken): Promise<IExtensionManifest | null>;
349347
getChangelog(extension: IGalleryExtension, token: CancellationToken): Promise<string>;
350348
getCoreTranslation(extension: IGalleryExtension, languageId: string): Promise<ITranslation | null>;
351349
getExtensionsControlManifest(): Promise<IExtensionsControlManifest>;
352-
isExtensionCompatible(extension: IGalleryExtension, includePreRelease: boolean, targetPlatform: TargetPlatform): Promise<boolean>;
353-
getCompatibleExtensions(identifiers: ReadonlyArray<IExtensionIdentifierWithPreRelease>, targetPlatform: TargetPlatform): Promise<IGalleryExtension[]>;
354-
getCompatibleExtension(extension: IGalleryExtension, includePreRelease: boolean, targetPlatform: TargetPlatform): Promise<IGalleryExtension | null>;
355-
getCompatibleExtension(id: IExtensionIdentifier, includePreRelease: boolean, targetPlatform: TargetPlatform): Promise<IGalleryExtension | null>;
356-
getAllCompatibleVersions(extension: IGalleryExtension, includePreRelease: boolean, targetPlatform: TargetPlatform): Promise<IGalleryExtensionVersion[]>;
357350
}
358351

359352
export interface InstallExtensionEvent {

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ export class ExtensionManagementCLIService implements IExtensionManagementCLISer
200200

201201
private async getGalleryExtensions(extensions: InstallExtensionInfo[]): Promise<Map<string, IGalleryExtension>> {
202202
const galleryExtensions = new Map<string, IGalleryExtension>();
203-
const result = await this.extensionGalleryService.getExtensions(extensions, extensions.some(e => e.installOptions.installPreReleaseVersion), CancellationToken.None);
203+
const preRelease = extensions.some(e => e.installOptions.installPreReleaseVersion);
204+
const result = await this.extensionGalleryService.getExtensions(extensions.map(e => ({...e, preRelease})), CancellationToken.None);
204205
for (const extension of result) {
205206
galleryExtensions.set(extension.identifier.id.toLowerCase(), extension);
206207
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { compareIgnoreCase } from 'vs/base/common/strings';
7-
import { IExtensionIdentifier, IExtensionIdentifierWithVersion, IGalleryExtension, ILocalExtension, IExtensionsControlManifest } from 'vs/platform/extensionManagement/common/extensionManagement';
7+
import { IExtensionIdentifier, IGalleryExtension, ILocalExtension, IExtensionsControlManifest } from 'vs/platform/extensionManagement/common/extensionManagement';
88
import { ExtensionIdentifier, IExtension } from 'vs/platform/extensions/common/extensions';
99

1010
export function areSameExtensions(a: IExtensionIdentifier, b: IExtensionIdentifier): boolean {
@@ -17,7 +17,7 @@ export function areSameExtensions(a: IExtensionIdentifier, b: IExtensionIdentifi
1717
return compareIgnoreCase(a.id, b.id) === 0;
1818
}
1919

20-
export class ExtensionIdentifierWithVersion implements IExtensionIdentifierWithVersion {
20+
export class ExtensionIdentifierWithVersion {
2121

2222
readonly id: string;
2323
readonly uuid?: string;

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6+
import { CancellationToken } from 'vs/base/common/cancellation';
67
import { IExtensionGalleryService, IExtensionManagementService, IGlobalExtensionEnablementService, InstallOperation } from 'vs/platform/extensionManagement/common/extensionManagement';
78
import { areSameExtensions, getExtensionId } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
89
import { IExtensionStorageService } from 'vs/platform/extensionManagement/common/extensionStorage';
@@ -30,7 +31,7 @@ export async function migrateUnsupportedExtensions(extensionManagementService: I
3031
continue;
3132
}
3233

33-
const gallery = await galleryService.getCompatibleExtension({ id: preReleaseExtensionId }, true, await extensionManagementService.getTargetPlatform());
34+
const gallery = (await galleryService.getExtensions([{ id: preReleaseExtensionId, preRelease: true }], { targetPlatform: await extensionManagementService.getTargetPlatform(), compatible: true }, CancellationToken.None))[0];
3435
if (!gallery) {
3536
logService.info(`Skipping migrating '${unsupportedExtension.identifier.id}' extension because, the comaptible target '${preReleaseExtensionId}' extension is not found`);
3637
continue;

src/vs/platform/userDataSync/common/extensionsSync.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ export class ExtensionsSynchroniser extends AbstractSynchroniser implements IUse
378378
}
379379

380380
// User Extension Sync: Install/Update, Enablement & State
381-
const extension = (await this.extensionGalleryService.getExtensions([e.identifier], !!e.preRelease, CancellationToken.None))[0];
381+
const extension = (await this.extensionGalleryService.getExtensions([{ ...e.identifier, preRelease: e.preRelease }], CancellationToken.None))[0];
382382

383383
/* Update extension state only if
384384
* extension is installed and version is same as synced version or

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -2623,7 +2623,7 @@ export class InstallLocalExtensionsInRemoteAction extends AbstractInstallExtensi
26232623
const targetPlatform = await this.extensionManagementServerService.remoteExtensionManagementServer!.extensionManagementService.getTargetPlatform();
26242624
await Promises.settled(localExtensionsToInstall.map(async extension => {
26252625
if (this.extensionGalleryService.isEnabled()) {
2626-
const gallery = await this.extensionGalleryService.getCompatibleExtension(extension.identifier, !!extension.local?.preRelease, targetPlatform);
2626+
const gallery = (await this.extensionGalleryService.getExtensions([{ ...extension.identifier, preRelease: !!extension.local?.preRelease }], { targetPlatform, compatible: true }, CancellationToken.None))[0];
26272627
if (gallery) {
26282628
galleryExtensions.push(gallery);
26292629
return;
@@ -2672,7 +2672,7 @@ export class InstallRemoteExtensionsInLocalAction extends AbstractInstallExtensi
26722672
const targetPlatform = await this.extensionManagementServerService.localExtensionManagementServer!.extensionManagementService.getTargetPlatform();
26732673
await Promises.settled(extensions.map(async extension => {
26742674
if (this.extensionGalleryService.isEnabled()) {
2675-
const gallery = await this.extensionGalleryService.getCompatibleExtension(extension.identifier, !!extension.local?.preRelease, targetPlatform);
2675+
const gallery = (await this.extensionGalleryService.getExtensions([{ ...extension.identifier, preRelease: !!extension.local?.preRelease }], { targetPlatform, compatible: true }, CancellationToken.None))[0];
26762676
if (gallery) {
26772677
galleryExtensions.push(gallery);
26782678
return;

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ class Extensions extends Disposable {
463463

464464
private async getCompatibleExtension(extensionOrIdentifier: IGalleryExtension | IExtensionIdentifier, includePreRelease: boolean): Promise<IGalleryExtension | null> {
465465
if (isIExtensionIdentifier(extensionOrIdentifier)) {
466-
return this.galleryService.getCompatibleExtension(extensionOrIdentifier, includePreRelease, await this.server.extensionManagementService.getTargetPlatform());
466+
return (await this.galleryService.getExtensions([{ ...extensionOrIdentifier, preRelease: includePreRelease }], { targetPlatform: await this.server.extensionManagementService.getTargetPlatform(), compatible: true }, CancellationToken.None))[0] || null;
467467
}
468468
const extension = extensionOrIdentifier;
469469
if (includePreRelease && extension.hasPreReleaseVersion && !extension.properties.isPreReleaseVersion) {
@@ -1023,7 +1023,7 @@ export class ExtensionsWorkbenchService extends Disposable implements IExtension
10231023

10241024
if (identifiers.length) {
10251025
const extensionsControlManifest = await this.extensionManagementService.getExtensionsControlManifest();
1026-
const galleryExtensions = await this.galleryService.getCompatibleExtensions(identifiers, targetPlatform);
1026+
const galleryExtensions = await this.galleryService.getExtensions(identifiers, { targetPlatform, compatible: true }, CancellationToken.None);
10271027
galleryExtensions.forEach(gallery => this.fromGallery(gallery, extensionsControlManifest));
10281028
}
10291029
}

src/vs/workbench/contrib/extensions/test/electron-browser/extensionsWorkbenchService.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ suite('ExtensionsWorkbenchServiceTest', () => {
309309
instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [local1, local2]);
310310
instantiationService.stubPromise(IExtensionGalleryService, 'query', aPage(gallery1));
311311
instantiationService.stubPromise(IExtensionGalleryService, 'getCompatibleExtension', gallery1);
312-
instantiationService.stubPromise(IExtensionGalleryService, 'getCompatibleExtensions', [gallery1]);
312+
instantiationService.stubPromise(IExtensionGalleryService, 'getExtensions', [gallery1]);
313313
testObject = await aWorkbenchService();
314314
await testObject.queryLocal();
315315

@@ -433,7 +433,7 @@ suite('ExtensionsWorkbenchServiceTest', () => {
433433
const gallery = aGalleryExtension(local.manifest.name, { identifier: local.identifier });
434434
instantiationService.stubPromise(IExtensionGalleryService, 'query', aPage(gallery));
435435
instantiationService.stubPromise(IExtensionGalleryService, 'getCompatibleExtension', gallery);
436-
instantiationService.stubPromise(IExtensionGalleryService, 'getCompatibleExtensions', [gallery]);
436+
instantiationService.stubPromise(IExtensionGalleryService, 'getExtensions', [gallery]);
437437
testObject = await aWorkbenchService();
438438
const target = testObject.local[0];
439439

0 commit comments

Comments
 (0)