diff --git a/src/vs/editor/contrib/links/links.ts b/src/vs/editor/contrib/links/links.ts index 056e2cb5b35..de26df3e3d4 100644 --- a/src/vs/editor/contrib/links/links.ts +++ b/src/vs/editor/contrib/links/links.ts @@ -9,7 +9,7 @@ import * as async from 'vs/base/common/async'; import { CancellationToken } from 'vs/base/common/cancellation'; import { onUnexpectedError } from 'vs/base/common/errors'; import { MarkdownString } from 'vs/base/common/htmlContent'; -import { IDisposable, dispose } from 'vs/base/common/lifecycle'; +import { DisposableStore } from 'vs/base/common/lifecycle'; import * as platform from 'vs/base/common/platform'; import { ICodeEditor, MouseTargetType } from 'vs/editor/browser/editorBrowser'; import { EditorAction, ServicesAccessor, registerEditorAction, registerEditorContribution } from 'vs/editor/browser/editorExtensions'; @@ -172,7 +172,7 @@ class LinkDetector implements editorCommon.IEditorContribution { private readonly editor: ICodeEditor; private enabled: boolean; - private listenersToRemove: IDisposable[]; + private readonly listenersToRemove = new DisposableStore(); private readonly timeout: async.TimeoutTimer; private computePromise: async.CancelablePromise | null; private activeLinksList: LinksList | null; @@ -189,22 +189,21 @@ class LinkDetector implements editorCommon.IEditorContribution { this.editor = editor; this.openerService = openerService; this.notificationService = notificationService; - this.listenersToRemove = []; let clickLinkGesture = new ClickLinkGesture(editor); - this.listenersToRemove.push(clickLinkGesture); - this.listenersToRemove.push(clickLinkGesture.onMouseMoveOrRelevantKeyDown(([mouseEvent, keyboardEvent]) => { + this.listenersToRemove.add(clickLinkGesture); + this.listenersToRemove.add(clickLinkGesture.onMouseMoveOrRelevantKeyDown(([mouseEvent, keyboardEvent]) => { this._onEditorMouseMove(mouseEvent, keyboardEvent); })); - this.listenersToRemove.push(clickLinkGesture.onExecute((e) => { + this.listenersToRemove.add(clickLinkGesture.onExecute((e) => { this.onEditorMouseUp(e); })); - this.listenersToRemove.push(clickLinkGesture.onCancel((e) => { + this.listenersToRemove.add(clickLinkGesture.onCancel((e) => { this.cleanUpActiveLinkDecoration(); })); this.enabled = editor.getConfiguration().contribInfo.links; - this.listenersToRemove.push(editor.onDidChangeConfiguration((e) => { + this.listenersToRemove.add(editor.onDidChangeConfiguration((e) => { let enabled = editor.getConfiguration().contribInfo.links; if (this.enabled === enabled) { // No change in our configuration option @@ -221,10 +220,10 @@ class LinkDetector implements editorCommon.IEditorContribution { // Start computing (for the getting enabled case) this.beginCompute(); })); - this.listenersToRemove.push(editor.onDidChangeModelContent((e) => this.onChange())); - this.listenersToRemove.push(editor.onDidChangeModel((e) => this.onModelChanged())); - this.listenersToRemove.push(editor.onDidChangeModelLanguage((e) => this.onModelModeChanged())); - this.listenersToRemove.push(LinkProviderRegistry.onDidChange((e) => this.onModelModeChanged())); + this.listenersToRemove.add(editor.onDidChangeModelContent((e) => this.onChange())); + this.listenersToRemove.add(editor.onDidChangeModel((e) => this.onModelChanged())); + this.listenersToRemove.add(editor.onDidChangeModelLanguage((e) => this.onModelModeChanged())); + this.listenersToRemove.add(LinkProviderRegistry.onDidChange((e) => this.onModelModeChanged())); this.timeout = new async.TimeoutTimer(); this.computePromise = null; @@ -414,7 +413,7 @@ class LinkDetector implements editorCommon.IEditorContribution { } public dispose(): void { - this.listenersToRemove = dispose(this.listenersToRemove); + this.listenersToRemove.dispose(); this.stop(); this.timeout.dispose(); } diff --git a/src/vs/editor/contrib/wordHighlighter/wordHighlighter.ts b/src/vs/editor/contrib/wordHighlighter/wordHighlighter.ts index 6b918096810..0820b22ce51 100644 --- a/src/vs/editor/contrib/wordHighlighter/wordHighlighter.ts +++ b/src/vs/editor/contrib/wordHighlighter/wordHighlighter.ts @@ -9,7 +9,7 @@ import { CancelablePromise, createCancelablePromise, first, timeout } from 'vs/b import { CancellationToken } from 'vs/base/common/cancellation'; import { onUnexpectedError, onUnexpectedExternalError } from 'vs/base/common/errors'; import { KeyCode, KeyMod } from 'vs/base/common/keyCodes'; -import { Disposable, IDisposable, dispose } from 'vs/base/common/lifecycle'; +import { Disposable, DisposableStore } from 'vs/base/common/lifecycle'; import { IActiveCodeEditor, ICodeEditor } from 'vs/editor/browser/editorBrowser'; import { EditorAction, IActionOptions, registerDefaultLanguageCommand, registerEditorAction, registerEditorContribution } from 'vs/editor/browser/editorExtensions'; import { CursorChangeReason, ICursorPositionChangedEvent } from 'vs/editor/common/controller/cursorEvents'; @@ -164,7 +164,7 @@ class WordHighlighter { private occurrencesHighlight: boolean; private readonly model: ITextModel; private _decorationIds: string[]; - private toUnhook: IDisposable[]; + private readonly toUnhook = new DisposableStore(); private workerRequestTokenId: number = 0; private workerRequest: IOccurenceAtPositionRequest | null; @@ -183,8 +183,7 @@ class WordHighlighter { this._ignorePositionChangeEvent = false; this.occurrencesHighlight = this.editor.getConfiguration().contribInfo.occurrencesHighlight; this.model = this.editor.getModel(); - this.toUnhook = []; - this.toUnhook.push(editor.onDidChangeCursorPosition((e: ICursorPositionChangedEvent) => { + this.toUnhook.add(editor.onDidChangeCursorPosition((e: ICursorPositionChangedEvent) => { if (this._ignorePositionChangeEvent) { // We are changing the position => ignore this event @@ -199,10 +198,10 @@ class WordHighlighter { this._onPositionChanged(e); })); - this.toUnhook.push(editor.onDidChangeModelContent((e) => { + this.toUnhook.add(editor.onDidChangeModelContent((e) => { this._stopAll(); })); - this.toUnhook.push(editor.onDidChangeConfiguration((e) => { + this.toUnhook.add(editor.onDidChangeConfiguration((e) => { let newValue = this.editor.getConfiguration().contribInfo.occurrencesHighlight; if (this.occurrencesHighlight !== newValue) { this.occurrencesHighlight = newValue; @@ -454,7 +453,7 @@ class WordHighlighter { public dispose(): void { this._stopAll(); - this.toUnhook = dispose(this.toUnhook); + this.toUnhook.dispose(); } } diff --git a/src/vs/platform/actions/browser/menuEntryActionViewItem.ts b/src/vs/platform/actions/browser/menuEntryActionViewItem.ts index 4d73996185d..2ec3d2e5d78 100644 --- a/src/vs/platform/actions/browser/menuEntryActionViewItem.ts +++ b/src/vs/platform/actions/browser/menuEntryActionViewItem.ts @@ -9,7 +9,7 @@ import { ActionViewItem, Separator } from 'vs/base/browser/ui/actionbar/actionba import { IAction } from 'vs/base/common/actions'; import { Emitter } from 'vs/base/common/event'; import { IdGenerator } from 'vs/base/common/idGenerator'; -import { dispose, IDisposable, toDisposable, MutableDisposable, DisposableStore } from 'vs/base/common/lifecycle'; +import { IDisposable, toDisposable, MutableDisposable, DisposableStore } from 'vs/base/common/lifecycle'; import { isLinux, isWindows } from 'vs/base/common/platform'; import { localize } from 'vs/nls'; import { ICommandAction, IMenu, IMenuActionOptions, MenuItemAction, SubmenuItemAction } from 'vs/platform/actions/common/actions'; @@ -20,7 +20,7 @@ import { INotificationService } from 'vs/platform/notification/common/notificati // The alternative key on all platforms is alt. On windows we also support shift as an alternative key #44136 class AlternativeKeyEmitter extends Emitter { - private _subscriptions: IDisposable[] = []; + private readonly _subscriptions = new DisposableStore(); private _isPressed: boolean; private static instance: AlternativeKeyEmitter; private _suppressAltKeyUp: boolean = false; @@ -28,10 +28,10 @@ class AlternativeKeyEmitter extends Emitter { private constructor(contextMenuService: IContextMenuService) { super(); - this._subscriptions.push(domEvent(document.body, 'keydown')(e => { + this._subscriptions.add(domEvent(document.body, 'keydown')(e => { this.isPressed = e.altKey || ((isWindows || isLinux) && e.shiftKey); })); - this._subscriptions.push(domEvent(document.body, 'keyup')(e => { + this._subscriptions.add(domEvent(document.body, 'keyup')(e => { if (this.isPressed) { if (this._suppressAltKeyUp) { e.preventDefault(); @@ -41,10 +41,10 @@ class AlternativeKeyEmitter extends Emitter { this._suppressAltKeyUp = false; this.isPressed = false; })); - this._subscriptions.push(domEvent(document.body, 'mouseleave')(e => this.isPressed = false)); - this._subscriptions.push(domEvent(document.body, 'blur')(e => this.isPressed = false)); + this._subscriptions.add(domEvent(document.body, 'mouseleave')(e => this.isPressed = false)); + this._subscriptions.add(domEvent(document.body, 'blur')(e => this.isPressed = false)); // Workaround since we do not get any events while a context menu is shown - this._subscriptions.push(contextMenuService.onDidContextMenu(() => this.isPressed = false)); + this._subscriptions.add(contextMenuService.onDidContextMenu(() => this.isPressed = false)); } get isPressed(): boolean { @@ -72,7 +72,7 @@ class AlternativeKeyEmitter extends Emitter { dispose() { super.dispose(); - this._subscriptions = dispose(this._subscriptions); + this._subscriptions.dispose(); } } diff --git a/src/vs/platform/contextkey/browser/contextKeyService.ts b/src/vs/platform/contextkey/browser/contextKeyService.ts index bd7008325ee..7b23bc6e6f5 100644 --- a/src/vs/platform/contextkey/browser/contextKeyService.ts +++ b/src/vs/platform/contextkey/browser/contextKeyService.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import { Emitter, Event, PauseableEmitter } from 'vs/base/common/event'; -import { IDisposable, dispose } from 'vs/base/common/lifecycle'; +import { IDisposable, DisposableStore } from 'vs/base/common/lifecycle'; import { keys } from 'vs/base/common/map'; import { CommandsRegistry } from 'vs/platform/commands/common/commands'; import { ConfigurationTarget, IConfigurationService } from 'vs/platform/configuration/common/configuration'; @@ -323,7 +323,7 @@ export class ContextKeyService extends AbstractContextKeyService implements ICon private _lastContextId: number; private readonly _contexts = new Map(); - private _toDispose: IDisposable[] = []; + private readonly _toDispose = new DisposableStore(); constructor(@IConfigurationService configurationService: IConfigurationService) { super(0); @@ -332,7 +332,7 @@ export class ContextKeyService extends AbstractContextKeyService implements ICon const myContext = new ConfigAwareContextValuesContainer(this._myContextId, configurationService, this._onDidChangeContext); this._contexts.set(this._myContextId, myContext); - this._toDispose.push(myContext); + this._toDispose.add(myContext); // Uncomment this to see the contexts continuously logged // let lastLoggedValue: string | null = null; @@ -348,7 +348,7 @@ export class ContextKeyService extends AbstractContextKeyService implements ICon public dispose(): void { this._isDisposed = true; - this._toDispose = dispose(this._toDispose); + this._toDispose.dispose(); } public getContextValuesContainer(contextId: number): Context { diff --git a/src/vs/platform/contextview/browser/contextMenuHandler.ts b/src/vs/platform/contextview/browser/contextMenuHandler.ts index e5e32109271..8bcf74d2b6e 100644 --- a/src/vs/platform/contextview/browser/contextMenuHandler.ts +++ b/src/vs/platform/contextview/browser/contextMenuHandler.ts @@ -5,7 +5,7 @@ import 'vs/css!./contextMenuHandler'; -import { IDisposable, combinedDisposable } from 'vs/base/common/lifecycle'; +import { combinedDisposable, DisposableStore } from 'vs/base/common/lifecycle'; import { ActionRunner, IRunEvent, WBActionExecutedEvent, WBActionExecutedClassification } from 'vs/base/common/actions'; import { Menu } from 'vs/base/browser/ui/menu/menu'; import { IContextViewService } from 'vs/platform/contextview/browser/contextView'; @@ -67,7 +67,7 @@ export class ContextMenuHandler { this.block = container.appendChild($('.context-view-block')); } - const menuDisposables: IDisposable[] = []; + const menuDisposables = new DisposableStore(); const actionRunner = delegate.actionRunner || new ActionRunner(); actionRunner.onDidBeforeRun(this.onActionRun, this, menuDisposables); @@ -79,7 +79,7 @@ export class ContextMenuHandler { getKeyBinding: delegate.getKeyBinding ? delegate.getKeyBinding : action => this.keybindingService.lookupKeybinding(action.id) }); - menuDisposables.push(attachMenuStyler(menu, this.themeService)); + menuDisposables.add(attachMenuStyler(menu, this.themeService)); menu.onDidCancel(() => this.contextViewService.hideContextView(true), null, menuDisposables); menu.onDidBlur(() => this.contextViewService.hideContextView(true), null, menuDisposables); @@ -104,7 +104,7 @@ export class ContextMenuHandler { this.contextViewService.hideContextView(true); }, null, menuDisposables); - return combinedDisposable(...menuDisposables, menu); + return combinedDisposable(menuDisposables, menu); }, focus: () => { diff --git a/src/vs/platform/telemetry/browser/errorTelemetry.ts b/src/vs/platform/telemetry/browser/errorTelemetry.ts index 26380fa6ef0..6ecc99a211c 100644 --- a/src/vs/platform/telemetry/browser/errorTelemetry.ts +++ b/src/vs/platform/telemetry/browser/errorTelemetry.ts @@ -20,7 +20,7 @@ export default class ErrorTelemetry extends BaseErrorTelemetry { oldOnError.apply(this, arguments); } }; - this._disposables.push(toDisposable(function () { + this._disposables.add(toDisposable(() => { if (oldOnError) { globals.onerror = oldOnError; } diff --git a/src/vs/platform/telemetry/common/errorTelemetry.ts b/src/vs/platform/telemetry/common/errorTelemetry.ts index 4145ed158c9..d58610ecc67 100644 --- a/src/vs/platform/telemetry/common/errorTelemetry.ts +++ b/src/vs/platform/telemetry/common/errorTelemetry.ts @@ -5,7 +5,7 @@ import { binarySearch } from 'vs/base/common/arrays'; import * as Errors from 'vs/base/common/errors'; -import { dispose, IDisposable, toDisposable } from 'vs/base/common/lifecycle'; +import { toDisposable, DisposableStore } from 'vs/base/common/lifecycle'; import { safeStringify } from 'vs/base/common/objects'; import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; @@ -49,7 +49,7 @@ export default abstract class BaseErrorTelemetry { private _flushDelay: number; private _flushHandle: any = -1; private _buffer: ErrorEvent[] = []; - protected _disposables: IDisposable[] = []; + protected readonly _disposables = new DisposableStore(); constructor(telemetryService: ITelemetryService, flushDelay = BaseErrorTelemetry.ERROR_FLUSH_TIMEOUT) { this._telemetryService = telemetryService; @@ -57,7 +57,7 @@ export default abstract class BaseErrorTelemetry { // (1) check for unexpected but handled errors const unbind = Errors.errorHandler.addListener((err) => this._onErrorEvent(err)); - this._disposables.push(toDisposable(unbind)); + this._disposables.add(toDisposable(unbind)); // (2) install implementation-specific error listeners this.installErrorListeners(); @@ -66,7 +66,7 @@ export default abstract class BaseErrorTelemetry { dispose() { clearTimeout(this._flushHandle); this._flushBuffer(); - this._disposables = dispose(this._disposables); + this._disposables.dispose(); } protected installErrorListeners(): void {