提交 955c2468 编写于 作者: S Sandeep Somavarapu

#14841 Fix extensionsWorkbenchService

- Enabling an extension globally should enable it for workspace also
上级 f7afdaa2
......@@ -56,25 +56,19 @@ export class ExtensionEnablementService implements IExtensionEnablementService {
return TPromise.wrap(false);
}
if (this.isDisabled(identifier) === !enable) {
return TPromise.wrap(false);
}
if (enable) {
if (workspace) {
this.enableExtension(identifier, StorageScope.WORKSPACE);
return this.enableExtension(identifier, StorageScope.WORKSPACE);
} else {
this.enableExtension(identifier, StorageScope.GLOBAL);
return this.enableExtension(identifier, StorageScope.GLOBAL);
}
} else {
if (workspace) {
this.disableExtension(identifier, StorageScope.WORKSPACE);
return this.disableExtension(identifier, StorageScope.WORKSPACE);
} else {
this.disableExtension(identifier, StorageScope.GLOBAL);
return this.disableExtension(identifier, StorageScope.GLOBAL);
}
}
return TPromise.wrap(true);
}
private getDisabledExtensions(): string[] {
......@@ -99,9 +93,13 @@ export class ExtensionEnablementService implements IExtensionEnablementService {
private disableExtension(identifier: string, scope: StorageScope): TPromise<boolean> {
let disabledExtensions = this._getDisabledExtensions(scope);
disabledExtensions.push(identifier);
this._setDisabledExtensions(disabledExtensions, scope, identifier);
return TPromise.wrap(true);
const index = disabledExtensions.indexOf(identifier);
if (index === -1) {
disabledExtensions.push(identifier);
this._setDisabledExtensions(disabledExtensions, scope, identifier);
return TPromise.wrap(true);
}
return TPromise.wrap(false);
}
private enableExtension(identifier: string, scope: StorageScope): TPromise<boolean> {
......@@ -110,8 +108,9 @@ export class ExtensionEnablementService implements IExtensionEnablementService {
if (index !== -1) {
disabledExtensions.splice(index, 1);
this._setDisabledExtensions(disabledExtensions, scope, identifier);
return TPromise.wrap(true);
}
return TPromise.wrap(true);
return TPromise.wrap(false);
}
private _getDisabledExtensions(scope: StorageScope): string[] {
......
......@@ -502,7 +502,7 @@ export class ExtensionsWorkbenchService implements IExtensionsWorkbenchService {
return TPromise.wrap(null);
}
return this.extensionEnablementService.setEnablement(extension.identifier, enable, workspace).then(reload => {
return this.doSetEnablement(extension, enable, workspace).then(reload => {
this.telemetryService.publicLog(enable ? 'extension:enable' : 'extension:disable', extension.telemetryData);
});
}
......@@ -520,6 +520,20 @@ export class ExtensionsWorkbenchService implements IExtensionsWorkbenchService {
}
return this.extensionService.uninstall(local);
}
private doSetEnablement(extension: IExtension, enable: boolean, workspace: boolean): TPromise<boolean> {
if (workspace) {
return this.extensionEnablementService.setEnablement(extension.identifier, enable, workspace);
}
const globalElablement = this.extensionEnablementService.setEnablement(extension.identifier, enable, false);
if (enable && this.workspaceContextService.getWorkspace()) {
const workspaceEnablement = this.extensionEnablementService.setEnablement(extension.identifier, enable, true);
return TPromise.join([globalElablement, workspaceEnablement]).then(values => values[0] || values[1]);
}
return globalElablement;
}
private onInstallExtension(event: InstallExtensionEvent): void {
......
......@@ -748,6 +748,29 @@ suite('ExtensionsWorkbenchService Test', () => {
assert.ok(!actual.disabledGlobally);
});
test('test enable extension globally when extension is disabled for workspace', () => {
instantiationService.get(IExtensionEnablementService).setEnablement('pub.a', false, true);
instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [aLocalExtension('a')]);
testObject = instantiationService.createInstance(ExtensionsWorkbenchService);
testObject.setEnablement(testObject.local[0], true);
const actual = testObject.local[0];
assert.ok(!actual.disabledForWorkspace);
assert.ok(!actual.disabledGlobally);
});
test('test disable extension globally should not disable for workspace', () => {
instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [aLocalExtension('a')]);
testObject = instantiationService.createInstance(ExtensionsWorkbenchService);
testObject.setEnablement(testObject.local[0], false);
const actual = testObject.local[0];
assert.ok(!actual.disabledForWorkspace);
assert.ok(actual.disabledGlobally);
});
test('test disabled flags are not updated for system extensions', () => {
instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [aLocalExtension('a', {}, { type: LocalExtensionType.System })]);
testObject = instantiationService.createInstance(ExtensionsWorkbenchService);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册