Skip to content

Commit d351f7e

Browse files
committed
1 parent 389e428 commit d351f7e

7 files changed

Lines changed: 46 additions & 72 deletions

File tree

src/vs/code/node/cliProcessMain.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ export class Main {
136136

137137
const [id, version] = getIdAndVersion(extension);
138138
return this.extensionManagementService.getInstalled(ExtensionType.User)
139-
.then(installed => this.extensionGalleryService.getExtension({ id }, version)
139+
.then(installed => this.extensionGalleryService.getCompatibleExtension({ id }, version)
140140
.then<IGalleryExtension>(null, err => {
141141
if (err.responseText) {
142142
try {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,11 @@ export interface IExtensionGalleryService {
156156
getManifest(extension: IGalleryExtension, token: CancellationToken): Promise<IExtensionManifest | null>;
157157
getChangelog(extension: IGalleryExtension, token: CancellationToken): Promise<string>;
158158
getCoreTranslation(extension: IGalleryExtension, languageId: string): Promise<ITranslation | null>;
159-
loadCompatibleVersion(extension: IGalleryExtension, fromVersion?: string): Promise<IGalleryExtension | null>;
160159
getAllVersions(extension: IGalleryExtension, compatible: boolean): Promise<IGalleryExtensionVersion[]>;
161160
loadAllDependencies(dependencies: IExtensionIdentifier[], token: CancellationToken): Promise<IGalleryExtension[]>;
162161
getExtensionsReport(): Promise<IReportedExtension[]>;
163-
getExtension(id: IExtensionIdentifier, version?: string): Promise<IGalleryExtension | null>;
162+
getCompatibleExtension(extension: IGalleryExtension): Promise<IGalleryExtension | null>;
163+
getCompatibleExtension(id: IExtensionIdentifier, version?: string): Promise<IGalleryExtension | null>;
164164
}
165165

166166
export interface InstallExtensionEvent {

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

Lines changed: 32 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { tmpdir } from 'os';
77
import * as path from 'path';
88
import { distinct } from 'vs/base/common/arrays';
99
import { getErrorMessage, isPromiseCanceledError, canceled } from 'vs/base/common/errors';
10-
import { StatisticType, IGalleryExtension, IExtensionGalleryService, IGalleryExtensionAsset, IQueryOptions, SortBy, SortOrder, IExtensionIdentifier, IReportedExtension, InstallOperation, ITranslation, IGalleryExtensionVersion, IGalleryExtensionAssets } from 'vs/platform/extensionManagement/common/extensionManagement';
10+
import { StatisticType, IGalleryExtension, IExtensionGalleryService, IGalleryExtensionAsset, IQueryOptions, SortBy, SortOrder, IExtensionIdentifier, IReportedExtension, InstallOperation, ITranslation, IGalleryExtensionVersion, IGalleryExtensionAssets, isIExtensionIdentifier } from 'vs/platform/extensionManagement/common/extensionManagement';
1111
import { getGalleryExtensionId, getGalleryExtensionTelemetryData, adoptToGalleryExtensionId } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
1212
import { assign, getOrDefault } from 'vs/base/common/objects';
1313
import { IRequestService } from 'vs/platform/request/node/request';
@@ -351,29 +351,49 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
351351
return !!this.extensionsGalleryUrl;
352352
}
353353

354-
getExtension({ id, uuid }: IExtensionIdentifier, version?: string): Promise<IGalleryExtension | null> {
354+
getCompatibleExtension(arg1: IExtensionIdentifier | IGalleryExtension, version?: string): Promise<IGalleryExtension | null> {
355+
const extension: IGalleryExtension | null = isIExtensionIdentifier(arg1) ? null : arg1;
356+
if (extension && extension.properties.engine && isEngineValid(extension.properties.engine)) {
357+
return Promise.resolve(extension);
358+
}
359+
const { id, uuid } = extension ? extension.identifier : <IExtensionIdentifier>arg1;
355360
let query = new Query()
356361
.withFlags(Flags.IncludeAssetUri, Flags.IncludeStatistics, Flags.IncludeFiles, Flags.IncludeVersionProperties, Flags.ExcludeNonValidated)
357362
.withPage(1, 1)
358363
.withFilter(FilterType.Target, 'Microsoft.VisualStudio.Code')
359-
.withFilter(FilterType.ExcludeWithFlags, flagsToString(Flags.Unpublished));
364+
.withFilter(FilterType.ExcludeWithFlags, flagsToString(Flags.Unpublished))
365+
.withAssetTypes(AssetType.Manifest, AssetType.VSIX);
360366

361367
if (uuid) {
362368
query = query.withFilter(FilterType.ExtensionId, uuid);
363369
} else {
364370
query = query.withFilter(FilterType.ExtensionName, id);
365371
}
366372

367-
return this.queryGallery(query, CancellationToken.None).then(({ galleryExtensions }) => {
368-
if (galleryExtensions.length) {
369-
const galleryExtension = galleryExtensions[0];
370-
const versionAsset = version ? galleryExtension.versions.filter(v => v.version === version)[0] : galleryExtension.versions[0];
371-
if (versionAsset) {
372-
return toExtension(galleryExtension, versionAsset, 0, query);
373+
return this.queryGallery(query, CancellationToken.None)
374+
.then(({ galleryExtensions }) => {
375+
const [rawExtension] = galleryExtensions;
376+
if (!rawExtension || !rawExtension.versions.length) {
377+
return null;
373378
}
374-
}
375-
return null;
376-
});
379+
if (version) {
380+
const versionAsset = rawExtension.versions.filter(v => v.version === version)[0];
381+
if (versionAsset) {
382+
const extension = toExtension(rawExtension, versionAsset, 0, query);
383+
if (extension.properties.engine && isEngineValid(extension.properties.engine)) {
384+
return extension;
385+
}
386+
}
387+
return null;
388+
}
389+
return this.getLastValidExtensionVersion(rawExtension, rawExtension.versions)
390+
.then(rawVersion => {
391+
if (rawVersion) {
392+
return toExtension(rawExtension, rawVersion, 0, query);
393+
}
394+
return null;
395+
});
396+
});
377397
}
378398

379399
query(options: IQueryOptions = {}): Promise<IPager<IGalleryExtension>> {
@@ -604,59 +624,6 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
604624
});
605625
}
606626

607-
loadCompatibleVersion(extension: IGalleryExtension, fromVersion: string = extension.version): Promise<IGalleryExtension | null> {
608-
if (extension.version === fromVersion && extension.properties.engine && isEngineValid(extension.properties.engine)) {
609-
return Promise.resolve(extension);
610-
}
611-
const query = new Query()
612-
.withFlags(Flags.IncludeVersions, Flags.IncludeFiles, Flags.IncludeVersionProperties, Flags.ExcludeNonValidated)
613-
.withPage(1, 1)
614-
.withFilter(FilterType.Target, 'Microsoft.VisualStudio.Code')
615-
.withFilter(FilterType.ExcludeWithFlags, flagsToString(Flags.Unpublished))
616-
.withAssetTypes(AssetType.Manifest, AssetType.VSIX)
617-
.withFilter(FilterType.ExtensionId, extension.identifier.uuid);
618-
619-
return this.queryGallery(query, CancellationToken.None)
620-
.then(({ galleryExtensions }) => {
621-
const [rawExtension] = galleryExtensions;
622-
623-
if (!rawExtension) {
624-
return null;
625-
}
626-
627-
const versions: IRawGalleryExtensionVersion[] = this.getVersionsFrom(rawExtension.versions, fromVersion);
628-
if (!versions.length) {
629-
return null;
630-
}
631-
632-
return this.getLastValidExtensionVersion(rawExtension, versions)
633-
.then(rawVersion => {
634-
if (rawVersion) {
635-
return toExtension(rawExtension, rawVersion, 0, query);
636-
}
637-
return null;
638-
});
639-
});
640-
}
641-
642-
private getVersionsFrom(versions: IRawGalleryExtensionVersion[], version: string): IRawGalleryExtensionVersion[] {
643-
if (versions[0].version === version) {
644-
return versions;
645-
}
646-
const result: IRawGalleryExtensionVersion[] = [];
647-
let currentVersion: IRawGalleryExtensionVersion | null = null;
648-
for (const v of versions) {
649-
if (!currentVersion) {
650-
if (v.version === version) {
651-
currentVersion = v;
652-
}
653-
}
654-
if (currentVersion) {
655-
result.push(v);
656-
}
657-
}
658-
return result;
659-
}
660627

661628
private loadDependencies(extensionNames: string[], token: CancellationToken): Promise<IGalleryExtension[]> {
662629
if (!extensionNames || extensionNames.length === 0) {

src/vs/platform/extensionManagement/node/extensionManagementService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ export class ExtensionManagementService extends Disposable implements IExtension
333333
return Promise.reject(new ExtensionManagementError(nls.localize('malicious extension', "Can't install extension since it was reported to be problematic."), INSTALL_ERROR_MALICIOUS));
334334
}
335335

336-
const compatibleExtension = await this.galleryService.loadCompatibleVersion(extension);
336+
const compatibleExtension = await this.galleryService.getCompatibleExtension(extension);
337337

338338
if (!compatibleExtension) {
339339
return Promise.reject(new ExtensionManagementError(nls.localize('notFoundCompatibleDependency', "Unable to install because, the extension '{0}' compatible with current version '{1}' of VS Code is not found.", extension.identifier.id, pkg.version), INSTALL_ERROR_INCOMPATIBLE));

src/vs/platform/extensions/common/extensions.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,13 @@ export class ExtensionIdentifierWithVersion {
129129
}
130130
}
131131

132+
export function isIExtensionIdentifier(thing: any): thing is IExtensionIdentifier {
133+
return thing
134+
&& typeof thing === 'object'
135+
&& typeof thing.id === 'string'
136+
&& (!thing.uuid || typeof thing.uuid === 'string');
137+
}
138+
132139
export interface IExtensionIdentifier {
133140
id: string;
134141
uuid?: string;

src/vs/workbench/parts/extensions/node/extensionsWorkbenchService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ export class ExtensionsWorkbenchService implements IExtensionsWorkbenchService,
507507
// Loading the compatible version only there is an engine property
508508
// Otherwise falling back to old way so that we will not make many roundtrips
509509
if (gallery.properties.engine) {
510-
this.galleryService.loadCompatibleVersion(gallery)
510+
this.galleryService.getCompatibleExtension(gallery)
511511
.then(compatible => compatible ? this.syncLocalWithGalleryExtension(result!, compatible) : null);
512512
} else {
513513
this.syncLocalWithGalleryExtension(result, gallery);
@@ -679,7 +679,7 @@ export class ExtensionsWorkbenchService implements IExtensionsWorkbenchService,
679679
return Promise.reject(new Error('Missing gallery'));
680680
}
681681

682-
return this.galleryService.getExtension(extension.gallery.identifier, version)
682+
return this.galleryService.getCompatibleExtension(extension.gallery.identifier, version)
683683
.then(gallery => {
684684
if (!gallery) {
685685
return undefined;

src/vs/workbench/services/extensions/electron-browser/inactiveExtensionUrlHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ export class ExtensionUrlHandler implements IExtensionUrlHandler, IURLHandler {
190190

191191
// Extension is not installed
192192
else {
193-
const galleryExtension = await this.galleryService.getExtension(extensionIdentifier);
193+
const galleryExtension = await this.galleryService.getCompatibleExtension(extensionIdentifier);
194194

195195
if (!galleryExtension) {
196196
return;

0 commit comments

Comments
 (0)