fix test failures
This commit is contained in:
parent
95be625ad7
commit
4cb12d10c6
5 changed files with 22 additions and 38 deletions
|
@ -14,8 +14,8 @@ export class GlobalExtensionEnablementService extends Disposable implements IGlo
|
|||
|
||||
_serviceBrand: undefined;
|
||||
|
||||
private _onDidChangeEnablement = new Emitter<readonly IExtensionIdentifier[]>();
|
||||
readonly onDidChangeEnablement: Event<readonly IExtensionIdentifier[]> = this._onDidChangeEnablement.event;
|
||||
private _onDidChangeEnablement = new Emitter<{ readonly extensions: IExtensionIdentifier[], readonly source?: string }>();
|
||||
readonly onDidChangeEnablement: Event<{ readonly extensions: IExtensionIdentifier[], readonly source?: string }> = this._onDidChangeEnablement.event;
|
||||
private readonly storageManger: StorageManager;
|
||||
|
||||
constructor(
|
||||
|
@ -23,20 +23,20 @@ export class GlobalExtensionEnablementService extends Disposable implements IGlo
|
|||
) {
|
||||
super();
|
||||
this.storageManger = this._register(new StorageManager(storageService));
|
||||
this._register(this.storageManger.onDidChange(extensions => this._onDidChangeEnablement.fire(extensions)));
|
||||
this._register(this.storageManger.onDidChange(extensions => this._onDidChangeEnablement.fire({ extensions, source: 'storage' })));
|
||||
}
|
||||
|
||||
async enableExtension(extension: IExtensionIdentifier): Promise<boolean> {
|
||||
async enableExtension(extension: IExtensionIdentifier, source?: string): Promise<boolean> {
|
||||
if (this._removeFromDisabledExtensions(extension)) {
|
||||
this._onDidChangeEnablement.fire([extension]);
|
||||
this._onDidChangeEnablement.fire({ extensions: [extension], source });
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
async disableExtension(extension: IExtensionIdentifier): Promise<boolean> {
|
||||
async disableExtension(extension: IExtensionIdentifier, source?: string): Promise<boolean> {
|
||||
if (this._addToDisabledExtensions(extension)) {
|
||||
this._onDidChangeEnablement.fire([extension]);
|
||||
this._onDidChangeEnablement.fire({ extensions: [extension], source });
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -213,11 +213,11 @@ export const IGlobalExtensionEnablementService = createDecorator<IGlobalExtensio
|
|||
|
||||
export interface IGlobalExtensionEnablementService {
|
||||
_serviceBrand: undefined;
|
||||
readonly onDidChangeEnablement: Event<readonly IExtensionIdentifier[]>;
|
||||
readonly onDidChangeEnablement: Event<{ readonly extensions: IExtensionIdentifier[], readonly source?: string }>;
|
||||
|
||||
getDisabledExtensions(): IExtensionIdentifier[];
|
||||
enableExtension(extension: IExtensionIdentifier): Promise<boolean>;
|
||||
disableExtension(extension: IExtensionIdentifier): Promise<boolean>;
|
||||
enableExtension(extension: IExtensionIdentifier, source?: string): Promise<boolean>;
|
||||
disableExtension(extension: IExtensionIdentifier, source?: string): Promise<boolean>;
|
||||
|
||||
// Async method until storage service is available in shared process
|
||||
getDisabledExtensionsAsync(): Promise<IExtensionIdentifier[]>;
|
||||
|
|
|
@ -156,7 +156,7 @@ export class GlobalExtensionEnablementServiceClient implements IGlobalExtensionE
|
|||
|
||||
_serviceBrand: undefined;
|
||||
|
||||
get onDidChangeEnablement(): Event<IExtensionIdentifier[]> { return this.channel.listen('onDidChangeEnablement'); }
|
||||
get onDidChangeEnablement(): Event<{ readonly extensions: IExtensionIdentifier[], readonly source?: string }> { return this.channel.listen('onDidChangeEnablement'); }
|
||||
|
||||
constructor(private readonly channel: IChannel) {
|
||||
}
|
||||
|
|
|
@ -942,16 +942,6 @@ suite('ExtensionsWorkbenchServiceTest', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('test installing an extension re-eanbles it when disabled globally', async () => {
|
||||
testObject = await aWorkbenchService();
|
||||
const local = aLocalExtension('pub.a');
|
||||
await instantiationService.get(IWorkbenchExtensionEnablementService).setEnablement([local], EnablementState.DisabledGlobally);
|
||||
didInstallEvent.fire({ local, identifier: local.identifier, operation: InstallOperation.Install });
|
||||
instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [local]);
|
||||
const actual = await testObject.queryLocal();
|
||||
assert.equal(actual[0].enablementState, EnablementState.EnabledGlobally);
|
||||
});
|
||||
|
||||
test('test updating an extension does not re-eanbles it when disabled globally', async () => {
|
||||
testObject = await aWorkbenchService();
|
||||
const local = aLocalExtension('pub.a');
|
||||
|
@ -962,16 +952,6 @@ suite('ExtensionsWorkbenchServiceTest', () => {
|
|||
assert.equal(actual[0].enablementState, EnablementState.DisabledGlobally);
|
||||
});
|
||||
|
||||
test('test installing an extension re-eanbles it when workspace disabled', async () => {
|
||||
testObject = await aWorkbenchService();
|
||||
const local = aLocalExtension('pub.a');
|
||||
await instantiationService.get(IWorkbenchExtensionEnablementService).setEnablement([local], EnablementState.DisabledWorkspace);
|
||||
didInstallEvent.fire({ local, identifier: local.identifier, operation: InstallOperation.Install });
|
||||
instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [local]);
|
||||
const actual = await testObject.queryLocal();
|
||||
assert.equal(actual[0].enablementState, EnablementState.EnabledGlobally);
|
||||
});
|
||||
|
||||
test('test updating an extension does not re-eanbles it when workspace disabled', async () => {
|
||||
testObject = await aWorkbenchService();
|
||||
const local = aLocalExtension('pub.a');
|
||||
|
|
|
@ -19,6 +19,8 @@ import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
|
|||
import { IProductService } from 'vs/platform/product/common/productService';
|
||||
import { StorageManager } from 'vs/platform/extensionManagement/common/extensionEnablementService';
|
||||
|
||||
const SOURCE = 'IWorkbenchExtensionEnablementService';
|
||||
|
||||
export class ExtensionEnablementService extends Disposable implements IWorkbenchExtensionEnablementService {
|
||||
|
||||
_serviceBrand: undefined;
|
||||
|
@ -40,7 +42,7 @@ export class ExtensionEnablementService extends Disposable implements IWorkbench
|
|||
) {
|
||||
super();
|
||||
this.storageManger = this._register(new StorageManager(storageService));
|
||||
this._register(this.globalExtensionEnablementService.onDidChangeEnablement(extensions => this.onDidChangeExtensions(extensions)));
|
||||
this._register(this.globalExtensionEnablementService.onDidChangeEnablement(({ extensions, source }) => this.onDidChangeExtensions(extensions, source)));
|
||||
this._register(extensionManagementService.onDidUninstallExtension(this._onDidUninstallExtension, this));
|
||||
}
|
||||
|
||||
|
@ -169,13 +171,13 @@ export class ExtensionEnablementService extends Disposable implements IWorkbench
|
|||
private _enableExtension(identifier: IExtensionIdentifier): Promise<boolean> {
|
||||
this._removeFromWorkspaceDisabledExtensions(identifier);
|
||||
this._removeFromWorkspaceEnabledExtensions(identifier);
|
||||
return this.globalExtensionEnablementService.enableExtension(identifier);
|
||||
return this.globalExtensionEnablementService.enableExtension(identifier, SOURCE);
|
||||
}
|
||||
|
||||
private _disableExtension(identifier: IExtensionIdentifier): Promise<boolean> {
|
||||
this._removeFromWorkspaceDisabledExtensions(identifier);
|
||||
this._removeFromWorkspaceEnabledExtensions(identifier);
|
||||
return this.globalExtensionEnablementService.disableExtension(identifier);
|
||||
return this.globalExtensionEnablementService.disableExtension(identifier, SOURCE);
|
||||
}
|
||||
|
||||
private _enableExtensionInWorkspace(identifier: IExtensionIdentifier): void {
|
||||
|
@ -273,11 +275,13 @@ export class ExtensionEnablementService extends Disposable implements IWorkbench
|
|||
this.storageManger.set(storageId, extensions, StorageScope.WORKSPACE);
|
||||
}
|
||||
|
||||
private async onDidChangeExtensions(extensionIdentifiers: ReadonlyArray<IExtensionIdentifier>): Promise<void> {
|
||||
private async onDidChangeExtensions(extensionIdentifiers: ReadonlyArray<IExtensionIdentifier>, source?: string): Promise<void> {
|
||||
if (source !== SOURCE) {
|
||||
const installedExtensions = await this.extensionManagementService.getInstalled();
|
||||
const extensions = installedExtensions.filter(installedExtension => extensionIdentifiers.some(identifier => areSameExtensions(identifier, installedExtension.identifier)));
|
||||
this._onEnablementChanged.fire(extensions);
|
||||
}
|
||||
}
|
||||
|
||||
private _onDidUninstallExtension({ identifier, error }: DidUninstallExtensionEvent): void {
|
||||
if (!error) {
|
||||
|
|
Loading…
Reference in a new issue