Skip to content

Commit 228fe8a

Browse files
committed
Replaceing uses of IDisposableWith DisposableStore
microsoft#74250
1 parent ae2cc87 commit 228fe8a

7 files changed

Lines changed: 39 additions & 41 deletions

File tree

src/vs/editor/contrib/links/links.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import * as async from 'vs/base/common/async';
99
import { CancellationToken } from 'vs/base/common/cancellation';
1010
import { onUnexpectedError } from 'vs/base/common/errors';
1111
import { MarkdownString } from 'vs/base/common/htmlContent';
12-
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
12+
import { DisposableStore } from 'vs/base/common/lifecycle';
1313
import * as platform from 'vs/base/common/platform';
1414
import { ICodeEditor, MouseTargetType } from 'vs/editor/browser/editorBrowser';
1515
import { EditorAction, ServicesAccessor, registerEditorAction, registerEditorContribution } from 'vs/editor/browser/editorExtensions';
@@ -172,7 +172,7 @@ class LinkDetector implements editorCommon.IEditorContribution {
172172

173173
private readonly editor: ICodeEditor;
174174
private enabled: boolean;
175-
private listenersToRemove: IDisposable[];
175+
private readonly listenersToRemove = new DisposableStore();
176176
private readonly timeout: async.TimeoutTimer;
177177
private computePromise: async.CancelablePromise<LinksList> | null;
178178
private activeLinksList: LinksList | null;
@@ -189,22 +189,21 @@ class LinkDetector implements editorCommon.IEditorContribution {
189189
this.editor = editor;
190190
this.openerService = openerService;
191191
this.notificationService = notificationService;
192-
this.listenersToRemove = [];
193192

194193
let clickLinkGesture = new ClickLinkGesture(editor);
195-
this.listenersToRemove.push(clickLinkGesture);
196-
this.listenersToRemove.push(clickLinkGesture.onMouseMoveOrRelevantKeyDown(([mouseEvent, keyboardEvent]) => {
194+
this.listenersToRemove.add(clickLinkGesture);
195+
this.listenersToRemove.add(clickLinkGesture.onMouseMoveOrRelevantKeyDown(([mouseEvent, keyboardEvent]) => {
197196
this._onEditorMouseMove(mouseEvent, keyboardEvent);
198197
}));
199-
this.listenersToRemove.push(clickLinkGesture.onExecute((e) => {
198+
this.listenersToRemove.add(clickLinkGesture.onExecute((e) => {
200199
this.onEditorMouseUp(e);
201200
}));
202-
this.listenersToRemove.push(clickLinkGesture.onCancel((e) => {
201+
this.listenersToRemove.add(clickLinkGesture.onCancel((e) => {
203202
this.cleanUpActiveLinkDecoration();
204203
}));
205204

206205
this.enabled = editor.getConfiguration().contribInfo.links;
207-
this.listenersToRemove.push(editor.onDidChangeConfiguration((e) => {
206+
this.listenersToRemove.add(editor.onDidChangeConfiguration((e) => {
208207
let enabled = editor.getConfiguration().contribInfo.links;
209208
if (this.enabled === enabled) {
210209
// No change in our configuration option
@@ -221,10 +220,10 @@ class LinkDetector implements editorCommon.IEditorContribution {
221220
// Start computing (for the getting enabled case)
222221
this.beginCompute();
223222
}));
224-
this.listenersToRemove.push(editor.onDidChangeModelContent((e) => this.onChange()));
225-
this.listenersToRemove.push(editor.onDidChangeModel((e) => this.onModelChanged()));
226-
this.listenersToRemove.push(editor.onDidChangeModelLanguage((e) => this.onModelModeChanged()));
227-
this.listenersToRemove.push(LinkProviderRegistry.onDidChange((e) => this.onModelModeChanged()));
223+
this.listenersToRemove.add(editor.onDidChangeModelContent((e) => this.onChange()));
224+
this.listenersToRemove.add(editor.onDidChangeModel((e) => this.onModelChanged()));
225+
this.listenersToRemove.add(editor.onDidChangeModelLanguage((e) => this.onModelModeChanged()));
226+
this.listenersToRemove.add(LinkProviderRegistry.onDidChange((e) => this.onModelModeChanged()));
228227

229228
this.timeout = new async.TimeoutTimer();
230229
this.computePromise = null;
@@ -414,7 +413,7 @@ class LinkDetector implements editorCommon.IEditorContribution {
414413
}
415414

416415
public dispose(): void {
417-
this.listenersToRemove = dispose(this.listenersToRemove);
416+
this.listenersToRemove.dispose();
418417
this.stop();
419418
this.timeout.dispose();
420419
}

src/vs/editor/contrib/wordHighlighter/wordHighlighter.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { CancelablePromise, createCancelablePromise, first, timeout } from 'vs/b
99
import { CancellationToken } from 'vs/base/common/cancellation';
1010
import { onUnexpectedError, onUnexpectedExternalError } from 'vs/base/common/errors';
1111
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
12-
import { Disposable, IDisposable, dispose } from 'vs/base/common/lifecycle';
12+
import { Disposable, DisposableStore } from 'vs/base/common/lifecycle';
1313
import { IActiveCodeEditor, ICodeEditor } from 'vs/editor/browser/editorBrowser';
1414
import { EditorAction, IActionOptions, registerDefaultLanguageCommand, registerEditorAction, registerEditorContribution } from 'vs/editor/browser/editorExtensions';
1515
import { CursorChangeReason, ICursorPositionChangedEvent } from 'vs/editor/common/controller/cursorEvents';
@@ -164,7 +164,7 @@ class WordHighlighter {
164164
private occurrencesHighlight: boolean;
165165
private readonly model: ITextModel;
166166
private _decorationIds: string[];
167-
private toUnhook: IDisposable[];
167+
private readonly toUnhook = new DisposableStore();
168168

169169
private workerRequestTokenId: number = 0;
170170
private workerRequest: IOccurenceAtPositionRequest | null;
@@ -183,8 +183,7 @@ class WordHighlighter {
183183
this._ignorePositionChangeEvent = false;
184184
this.occurrencesHighlight = this.editor.getConfiguration().contribInfo.occurrencesHighlight;
185185
this.model = this.editor.getModel();
186-
this.toUnhook = [];
187-
this.toUnhook.push(editor.onDidChangeCursorPosition((e: ICursorPositionChangedEvent) => {
186+
this.toUnhook.add(editor.onDidChangeCursorPosition((e: ICursorPositionChangedEvent) => {
188187

189188
if (this._ignorePositionChangeEvent) {
190189
// We are changing the position => ignore this event
@@ -199,10 +198,10 @@ class WordHighlighter {
199198

200199
this._onPositionChanged(e);
201200
}));
202-
this.toUnhook.push(editor.onDidChangeModelContent((e) => {
201+
this.toUnhook.add(editor.onDidChangeModelContent((e) => {
203202
this._stopAll();
204203
}));
205-
this.toUnhook.push(editor.onDidChangeConfiguration((e) => {
204+
this.toUnhook.add(editor.onDidChangeConfiguration((e) => {
206205
let newValue = this.editor.getConfiguration().contribInfo.occurrencesHighlight;
207206
if (this.occurrencesHighlight !== newValue) {
208207
this.occurrencesHighlight = newValue;
@@ -454,7 +453,7 @@ class WordHighlighter {
454453

455454
public dispose(): void {
456455
this._stopAll();
457-
this.toUnhook = dispose(this.toUnhook);
456+
this.toUnhook.dispose();
458457
}
459458
}
460459

src/vs/platform/actions/browser/menuEntryActionViewItem.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { ActionViewItem, Separator } from 'vs/base/browser/ui/actionbar/actionba
99
import { IAction } from 'vs/base/common/actions';
1010
import { Emitter } from 'vs/base/common/event';
1111
import { IdGenerator } from 'vs/base/common/idGenerator';
12-
import { dispose, IDisposable, toDisposable, MutableDisposable, DisposableStore } from 'vs/base/common/lifecycle';
12+
import { IDisposable, toDisposable, MutableDisposable, DisposableStore } from 'vs/base/common/lifecycle';
1313
import { isLinux, isWindows } from 'vs/base/common/platform';
1414
import { localize } from 'vs/nls';
1515
import { ICommandAction, IMenu, IMenuActionOptions, MenuItemAction, SubmenuItemAction } from 'vs/platform/actions/common/actions';
@@ -20,18 +20,18 @@ import { INotificationService } from 'vs/platform/notification/common/notificati
2020
// The alternative key on all platforms is alt. On windows we also support shift as an alternative key #44136
2121
class AlternativeKeyEmitter extends Emitter<boolean> {
2222

23-
private _subscriptions: IDisposable[] = [];
23+
private readonly _subscriptions = new DisposableStore();
2424
private _isPressed: boolean;
2525
private static instance: AlternativeKeyEmitter;
2626
private _suppressAltKeyUp: boolean = false;
2727

2828
private constructor(contextMenuService: IContextMenuService) {
2929
super();
3030

31-
this._subscriptions.push(domEvent(document.body, 'keydown')(e => {
31+
this._subscriptions.add(domEvent(document.body, 'keydown')(e => {
3232
this.isPressed = e.altKey || ((isWindows || isLinux) && e.shiftKey);
3333
}));
34-
this._subscriptions.push(domEvent(document.body, 'keyup')(e => {
34+
this._subscriptions.add(domEvent(document.body, 'keyup')(e => {
3535
if (this.isPressed) {
3636
if (this._suppressAltKeyUp) {
3737
e.preventDefault();
@@ -41,10 +41,10 @@ class AlternativeKeyEmitter extends Emitter<boolean> {
4141
this._suppressAltKeyUp = false;
4242
this.isPressed = false;
4343
}));
44-
this._subscriptions.push(domEvent(document.body, 'mouseleave')(e => this.isPressed = false));
45-
this._subscriptions.push(domEvent(document.body, 'blur')(e => this.isPressed = false));
44+
this._subscriptions.add(domEvent(document.body, 'mouseleave')(e => this.isPressed = false));
45+
this._subscriptions.add(domEvent(document.body, 'blur')(e => this.isPressed = false));
4646
// Workaround since we do not get any events while a context menu is shown
47-
this._subscriptions.push(contextMenuService.onDidContextMenu(() => this.isPressed = false));
47+
this._subscriptions.add(contextMenuService.onDidContextMenu(() => this.isPressed = false));
4848
}
4949

5050
get isPressed(): boolean {
@@ -72,7 +72,7 @@ class AlternativeKeyEmitter extends Emitter<boolean> {
7272

7373
dispose() {
7474
super.dispose();
75-
this._subscriptions = dispose(this._subscriptions);
75+
this._subscriptions.dispose();
7676
}
7777
}
7878

src/vs/platform/contextkey/browser/contextKeyService.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { Emitter, Event, PauseableEmitter } from 'vs/base/common/event';
7-
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
7+
import { IDisposable, DisposableStore } from 'vs/base/common/lifecycle';
88
import { keys } from 'vs/base/common/map';
99
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
1010
import { ConfigurationTarget, IConfigurationService } from 'vs/platform/configuration/common/configuration';
@@ -323,7 +323,7 @@ export class ContextKeyService extends AbstractContextKeyService implements ICon
323323
private _lastContextId: number;
324324
private readonly _contexts = new Map<number, Context>();
325325

326-
private _toDispose: IDisposable[] = [];
326+
private readonly _toDispose = new DisposableStore();
327327

328328
constructor(@IConfigurationService configurationService: IConfigurationService) {
329329
super(0);
@@ -332,7 +332,7 @@ export class ContextKeyService extends AbstractContextKeyService implements ICon
332332

333333
const myContext = new ConfigAwareContextValuesContainer(this._myContextId, configurationService, this._onDidChangeContext);
334334
this._contexts.set(this._myContextId, myContext);
335-
this._toDispose.push(myContext);
335+
this._toDispose.add(myContext);
336336

337337
// Uncomment this to see the contexts continuously logged
338338
// let lastLoggedValue: string | null = null;
@@ -348,7 +348,7 @@ export class ContextKeyService extends AbstractContextKeyService implements ICon
348348

349349
public dispose(): void {
350350
this._isDisposed = true;
351-
this._toDispose = dispose(this._toDispose);
351+
this._toDispose.dispose();
352352
}
353353

354354
public getContextValuesContainer(contextId: number): Context {

src/vs/platform/contextview/browser/contextMenuHandler.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import 'vs/css!./contextMenuHandler';
77

8-
import { IDisposable, combinedDisposable } from 'vs/base/common/lifecycle';
8+
import { combinedDisposable, DisposableStore } from 'vs/base/common/lifecycle';
99
import { ActionRunner, IRunEvent, WBActionExecutedEvent, WBActionExecutedClassification } from 'vs/base/common/actions';
1010
import { Menu } from 'vs/base/browser/ui/menu/menu';
1111
import { IContextViewService } from 'vs/platform/contextview/browser/contextView';
@@ -67,7 +67,7 @@ export class ContextMenuHandler {
6767
this.block = container.appendChild($('.context-view-block'));
6868
}
6969

70-
const menuDisposables: IDisposable[] = [];
70+
const menuDisposables = new DisposableStore();
7171

7272
const actionRunner = delegate.actionRunner || new ActionRunner();
7373
actionRunner.onDidBeforeRun(this.onActionRun, this, menuDisposables);
@@ -79,7 +79,7 @@ export class ContextMenuHandler {
7979
getKeyBinding: delegate.getKeyBinding ? delegate.getKeyBinding : action => this.keybindingService.lookupKeybinding(action.id)
8080
});
8181

82-
menuDisposables.push(attachMenuStyler(menu, this.themeService));
82+
menuDisposables.add(attachMenuStyler(menu, this.themeService));
8383

8484
menu.onDidCancel(() => this.contextViewService.hideContextView(true), null, menuDisposables);
8585
menu.onDidBlur(() => this.contextViewService.hideContextView(true), null, menuDisposables);
@@ -104,7 +104,7 @@ export class ContextMenuHandler {
104104
this.contextViewService.hideContextView(true);
105105
}, null, menuDisposables);
106106

107-
return combinedDisposable(...menuDisposables, menu);
107+
return combinedDisposable(menuDisposables, menu);
108108
},
109109

110110
focus: () => {

src/vs/platform/telemetry/browser/errorTelemetry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default class ErrorTelemetry extends BaseErrorTelemetry {
2020
oldOnError.apply(this, arguments);
2121
}
2222
};
23-
this._disposables.push(toDisposable(function () {
23+
this._disposables.add(toDisposable(() => {
2424
if (oldOnError) {
2525
globals.onerror = oldOnError;
2626
}

src/vs/platform/telemetry/common/errorTelemetry.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import { binarySearch } from 'vs/base/common/arrays';
77
import * as Errors from 'vs/base/common/errors';
8-
import { dispose, IDisposable, toDisposable } from 'vs/base/common/lifecycle';
8+
import { toDisposable, DisposableStore } from 'vs/base/common/lifecycle';
99
import { safeStringify } from 'vs/base/common/objects';
1010
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
1111

@@ -49,15 +49,15 @@ export default abstract class BaseErrorTelemetry {
4949
private _flushDelay: number;
5050
private _flushHandle: any = -1;
5151
private _buffer: ErrorEvent[] = [];
52-
protected _disposables: IDisposable[] = [];
52+
protected readonly _disposables = new DisposableStore();
5353

5454
constructor(telemetryService: ITelemetryService, flushDelay = BaseErrorTelemetry.ERROR_FLUSH_TIMEOUT) {
5555
this._telemetryService = telemetryService;
5656
this._flushDelay = flushDelay;
5757

5858
// (1) check for unexpected but handled errors
5959
const unbind = Errors.errorHandler.addListener((err) => this._onErrorEvent(err));
60-
this._disposables.push(toDisposable(unbind));
60+
this._disposables.add(toDisposable(unbind));
6161

6262
// (2) install implementation-specific error listeners
6363
this.installErrorListeners();
@@ -66,7 +66,7 @@ export default abstract class BaseErrorTelemetry {
6666
dispose() {
6767
clearTimeout(this._flushHandle);
6868
this._flushBuffer();
69-
this._disposables = dispose(this._disposables);
69+
this._disposables.dispose();
7070
}
7171

7272
protected installErrorListeners(): void {

0 commit comments

Comments
 (0)