Skip to content

Commit b7faf23

Browse files
authored
1 parent 055bc4f commit b7faf23

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { IPager, singlePagePager } from 'vs/base/common/paging';
1414
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
1515
import {
1616
IExtensionGalleryService, ILocalExtension, IGalleryExtension, IQueryOptions,
17-
InstallExtensionEvent, DidUninstallExtensionEvent, IExtensionIdentifier, InstallOperation, InstallOptions, WEB_EXTENSION_TAG, InstallExtensionResult,
17+
InstallExtensionEvent, DidUninstallExtensionEvent, InstallOperation, InstallOptions, WEB_EXTENSION_TAG, InstallExtensionResult,
1818
IExtensionsControlManifest, InstallVSIXOptions, IExtensionInfo, IExtensionQueryOptions, IDeprecationInfo
1919
} from 'vs/platform/extensionManagement/common/extensionManagement';
2020
import { IWorkbenchExtensionEnablementService, EnablementState, IExtensionManagementServerService, IExtensionManagementServer, IWorkbenchExtensionManagementService, DefaultIconPath } from 'vs/workbench/services/extensionManagement/common/extensionManagement';
@@ -34,7 +34,7 @@ import * as resources from 'vs/base/common/resources';
3434
import { CancellationToken } from 'vs/base/common/cancellation';
3535
import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage';
3636
import { IFileService } from 'vs/platform/files/common/files';
37-
import { IExtensionManifest, ExtensionType, IExtension as IPlatformExtension, TargetPlatform, ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
37+
import { IExtensionManifest, ExtensionType, IExtension as IPlatformExtension, TargetPlatform, ExtensionIdentifier, IExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
3838
import { ILanguageService } from 'vs/editor/common/languages/language';
3939
import { IProductService } from 'vs/platform/product/common/productService';
4040
import { FileAccess } from 'vs/base/common/network';
@@ -1331,7 +1331,7 @@ export class ExtensionsWorkbenchService extends Disposable implements IExtension
13311331
this.ignoreAutoUpdate(new ExtensionKey(identifier, manifest.version));
13321332
}
13331333

1334-
return this.local.filter(local => areSameExtensions(local.identifier, identifier))[0];
1334+
return this.waitAndGetInstalledExtension(identifier);
13351335
}
13361336

13371337
private async installFromGallery(extension: IExtension, gallery: IGalleryExtension, installOptions?: InstallOptions): Promise<IExtension> {
@@ -1343,13 +1343,26 @@ export class ExtensionsWorkbenchService extends Disposable implements IExtension
13431343
} else {
13441344
await this.extensionManagementService.installFromGallery(gallery, installOptions);
13451345
}
1346-
return this.local.filter(local => areSameExtensions(local.identifier, gallery.identifier))[0];
1346+
return this.waitAndGetInstalledExtension(gallery.identifier);
13471347
} finally {
13481348
this.installing = this.installing.filter(e => e !== extension);
13491349
this._onChange.fire(this.local.filter(e => areSameExtensions(e.identifier, extension.identifier))[0]);
13501350
}
13511351
}
13521352

1353+
private async waitAndGetInstalledExtension(identifier: IExtensionIdentifier): Promise<IExtension> {
1354+
let installedExtension = this.local.find(local => areSameExtensions(local.identifier, identifier));
1355+
if (!installedExtension) {
1356+
await Event.toPromise(Event.filter(this.onChange, e => !!e && this.local.some(local => areSameExtensions(local.identifier, identifier))));
1357+
}
1358+
installedExtension = this.local.find(local => areSameExtensions(local.identifier, identifier));
1359+
if (!installedExtension) {
1360+
// This should not happen
1361+
throw new Error('Extension should have been installed');
1362+
}
1363+
return installedExtension;
1364+
}
1365+
13531366
private promptAndSetEnablement(extensions: IExtension[], enablementState: EnablementState): Promise<any> {
13541367
const enable = enablementState === EnablementState.EnabledGlobally || enablementState === EnablementState.EnabledWorkspace;
13551368
if (enable) {

0 commit comments

Comments
 (0)