Skip to content

Commit 1ef4a75

Browse files
committed
Replace IDisposable with DisposableStore in a few more simple cases
1 parent b61980c commit 1ef4a75

5 files changed

Lines changed: 27 additions & 31 deletions

File tree

src/vs/editor/contrib/find/findModel.ts

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

66
import { RunOnceScheduler, TimeoutTimer } from 'vs/base/common/async';
77
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
8-
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
8+
import { dispose, DisposableStore } from 'vs/base/common/lifecycle';
99
import { IActiveCodeEditor } from 'vs/editor/browser/editorBrowser';
1010
import { ReplaceCommand, ReplaceCommandThatPreservesSelection } from 'vs/editor/common/commands/replaceCommand';
1111
import { CursorChangeReason, ICursorPositionChangedEvent } from 'vs/editor/common/controller/cursorEvents';
@@ -71,7 +71,7 @@ export class FindModelBoundToEditorModel {
7171

7272
private readonly _editor: IActiveCodeEditor;
7373
private readonly _state: FindReplaceState;
74-
private _toDispose: IDisposable[];
74+
private readonly _toDispose = new DisposableStore();
7575
private readonly _decorations: FindDecorations;
7676
private _ignoreModelContentChanged: boolean;
7777
private readonly _startSearchingTimer: TimeoutTimer;
@@ -82,17 +82,16 @@ export class FindModelBoundToEditorModel {
8282
constructor(editor: IActiveCodeEditor, state: FindReplaceState) {
8383
this._editor = editor;
8484
this._state = state;
85-
this._toDispose = [];
8685
this._isDisposed = false;
8786
this._startSearchingTimer = new TimeoutTimer();
8887

8988
this._decorations = new FindDecorations(editor);
90-
this._toDispose.push(this._decorations);
89+
this._toDispose.add(this._decorations);
9190

9291
this._updateDecorationsScheduler = new RunOnceScheduler(() => this.research(false), 100);
93-
this._toDispose.push(this._updateDecorationsScheduler);
92+
this._toDispose.add(this._updateDecorationsScheduler);
9493

95-
this._toDispose.push(this._editor.onDidChangeCursorPosition((e: ICursorPositionChangedEvent) => {
94+
this._toDispose.add(this._editor.onDidChangeCursorPosition((e: ICursorPositionChangedEvent) => {
9695
if (
9796
e.reason === CursorChangeReason.Explicit
9897
|| e.reason === CursorChangeReason.Undo
@@ -103,7 +102,7 @@ export class FindModelBoundToEditorModel {
103102
}));
104103

105104
this._ignoreModelContentChanged = false;
106-
this._toDispose.push(this._editor.onDidChangeModelContent((e) => {
105+
this._toDispose.add(this._editor.onDidChangeModelContent((e) => {
107106
if (this._ignoreModelContentChanged) {
108107
return;
109108
}
@@ -115,15 +114,15 @@ export class FindModelBoundToEditorModel {
115114
this._updateDecorationsScheduler.schedule();
116115
}));
117116

118-
this._toDispose.push(this._state.onFindReplaceStateChange((e) => this._onStateChanged(e)));
117+
this._toDispose.add(this._state.onFindReplaceStateChange((e) => this._onStateChanged(e)));
119118

120119
this.research(false, this._state.searchScope);
121120
}
122121

123122
public dispose(): void {
124123
this._isDisposed = true;
125124
dispose(this._startSearchingTimer);
126-
this._toDispose = dispose(this._toDispose);
125+
this._toDispose.dispose();
127126
}
128127

129128
private _onStateChanged(e: FindReplaceStateChangedEvent): void {

src/vs/editor/contrib/gotoError/gotoError.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import * as nls from 'vs/nls';
77
import { Emitter } from 'vs/base/common/event';
88
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
9-
import { IDisposable, dispose, DisposableStore } from 'vs/base/common/lifecycle';
9+
import { DisposableStore } from 'vs/base/common/lifecycle';
1010
import { URI } from 'vs/base/common/uri';
1111
import { RawContextKey, IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
1212
import { IMarker, IMarkerService, MarkerSeverity } from 'vs/platform/markers/common/markers';
@@ -32,7 +32,7 @@ class MarkerModel {
3232
private readonly _editor: ICodeEditor;
3333
private _markers: IMarker[];
3434
private _nextIdx: number;
35-
private _toUnbind: IDisposable[];
35+
private readonly _toUnbind = new DisposableStore();
3636
private _ignoreSelectionChange: boolean;
3737
private readonly _onCurrentMarkerChanged: Emitter<IMarker | undefined>;
3838
private readonly _onMarkerSetChanged: Emitter<MarkerModel>;
@@ -41,15 +41,14 @@ class MarkerModel {
4141
this._editor = editor;
4242
this._markers = [];
4343
this._nextIdx = -1;
44-
this._toUnbind = [];
4544
this._ignoreSelectionChange = false;
4645
this._onCurrentMarkerChanged = new Emitter<IMarker>();
4746
this._onMarkerSetChanged = new Emitter<MarkerModel>();
4847
this.setMarkers(markers);
4948

5049
// listen on editor
51-
this._toUnbind.push(this._editor.onDidDispose(() => this.dispose()));
52-
this._toUnbind.push(this._editor.onDidChangeCursorPosition(() => {
50+
this._toUnbind.add(this._editor.onDidDispose(() => this.dispose()));
51+
this._toUnbind.add(this._editor.onDidChangeCursorPosition(() => {
5352
if (this._ignoreSelectionChange) {
5453
return;
5554
}
@@ -190,7 +189,7 @@ class MarkerModel {
190189
}
191190

192191
public dispose(): void {
193-
this._toUnbind = dispose(this._toUnbind);
192+
this._toUnbind.dispose();
194193
}
195194
}
196195

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { ITelemetryAppender } from 'vs/platform/telemetry/common/telemetryUtils'
1010
import { optional } from 'vs/platform/instantiation/common/instantiation';
1111
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
1212
import { IConfigurationRegistry, Extensions } from 'vs/platform/configuration/common/configurationRegistry';
13-
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
13+
import { DisposableStore } from 'vs/base/common/lifecycle';
1414
import { cloneAndChange, mixin } from 'vs/base/common/objects';
1515
import { Registry } from 'vs/platform/registry/common/platform';
1616
import { ClassifiedEvent, StrictPropertyCheck, GDPRClassification } from 'vs/platform/telemetry/common/gdprTypings';
@@ -35,7 +35,7 @@ export class TelemetryService implements ITelemetryService {
3535
private _userOptIn: boolean;
3636
private _enabled: boolean;
3737

38-
private _disposables: IDisposable[] = [];
38+
private readonly _disposables = new DisposableStore();
3939
private _cleanupPatterns: RegExp[] = [];
4040

4141
constructor(
@@ -113,7 +113,7 @@ export class TelemetryService implements ITelemetryService {
113113
}
114114

115115
dispose(): void {
116-
this._disposables = dispose(this._disposables);
116+
this._disposables.dispose();
117117
}
118118

119119
publicLog(eventName: string, data?: ITelemetryData, anonymizeFilePaths?: boolean): Promise<any> {

src/vs/workbench/api/common/extHostSCM.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { URI, UriComponents } from 'vs/base/common/uri';
77
import { Event, Emitter } from 'vs/base/common/event';
88
import { debounce } from 'vs/base/common/decorators';
9-
import { dispose, IDisposable, DisposableStore, MutableDisposable } from 'vs/base/common/lifecycle';
9+
import { DisposableStore, MutableDisposable } from 'vs/base/common/lifecycle';
1010
import { asPromise } from 'vs/base/common/async';
1111
import { ExtHostCommands } from 'vs/workbench/api/common/extHostCommands';
1212
import { MainContext, MainThreadSCMShape, SCMRawResource, SCMRawResourceSplice, SCMRawResourceSplices, IMainContext, ExtHostSCMShape, CommandDto } from './extHost.protocol';
@@ -263,7 +263,6 @@ class ExtHostSourceControlResourceGroup implements vscode.SourceControlResourceG
263263
}
264264

265265
readonly handle = ExtHostSourceControlResourceGroup._handlePool++;
266-
private _disposables: IDisposable[] = [];
267266

268267
constructor(
269268
private _proxy: MainThreadSCMShape,
@@ -353,7 +352,6 @@ class ExtHostSourceControlResourceGroup implements vscode.SourceControlResourceG
353352

354353
dispose(): void {
355354
this._proxy.$unregisterGroup(this._sourceControlHandle, this.handle);
356-
this._disposables = dispose(this._disposables);
357355
this._onDidDispose.fire();
358356
}
359357
}

src/vs/workbench/contrib/files/common/explorerService.ts

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

66
import { Event, Emitter } from 'vs/base/common/event';
77
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
8-
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
8+
import { DisposableStore } from 'vs/base/common/lifecycle';
99
import { IExplorerService, IEditableData, IFilesConfiguration, SortOrder, SortOrderConfiguration } from 'vs/workbench/contrib/files/common/files';
1010
import { ExplorerItem, ExplorerModel } from 'vs/workbench/contrib/files/common/explorerModel';
1111
import { URI } from 'vs/base/common/uri';
@@ -36,7 +36,7 @@ export class ExplorerService implements IExplorerService {
3636
private _onDidChangeEditable = new Emitter<ExplorerItem>();
3737
private _onDidSelectResource = new Emitter<{ resource?: URI, reveal?: boolean }>();
3838
private _onDidCopyItems = new Emitter<{ items: ExplorerItem[], cut: boolean, previouslyCutItems: ExplorerItem[] | undefined }>();
39-
private disposables: IDisposable[] = [];
39+
private readonly disposables = new DisposableStore();
4040
private editable: { stat: ExplorerItem, data: IEditableData } | undefined;
4141
private _sortOrder: SortOrder;
4242
private cutItems: ExplorerItem[] | undefined;
@@ -88,18 +88,18 @@ export class ExplorerService implements IExplorerService {
8888
(root?: URI) => getFileEventsExcludes(this.configurationService, root),
8989
(event: IConfigurationChangeEvent) => event.affectsConfiguration(FILES_EXCLUDE_CONFIG)
9090
);
91-
this.disposables.push(fileEventsFilter);
91+
this.disposables.add(fileEventsFilter);
9292

9393
return fileEventsFilter;
9494
}
9595

9696
@memoize get model(): ExplorerModel {
9797
const model = new ExplorerModel(this.contextService);
98-
this.disposables.push(model);
99-
this.disposables.push(this.fileService.onAfterOperation(e => this.onFileOperation(e)));
100-
this.disposables.push(this.fileService.onFileChanges(e => this.onFileChanges(e)));
101-
this.disposables.push(this.configurationService.onDidChangeConfiguration(e => this.onConfigurationUpdated(this.configurationService.getValue<IFilesConfiguration>())));
102-
this.disposables.push(this.fileService.onDidChangeFileSystemProviderRegistrations(e => {
98+
this.disposables.add(model);
99+
this.disposables.add(this.fileService.onAfterOperation(e => this.onFileOperation(e)));
100+
this.disposables.add(this.fileService.onFileChanges(e => this.onFileChanges(e)));
101+
this.disposables.add(this.configurationService.onDidChangeConfiguration(e => this.onConfigurationUpdated(this.configurationService.getValue<IFilesConfiguration>())));
102+
this.disposables.add(this.fileService.onDidChangeFileSystemProviderRegistrations(e => {
103103
if (e.added && this.fileSystemProviderSchemes.has(e.scheme)) {
104104
// A file system provider got re-registered, we should update all file stats since they might change (got read-only)
105105
this.model.roots.forEach(r => r.forgetChildren());
@@ -108,7 +108,7 @@ export class ExplorerService implements IExplorerService {
108108
this.fileSystemProviderSchemes.add(e.scheme);
109109
}
110110
}));
111-
this.disposables.push(model.onDidChangeRoots(() => this._onDidChangeRoots.fire()));
111+
this.disposables.add(model.onDidChangeRoots(() => this._onDidChangeRoots.fire()));
112112

113113
return model;
114114
}
@@ -380,6 +380,6 @@ export class ExplorerService implements IExplorerService {
380380
}
381381

382382
dispose(): void {
383-
dispose(this.disposables);
383+
this.disposables.dispose();
384384
}
385385
}

0 commit comments

Comments
 (0)