Using DisposableStore in place of disposable arrays in a few more files

This commit is contained in:
Matt Bierner 2019-07-03 18:14:55 -07:00
parent 1da98a12da
commit e6b698b4fd
7 changed files with 59 additions and 69 deletions

View file

@ -6,7 +6,7 @@
import * as nls from 'vs/nls';
import { Emitter } from 'vs/base/common/event';
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { IDisposable, dispose, DisposableStore } from 'vs/base/common/lifecycle';
import { URI } from 'vs/base/common/uri';
import { RawContextKey, IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IMarker, IMarkerService, MarkerSeverity } from 'vs/platform/markers/common/markers';
@ -206,7 +206,7 @@ export class MarkerController implements editorCommon.IEditorContribution {
private _model: MarkerModel | null = null;
private _widget: MarkerNavigationWidget | null = null;
private readonly _widgetVisible: IContextKey<boolean>;
private _disposeOnClose: IDisposable[] = [];
private readonly _disposeOnClose = new DisposableStore();
constructor(
editor: ICodeEditor,
@ -226,11 +226,12 @@ export class MarkerController implements editorCommon.IEditorContribution {
public dispose(): void {
this._cleanUp();
this._disposeOnClose.dispose();
}
private _cleanUp(): void {
this._widgetVisible.reset();
this._disposeOnClose = dispose(this._disposeOnClose);
this._disposeOnClose.clear();
this._widget = null;
this._model = null;
}
@ -255,19 +256,21 @@ export class MarkerController implements editorCommon.IEditorContribution {
this._widgetVisible.set(true);
this._widget.onDidClose(() => this._cleanUp(), this, this._disposeOnClose);
this._disposeOnClose.push(this._model);
this._disposeOnClose.push(this._widget);
this._disposeOnClose.push(...actions);
this._disposeOnClose.push(this._widget.onDidSelectRelatedInformation(related => {
this._disposeOnClose.add(this._model);
this._disposeOnClose.add(this._widget);
for (const action of actions) {
this._disposeOnClose.add(action);
}
this._disposeOnClose.add(this._widget.onDidSelectRelatedInformation(related => {
this._editorService.openCodeEditor({
resource: related.resource,
options: { pinned: true, revealIfOpened: true, selection: Range.lift(related).collapseToStart() }
}, this._editor).then(undefined, onUnexpectedError);
this.closeMarkersNavigation(false);
}));
this._disposeOnClose.push(this._editor.onDidChangeModel(() => this._cleanUp()));
this._disposeOnClose.add(this._editor.onDidChangeModel(() => this._cleanUp()));
this._disposeOnClose.push(this._model.onCurrentMarkerChanged(marker => {
this._disposeOnClose.add(this._model.onCurrentMarkerChanged(marker => {
if (!marker || !this._model) {
this._cleanUp();
} else {
@ -279,7 +282,7 @@ export class MarkerController implements editorCommon.IEditorContribution {
});
}
}));
this._disposeOnClose.push(this._model.onMarkerSetChanged(() => {
this._disposeOnClose.add(this._model.onMarkerSetChanged(() => {
if (!this._widget || !this._widget.position || !this._model) {
return;
}

View file

@ -268,7 +268,7 @@ export class WorkbenchList<T> extends List<T> {
}
);
this.disposables.push(workbenchListOptionsDisposable);
this.disposables.add(workbenchListOptionsDisposable);
this.contextKeyService = createScopedContextKeyService(contextKeyService, this);
this.configurationService = configurationService;
@ -282,31 +282,29 @@ export class WorkbenchList<T> extends List<T> {
this._useAltAsMultipleSelectionModifier = useAltAsMultipleSelectionModifier(configurationService);
this.disposables.push(
this.contextKeyService,
(listService as ListService).register(this),
attachListStyler(this, themeService),
this.onSelectionChange(() => {
const selection = this.getSelection();
const focus = this.getFocus();
this.disposables.add(this.contextKeyService);
this.disposables.add((listService as ListService).register(this));
this.disposables.add(attachListStyler(this, themeService));
this.disposables.add(this.onSelectionChange(() => {
const selection = this.getSelection();
const focus = this.getFocus();
this.listHasSelectionOrFocus.set(selection.length > 0 || focus.length > 0);
this.listMultiSelection.set(selection.length > 1);
this.listDoubleSelection.set(selection.length === 2);
}),
this.onFocusChange(() => {
const selection = this.getSelection();
const focus = this.getFocus();
this.listHasSelectionOrFocus.set(selection.length > 0 || focus.length > 0);
this.listMultiSelection.set(selection.length > 1);
this.listDoubleSelection.set(selection.length === 2);
}));
this.disposables.add(this.onFocusChange(() => {
const selection = this.getSelection();
const focus = this.getFocus();
this.listHasSelectionOrFocus.set(selection.length > 0 || focus.length > 0);
})
);
this.listHasSelectionOrFocus.set(selection.length > 0 || focus.length > 0);
}));
this.registerListeners();
}
private registerListeners(): void {
this.disposables.push(this.configurationService.onDidChangeConfiguration(e => {
this.disposables.add(this.configurationService.onDidChangeConfiguration(e => {
if (e.affectsConfiguration(multiSelectModifierSettingKey)) {
this._useAltAsMultipleSelectionModifier = useAltAsMultipleSelectionModifier(this.configurationService);
}

View file

@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { IDisposable, Disposable } from 'vs/base/common/lifecycle';
import { Disposable, DisposableStore } from 'vs/base/common/lifecycle';
import { URI } from 'vs/base/common/uri';
import { Event, Emitter } from 'vs/base/common/event';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
@ -23,7 +23,7 @@ export class RangeHighlightDecorations extends Disposable {
private rangeHighlightDecorationId: string | null = null;
private editor: ICodeEditor | null = null;
private editorDisposables: IDisposable[] = [];
private readonly editorDisposables = this._register(new DisposableStore());
private readonly _onHighlightRemoved: Emitter<void> = this._register(new Emitter<void>());
get onHighlightRemoved(): Event<void> { return this._onHighlightRemoved.event; }
@ -72,9 +72,9 @@ export class RangeHighlightDecorations extends Disposable {
private setEditor(editor: ICodeEditor) {
if (this.editor !== editor) {
this.disposeEditorListeners();
this.editorDisposables.clear();
this.editor = editor;
this.editorDisposables.push(this.editor.onDidChangeCursorPosition((e: ICursorPositionChangedEvent) => {
this.editorDisposables.add(this.editor.onDidChangeCursorPosition((e: ICursorPositionChangedEvent) => {
if (
e.reason === CursorChangeReason.NotSet
|| e.reason === CursorChangeReason.Explicit
@ -84,19 +84,14 @@ export class RangeHighlightDecorations extends Disposable {
this.removeHighlightRange();
}
}));
this.editorDisposables.push(this.editor.onDidChangeModel(() => { this.removeHighlightRange(); }));
this.editorDisposables.push(this.editor.onDidDispose(() => {
this.editorDisposables.add(this.editor.onDidChangeModel(() => { this.removeHighlightRange(); }));
this.editorDisposables.add(this.editor.onDidDispose(() => {
this.removeHighlightRange();
this.editor = null;
}));
}
}
private disposeEditorListeners() {
this.editorDisposables.forEach(disposable => disposable.dispose());
this.editorDisposables = [];
}
private static readonly _WHOLE_LINE_RANGE_HIGHLIGHT = ModelDecorationOptions.register({
stickiness: TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges,
className: 'rangeHighlight',
@ -117,7 +112,6 @@ export class RangeHighlightDecorations extends Disposable {
if (this.editor && this.editor.getModel()) {
this.removeHighlightRange();
this.disposeEditorListeners();
this.editor = null;
}
}

View file

@ -15,7 +15,7 @@ import Messages from 'vs/workbench/contrib/markers/browser/messages';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { attachBadgeStyler } from 'vs/platform/theme/common/styler';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { IDisposable, dispose, Disposable, toDisposable } from 'vs/base/common/lifecycle';
import { IDisposable, dispose, Disposable, toDisposable, DisposableStore } from 'vs/base/common/lifecycle';
import { ActionBar } from 'vs/base/browser/ui/actionbar/actionbar';
import { QuickFixAction, QuickFixActionViewItem } from 'vs/workbench/contrib/markers/browser/markersPanelActions';
import { ILabelService } from 'vs/platform/label/common/label';
@ -143,7 +143,7 @@ export type FilterData = ResourceMarkersFilterData | MarkerFilterData | RelatedI
export class ResourceMarkersRenderer implements ITreeRenderer<ResourceMarkers, ResourceMarkersFilterData, IResourceMarkersTemplateData> {
private renderedNodes = new Map<ITreeNode<ResourceMarkers, ResourceMarkersFilterData>, IResourceMarkersTemplateData>();
private disposables: IDisposable[] = [];
private readonly disposables = new DisposableStore();
constructor(
private labels: ResourceLabels,
@ -207,7 +207,7 @@ export class ResourceMarkersRenderer implements ITreeRenderer<ResourceMarkers, R
}
dispose(): void {
this.disposables = dispose(this.disposables);
this.disposables.dispose();
}
}
@ -245,7 +245,7 @@ class MarkerWidget extends Disposable {
private readonly icon: HTMLElement;
private readonly multilineActionbar: ActionBar;
private readonly messageAndDetailsContainer: HTMLElement;
private disposables: IDisposable[] = [];
private readonly disposables = this._register(new DisposableStore());
constructor(
private parent: HTMLElement,
@ -259,15 +259,12 @@ class MarkerWidget extends Disposable {
this.icon = dom.append(parent, dom.$(''));
this.multilineActionbar = this._register(new ActionBar(dom.append(parent, dom.$('.multiline-actions'))));
this.messageAndDetailsContainer = dom.append(parent, dom.$('.marker-message-details'));
this._register(toDisposable(() => this.disposables = dispose(this.disposables)));
}
render(element: Marker, filterData: MarkerFilterData | undefined): void {
this.actionBar.clear();
this.multilineActionbar.clear();
if (this.disposables.length) {
this.disposables = dispose(this.disposables);
}
this.disposables.clear();
dom.clearNode(this.messageAndDetailsContainer);
this.icon.className = `marker-icon ${SeverityIcon.className(MarkerSeverity.toSeverity(element.marker.severity))}`;
@ -275,8 +272,8 @@ class MarkerWidget extends Disposable {
this.renderMultilineActionbar(element);
this.renderMessageAndDetails(element, filterData);
this.disposables.push(dom.addDisposableListener(this.parent, dom.EventType.MOUSE_OVER, () => this.markersViewModel.onMarkerMouseHover(element)));
this.disposables.push(dom.addDisposableListener(this.parent, dom.EventType.MOUSE_LEAVE, () => this.markersViewModel.onMarkerMouseLeave(element)));
this.disposables.add(dom.addDisposableListener(this.parent, dom.EventType.MOUSE_OVER, () => this.markersViewModel.onMarkerMouseHover(element)));
this.disposables.add(dom.addDisposableListener(this.parent, dom.EventType.MOUSE_LEAVE, () => this.markersViewModel.onMarkerMouseLeave(element)));
}
private renderQuickfixActionbar(marker: Marker): void {

View file

@ -8,7 +8,7 @@ import { CancellationTokenSource } from 'vs/base/common/cancellation';
import * as errors from 'vs/base/common/errors';
import { Emitter, Event } from 'vs/base/common/event';
import { getBaseLabel } from 'vs/base/common/labels';
import { Disposable, IDisposable } from 'vs/base/common/lifecycle';
import { Disposable, IDisposable, DisposableStore } from 'vs/base/common/lifecycle';
import { ResourceMap, TernarySearchTree, values } from 'vs/base/common/map';
import * as objects from 'vs/base/common/objects';
import { lcut } from 'vs/base/common/strings';
@ -1044,7 +1044,7 @@ export class RangeHighlightDecorations implements IDisposable {
private _decorationId: string | null = null;
private _model: ITextModel | null = null;
private _modelDisposables: IDisposable[] = [];
private readonly _modelDisposables = new DisposableStore();
constructor(
@IModelService private readonly _modelService: IModelService
@ -1079,30 +1079,29 @@ export class RangeHighlightDecorations implements IDisposable {
private setModel(model: ITextModel) {
if (this._model !== model) {
this.disposeModelListeners();
this.clearModelListeners();
this._model = model;
this._modelDisposables.push(this._model.onDidChangeDecorations((e) => {
this.disposeModelListeners();
this._modelDisposables.add(this._model.onDidChangeDecorations((e) => {
this.clearModelListeners();
this.removeHighlightRange();
this._model = null;
}));
this._modelDisposables.push(this._model.onWillDispose(() => {
this.disposeModelListeners();
this._modelDisposables.add(this._model.onWillDispose(() => {
this.clearModelListeners();
this.removeHighlightRange();
this._model = null;
}));
}
}
private disposeModelListeners() {
this._modelDisposables.forEach(disposable => disposable.dispose());
this._modelDisposables = [];
private clearModelListeners() {
this._modelDisposables.clear();
}
dispose() {
if (this._model) {
this.removeHighlightRange();
this.disposeModelListeners();
this._modelDisposables.dispose();
this._model = null;
}
}

View file

@ -9,7 +9,7 @@ import { onDidChangeFullscreen, isFullscreen } from 'vs/base/browser/browser';
import { getTotalHeight, getTotalWidth } from 'vs/base/browser/dom';
import { Color } from 'vs/base/common/color';
import { Event } from 'vs/base/common/event';
import { dispose, IDisposable } from 'vs/base/common/lifecycle';
import { DisposableStore } from 'vs/base/common/lifecycle';
import { ILifecycleService, LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle';
import { Registry } from 'vs/platform/registry/common/platform';
import { ColorIdentifier, editorBackground, foreground } from 'vs/platform/theme/common/colorRegistry';
@ -30,7 +30,7 @@ class PartsSplash {
private static readonly _splashElementId = 'monaco-parts-splash';
private readonly _disposables: IDisposable[] = [];
private readonly _disposables = new DisposableStore();
private _didChangeTitleBarStyle: boolean;
private _lastBaseTheme: string;
@ -64,7 +64,7 @@ class PartsSplash {
}
dispose(): void {
dispose(this._disposables);
this._disposables.dispose();
}
private _savePartsSplash() {

View file

@ -6,7 +6,7 @@
import { IStringDictionary, INumberDictionary } from 'vs/base/common/collections';
import { URI } from 'vs/base/common/uri';
import { Event, Emitter } from 'vs/base/common/event';
import { IDisposable } from 'vs/base/common/lifecycle';
import { IDisposable, DisposableStore } from 'vs/base/common/lifecycle';
import { IModelService } from 'vs/editor/common/services/modelService';
@ -43,7 +43,7 @@ export abstract class AbstractProblemCollector implements IDisposable {
private buffer: string[];
private bufferLength: number;
private openModels: IStringDictionary<boolean>;
private modelListeners: IDisposable[];
private readonly modelListeners = new DisposableStore();
private tail: Promise<void>;
// [owner] -> ApplyToKind
@ -77,7 +77,6 @@ export abstract class AbstractProblemCollector implements IDisposable {
this._numberOfMatches = 0;
this._maxMarkerSeverity = undefined;
this.openModels = Object.create(null);
this.modelListeners = [];
this.applyToByOwner = new Map<string, ApplyToKind>();
for (let problemMatcher of problemMatchers) {
let current = this.applyToByOwner.get(problemMatcher.owner);
@ -119,7 +118,7 @@ export abstract class AbstractProblemCollector implements IDisposable {
protected abstract async processLineInternal(line: string): Promise<void>;
public dispose() {
this.modelListeners.forEach(disposable => disposable.dispose());
this.modelListeners.dispose();
}
public get numberOfMatches(): number {