Skip to content

Commit

Permalink
Fix #66735
Browse files Browse the repository at this point in the history
  • Loading branch information
sandy081 committed Jan 23, 2019
1 parent 02248a4 commit 946e3e2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import 'vs/css!./media/extensionActions';
import { localize } from 'vs/nls';
import { IAction, Action } from 'vs/base/common/actions';
import { Throttler } from 'vs/base/common/async';
import { ThrottledDelayer } from 'vs/base/common/async';
import * as DOM from 'vs/base/browser/dom';
import * as paths from 'vs/base/common/paths';
import { Event } from 'vs/base/common/event';
Expand Down Expand Up @@ -956,7 +956,8 @@ export class ReloadAction extends ExtensionAction {
private static readonly EnabledClass = 'extension-action reload';
private static readonly DisabledClass = `${ReloadAction.EnabledClass} disabled`;

private throttler: Throttler;
// Use delayer to wait for more updates
private throttler: ThrottledDelayer<void>;
private disposables: IDisposable[] = [];

constructor(
Expand All @@ -966,13 +967,13 @@ export class ReloadAction extends ExtensionAction {
@IExtensionEnablementService private readonly extensionEnablementService: IExtensionEnablementService
) {
super('extensions.reload', localize('reloadAction', "Reload"), ReloadAction.DisabledClass, false);
this.throttler = new Throttler();
this.throttler = new ThrottledDelayer(50);
this.extensionService.onDidChangeExtensions(this.update, this, this.disposables);
this.update();
}

update(): void {
this.throttler.queue(() => {
update(): Promise<void> {
return this.throttler.trigger(() => {
this.enabled = false;
this.tooltip = '';
if (!this.extension) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ suite('ExtensionsActions Test', () => {
});

test('Test EnableAction when there is no extension', () => {
const testObject: ExtensionsActions.EnableDropDownAction = instantiationService.createInstance(ExtensionsActions.EnableDropDownAction, []);
const testObject: ExtensionsActions.EnableDropDownAction = instantiationService.createInstance(ExtensionsActions.EnableDropDownAction);

assert.ok(!testObject.enabled);
});
Expand All @@ -709,7 +709,7 @@ suite('ExtensionsActions Test', () => {

return instantiationService.get(IExtensionsWorkbenchService).queryLocal()
.then(extensions => {
const testObject: ExtensionsActions.EnableDropDownAction = instantiationService.createInstance(ExtensionsActions.EnableDropDownAction, []);
const testObject: ExtensionsActions.EnableDropDownAction = instantiationService.createInstance(ExtensionsActions.EnableDropDownAction);
testObject.extension = extensions[0];
assert.ok(!testObject.enabled);
});
Expand All @@ -723,7 +723,7 @@ suite('ExtensionsActions Test', () => {

return instantiationService.get(IExtensionsWorkbenchService).queryLocal()
.then(extensions => {
const testObject: ExtensionsActions.EnableDropDownAction = instantiationService.createInstance(ExtensionsActions.EnableDropDownAction, []);
const testObject: ExtensionsActions.EnableDropDownAction = instantiationService.createInstance(ExtensionsActions.EnableDropDownAction);
testObject.extension = extensions[0];
assert.ok(testObject.enabled);
});
Expand All @@ -738,7 +738,7 @@ suite('ExtensionsActions Test', () => {

return instantiationService.get(IExtensionsWorkbenchService).queryLocal()
.then(extensions => {
const testObject: ExtensionsActions.EnableDropDownAction = instantiationService.createInstance(ExtensionsActions.EnableDropDownAction, []);
const testObject: ExtensionsActions.EnableDropDownAction = instantiationService.createInstance(ExtensionsActions.EnableDropDownAction);
testObject.extension = extensions[0];
assert.ok(testObject.enabled);
});
Expand All @@ -751,7 +751,7 @@ suite('ExtensionsActions Test', () => {

return instantiationService.get(IExtensionsWorkbenchService).queryGallery()
.then(page => {
const testObject: ExtensionsActions.EnableDropDownAction = instantiationService.createInstance(ExtensionsActions.EnableDropDownAction, []);
const testObject: ExtensionsActions.EnableDropDownAction = instantiationService.createInstance(ExtensionsActions.EnableDropDownAction);
testObject.extension = page.firstPage[0];
assert.ok(!testObject.enabled);
});
Expand All @@ -763,7 +763,7 @@ suite('ExtensionsActions Test', () => {

return instantiationService.get(IExtensionsWorkbenchService).queryGallery()
.then(page => {
const testObject: ExtensionsActions.EnableDropDownAction = instantiationService.createInstance(ExtensionsActions.EnableDropDownAction, []);
const testObject: ExtensionsActions.EnableDropDownAction = instantiationService.createInstance(ExtensionsActions.EnableDropDownAction);
testObject.extension = page.firstPage[0];
instantiationService.get(IExtensionsWorkbenchService).onChange(() => testObject.update());

Expand All @@ -778,7 +778,7 @@ suite('ExtensionsActions Test', () => {

return instantiationService.get(IExtensionsWorkbenchService).queryLocal()
.then(extensions => {
const testObject: ExtensionsActions.EnableDropDownAction = instantiationService.createInstance(ExtensionsActions.EnableDropDownAction, []);
const testObject: ExtensionsActions.EnableDropDownAction = instantiationService.createInstance(ExtensionsActions.EnableDropDownAction);
testObject.extension = extensions[0];
uninstallEvent.fire(local.identifier);
assert.ok(!testObject.enabled);
Expand Down Expand Up @@ -1214,6 +1214,7 @@ suite('ExtensionsActions Test', () => {
return workbenchService.queryLocal().then(extensions => {
testObject.extension = extensions[0];
return workbenchService.setEnablement(extensions[0], EnablementState.Disabled)
.then(() => testObject.update())
.then(() => {
assert.ok(testObject.enabled);
assert.equal('Please reload Visual Studio Code to complete the disabling of this extension.', testObject.tooltip);
Expand Down Expand Up @@ -1250,6 +1251,7 @@ suite('ExtensionsActions Test', () => {
.then(extensions => {
testObject.extension = extensions[0];
return workbenchService.setEnablement(extensions[0], EnablementState.Enabled)
.then(() => testObject.update())
.then(() => {
assert.ok(testObject.enabled);
assert.equal('Please reload Visual Studio Code to complete the enabling of this extension.', testObject.tooltip);
Expand Down Expand Up @@ -1294,6 +1296,7 @@ suite('ExtensionsActions Test', () => {
installEvent.fire({ identifier: gallery.identifier, gallery });
didInstallEvent.fire({ identifier: gallery.identifier, gallery, operation: InstallOperation.Install, local: aLocalExtension('a', gallery, gallery) });
return workbenchService.setEnablement(extensions[0], EnablementState.Enabled)
.then(() => testObject.update())
.then(() => {
assert.ok(testObject.enabled);
assert.equal('Please reload Visual Studio Code to complete the enabling of this extension.', testObject.tooltip);
Expand Down

0 comments on commit 946e3e2

Please sign in to comment.