Clean up some more disposable usage (#7190)

* clean up some more disposable usage

* fix a bug

* add more to register
This commit is contained in:
Anthony Dresser
2019-09-13 12:28:33 -07:00
committed by GitHub
parent c9128d56c0
commit d9c5b7ea9e
12 changed files with 86 additions and 144 deletions

View File

@@ -30,7 +30,7 @@ import { IThemeService } from 'vs/platform/theme/common/themeService';
import { isUndefinedOrNull } from 'vs/base/common/types';
import { range } from 'vs/base/common/arrays';
import { Orientation } from 'vs/base/browser/ui/splitview/splitview';
import { Disposable, IDisposable, dispose } from 'vs/base/common/lifecycle';
import { Disposable, dispose, DisposableStore } from 'vs/base/common/lifecycle';
import { generateUuid } from 'vs/base/common/uuid';
import { Separator, ActionBar, ActionsOrientation } from 'vs/base/browser/ui/actionbar/actionbar';
import { isInDOM, Dimension } from 'vs/base/browser/dom';
@@ -59,12 +59,12 @@ const ACTIONBAR_HEIGHT = 120;
// this handles min size if rows is greater than the min grid visible rows
const MIN_GRID_HEIGHT = (MIN_GRID_HEIGHT_ROWS * ROW_HEIGHT) + HEADER_HEIGHT + ESTIMATED_SCROLL_BAR_HEIGHT;
export class GridPanel {
export class GridPanel extends Disposable {
private container = document.createElement('div');
private splitView: ScrollableSplitView;
private tables: GridTable<any>[] = [];
private tableDisposable: IDisposable[] = [];
private queryRunnerDisposables: IDisposable[] = [];
private tableDisposable = this._register(new DisposableStore());
private queryRunnerDisposables = this._register(new DisposableStore());
private currentHeight: number;
private runner: QueryRunner;
@@ -78,6 +78,7 @@ export class GridPanel {
@IInstantiationService private readonly instantiationService: IInstantiationService,
@ILogService private readonly logService: ILogService
) {
super();
this.splitView = new ScrollableSplitView(this.container, { enableResizing: false, verticalScrollbarVisibility: ScrollbarVisibility.Visible });
this.splitView.onScroll(e => {
if (this.state && this.splitView.length !== 0) {
@@ -107,13 +108,12 @@ export class GridPanel {
}
public set queryRunner(runner: QueryRunner) {
dispose(this.queryRunnerDisposables);
this.queryRunnerDisposables.clear();
this.reset();
this.queryRunnerDisposables = [];
this.runner = runner;
this.queryRunnerDisposables.push(this.runner.onResultSet(this.onResultSet, this));
this.queryRunnerDisposables.push(this.runner.onResultSetUpdate(this.updateResultSet, this));
this.queryRunnerDisposables.push(this.runner.onQueryStart(() => {
this.queryRunnerDisposables.add(this.runner.onResultSet(this.onResultSet, this));
this.queryRunnerDisposables.add(this.runner.onResultSetUpdate(this.updateResultSet, this));
this.queryRunnerDisposables.add(this.runner.onQueryStart(() => {
if (this.state) {
this.state.tableStates = [];
}
@@ -218,14 +218,14 @@ export class GridPanel {
}
}
let table = this.instantiationService.createInstance(GridTable, this.runner, set, tableState);
this.tableDisposable.push(tableState.onMaximizedChange(e => {
this.tableDisposable.add(tableState.onMaximizedChange(e => {
if (e) {
this.maximizeTable(table.id);
} else {
this.minimizeTables();
}
}));
this.tableDisposable.push(attachTableStyler(table, this.themeService));
this.tableDisposable.add(attachTableStyler(table, this.themeService));
tables.push(table);
}
@@ -254,8 +254,7 @@ export class GridPanel {
this.splitView.removeView(i);
}
dispose(this.tables);
dispose(this.tableDisposable);
this.tableDisposable = [];
this.tableDisposable.clear();
this.tables = [];
this.maximizedGrid = undefined;
}
@@ -305,11 +304,9 @@ export class GridPanel {
}
public dispose() {
dispose(this.queryRunnerDisposables);
dispose(this.tableDisposable);
dispose(this.tables);
this.tableDisposable = undefined;
this.tables = undefined;
super.dispose();
}
}

View File

@@ -21,7 +21,7 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
import { OpenMode, ClickBehavior, ICancelableEvent, IControllerOptions } from 'vs/base/parts/tree/browser/treeDefaults';
import { WorkbenchTreeController } from 'vs/platform/list/browser/listService';
import { isArray } from 'vs/base/common/types';
import { IDisposable, dispose, Disposable } from 'vs/base/common/lifecycle';
import { Disposable, DisposableStore } from 'vs/base/common/lifecycle';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { ScrollbarVisibility } from 'vs/base/common/scrollable';
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
@@ -68,7 +68,7 @@ export class MessagePanel extends Disposable {
private container = $('.message-tree');
private styleElement = createStyleSheet(this.container);
private queryRunnerDisposables: IDisposable[] = [];
private queryRunnerDisposables = this._register(new DisposableStore());
private _state: MessagePanelState | undefined;
private tree: ITree;
@@ -175,11 +175,10 @@ export class MessagePanel extends Disposable {
}
public set queryRunner(runner: QueryRunner) {
dispose(this.queryRunnerDisposables);
this.queryRunnerDisposables = [];
this.queryRunnerDisposables.clear();
this.reset();
this.queryRunnerDisposables.push(runner.onQueryStart(() => this.reset()));
this.queryRunnerDisposables.push(runner.onMessage(e => this.onMessage(e)));
this.queryRunnerDisposables.add(runner.onQueryStart(() => this.reset()));
this.queryRunnerDisposables.add(runner.onMessage(e => this.onMessage(e)));
this.onMessage(runner.messages);
}
@@ -246,7 +245,6 @@ export class MessagePanel extends Disposable {
}
public dispose() {
dispose(this.queryRunnerDisposables);
if (this.container) {
this.container.remove();
this.container = undefined;

View File

@@ -6,7 +6,7 @@
import 'vs/css!./media/queryActions';
import * as nls from 'vs/nls';
import { Action, IActionViewItem, IActionRunner } from 'vs/base/common/actions';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { IDisposable, dispose, Disposable } from 'vs/base/common/lifecycle';
import { IContextViewService } from 'vs/platform/contextview/browser/contextView';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IThemeService } from 'vs/platform/theme/common/themeService';
@@ -566,11 +566,10 @@ export class ToggleSqlCmdModeAction extends QueryTaskbarAction {
* Action item that handles the dropdown (combobox) that lists the available databases.
* Based off StartDebugActionItem.
*/
export class ListDatabasesActionItem implements IActionViewItem {
export class ListDatabasesActionItem extends Disposable implements IActionViewItem {
public static ID = 'listDatabaseQueryActionItem';
public actionRunner: IActionRunner;
private _toDispose: IDisposable[];
private _currentDatabaseName: string;
private _isConnected: boolean;
private _databaseListDropdown: HTMLElement;
@@ -587,7 +586,7 @@ export class ListDatabasesActionItem implements IActionViewItem {
@INotificationService private readonly notificationService: INotificationService,
@IConfigurationService private readonly configurationService: IConfigurationService
) {
this._toDispose = [];
super();
this._databaseListDropdown = $('.databaseListDropdown');
this._isInAccessibilityMode = this.configurationService.getValue('editor.accessibilitySupport') === 'on';
@@ -604,12 +603,12 @@ export class ListDatabasesActionItem implements IActionViewItem {
ariaLabel: this._selectDatabaseString,
actionLabel: nls.localize('listDatabases.toggleDatabaseNameDropdown', "Select Database Toggle Dropdown")
});
this._dropdown.onValueChange(s => this.databaseSelected(s));
this._toDispose.push(this._dropdown.onFocus(() => this.onDropdownFocus()));
this._register(this._dropdown.onValueChange(s => this.databaseSelected(s)));
this._register(this._dropdown.onFocus(() => this.onDropdownFocus()));
}
// Register event handlers
this._toDispose.push(this.connectionManagementService.onConnectionChanged(params => this.onConnectionChanged(params)));
this._register(this.connectionManagementService.onConnectionChanged(params => this.onConnectionChanged(params)));
}
// PUBLIC METHODS //////////////////////////////////////////////////////
@@ -657,10 +656,6 @@ export class ListDatabasesActionItem implements IActionViewItem {
}
}
public dispose(): void {
this._toDispose = dispose(this._toDispose);
}
// EVENT HANDLERS FROM EDITOR //////////////////////////////////////////
public onConnected(): void {
let dbName = this.getCurrentDatabaseName();

View File

@@ -22,7 +22,7 @@ import { IStorageService } from 'vs/platform/storage/common/storage';
import { IEditorGroup, IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
import { SplitView, Sizing } from 'vs/base/browser/ui/splitview/splitview';
import { Event } from 'vs/base/common/event';
import { dispose, IDisposable } from 'vs/base/common/lifecycle';
import { dispose, IDisposable, DisposableStore } from 'vs/base/common/lifecycle';
import { ISelectionData } from 'azdata';
import { Action, IActionViewItem } from 'vs/base/common/actions';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
@@ -68,7 +68,7 @@ export class QueryEditor extends BaseEditor {
private splitviewContainer: HTMLElement;
private splitview: SplitView;
private inputDisposables: IDisposable[] = [];
private inputDisposables = this._register(new DisposableStore());
private resultsVisible = false;
@@ -313,9 +313,8 @@ export class QueryEditor extends BaseEditor {
this.resultsEditor.setInput(newInput.results, options)
]);
dispose(this.inputDisposables);
this.inputDisposables = [];
this.inputDisposables.push(this.input.state.onChange(c => this.updateState(c)));
this.inputDisposables.clear();
this.inputDisposables.add(this.input.state.onChange(c => this.updateState(c)));
this.updateState({ connectingChange: true, connectedChange: true, executingChange: true, resultsVisibleChange: true, sqlCmdModeChanged: true });
const editorViewState = this.loadTextEditorViewState(this.input.getResource());

View File

@@ -5,7 +5,7 @@
import { Dimension } from 'vs/base/browser/dom';
import { localize } from 'vs/nls';
import { dispose, IDisposable } from 'vs/base/common/lifecycle';
import { Disposable } from 'vs/base/common/lifecycle';
import { Table } from 'sql/base/browser/ui/table/table';
import { PlanXmlParser } from 'sql/workbench/parts/queryPlan/common/planXmlParser';
@@ -34,17 +34,14 @@ const topOperationColumns: Array<Slick.Column<any>> = [
{ name: localize('topOperations.partitioned', "Partitioned"), field: 'partitioned', sortable: true }
];
export class TopOperationsTab implements IPanelTab {
export class TopOperationsTab extends Disposable implements IPanelTab {
public readonly title = localize('topOperationsTitle', "Top Operations");
public readonly identifier = 'TopOperationsTab';
public readonly view: TopOperationsView;
constructor(@IInstantiationService instantiationService: IInstantiationService) {
this.view = instantiationService.createInstance(TopOperationsView);
}
public dispose() {
dispose(this.view);
super();
this.view = this._register(instantiationService.createInstance(TopOperationsView));
}
public clear() {
@@ -52,14 +49,14 @@ export class TopOperationsTab implements IPanelTab {
}
}
export class TopOperationsView implements IPanelView {
export class TopOperationsView extends Disposable implements IPanelView {
private _state: TopOperationsState;
private table: Table<any>;
private disposables: IDisposable[] = [];
private container = document.createElement('div');
private dataView = new TableDataView();
constructor(@IThemeService private themeService: IThemeService) {
super();
this.table = new Table(this.container, {
columns: topOperationColumns,
dataProvider: this.dataView,
@@ -67,18 +64,14 @@ export class TopOperationsView implements IPanelView {
this.dataView.sort(args);
}
});
this.disposables.push(this.table);
this.disposables.push(attachTableStyler(this.table, this.themeService));
this._register(this.table);
this._register(attachTableStyler(this.table, this.themeService));
}
public render(container: HTMLElement): void {
container.appendChild(this.container);
}
dispose() {
dispose(this.disposables);
}
public layout(dimension: Dimension): void {
this.table.layout(dimension);
}

View File

@@ -19,25 +19,24 @@ import { TASKS_PANEL_ID } from 'sql/workbench/parts/tasks/common/tasks';
import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
import { ToggleTasksAction } from 'sql/workbench/parts/tasks/browser/tasksActions';
export class StatusUpdater implements ext.IWorkbenchContribution {
export class StatusUpdater extends lifecycle.Disposable implements ext.IWorkbenchContribution {
static ID = 'data.taskhistory.statusUpdater';
private badgeHandle: lifecycle.IDisposable;
private toDispose: lifecycle.IDisposable[];
constructor(
@IActivityService private readonly activityBarService: IActivityService,
@ITaskService private readonly taskService: ITaskService,
@IPanelService private readonly panelService: IPanelService
) {
this.toDispose = [];
super();
this.toDispose.push(this.taskService.onAddNewTask(args => {
this._register(this.taskService.onAddNewTask(args => {
this.panelService.openPanel(TASKS_PANEL_ID, true);
this.onServiceChange();
}));
this.toDispose.push(this.taskService.onTaskComplete(task => {
this._register(this.taskService.onTaskComplete(task => {
this.onServiceChange();
}));
@@ -55,8 +54,8 @@ export class StatusUpdater implements ext.IWorkbenchContribution {
}
public dispose(): void {
this.toDispose = lifecycle.dispose(this.toDispose);
lifecycle.dispose(this.badgeHandle);
super.dispose();
}
}

View File

@@ -10,7 +10,7 @@ import { Tree } from 'vs/base/parts/tree/browser/treeImpl';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { attachListStyler } from 'vs/platform/theme/common/styler';
import { ITree } from 'vs/base/parts/tree/browser/tree';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { dispose, Disposable } from 'vs/base/common/lifecycle';
import { DefaultFilter, DefaultDragAndDrop, DefaultAccessibilityProvider } from 'vs/base/parts/tree/browser/treeDefaults';
import { localize } from 'vs/nls';
import { hide, $, append } from 'vs/base/browser/dom';
@@ -27,10 +27,9 @@ import { IExpandableTree } from 'sql/workbench/parts/objectExplorer/browser/tree
/**
* TaskHistoryView implements the dynamic tree view.
*/
export class TaskHistoryView {
export class TaskHistoryView extends Disposable {
private _messages: HTMLElement;
private _tree: ITree;
private _toDispose: IDisposable[] = [];
constructor(
@IInstantiationService private _instantiationService: IInstantiationService,
@@ -38,6 +37,7 @@ export class TaskHistoryView {
@IErrorMessageService private _errorMessageService: IErrorMessageService,
@IThemeService private _themeService: IThemeService
) {
super();
}
/**
@@ -56,17 +56,17 @@ export class TaskHistoryView {
let noTaskMessage = localize('noTaskMessage', "No task history to display.");
append(this._messages, $('span')).innerText = noTaskMessage;
this._tree = this.createTaskHistoryTree(container, this._instantiationService);
this._toDispose.push(this._tree.onDidChangeSelection((event) => this.onSelected(event)));
this._tree = this._register(this.createTaskHistoryTree(container, this._instantiationService));
this._register(this._tree.onDidChangeSelection((event) => this.onSelected(event)));
// Theme styler
this._toDispose.push(attachListStyler(this._tree, this._themeService));
this._register(attachListStyler(this._tree, this._themeService));
this._toDispose.push(this._taskService.onAddNewTask(args => {
this._register(this._taskService.onAddNewTask(args => {
hide(this._messages);
this.refreshTree();
}));
this._toDispose.push(this._taskService.onTaskComplete(task => {
this._register(this._taskService.onTaskComplete(task => {
this.updateTask(task);
}));
@@ -166,12 +166,4 @@ export class TaskHistoryView {
this._tree.onHidden();
}
}
/**
* dispose the server tree view
*/
public dispose(): void {
this._tree.dispose();
this._toDispose = dispose(this._toDispose);
}
}

View File

@@ -14,7 +14,7 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
import { localize } from 'vs/nls';
import { IDisposable, toDisposable } from 'vs/base/common/lifecycle';
import { toDisposable } from 'vs/base/common/lifecycle';
import { IWorkbenchLayoutService } from 'vs/workbench/services/layout/browser/layoutService';
import * as DOM from 'vs/base/browser/dom';
import { ILogService } from 'vs/platform/log/common/log';
@@ -36,7 +36,6 @@ export class WebViewDialog extends Modal {
public onOk: Event<void> = this._onOk.event;
private _onClosed = new Emitter<void>();
public onClosed: Event<void> = this._onClosed.event;
private contentDisposables: IDisposable[] = [];
private _onMessage = new Emitter<any>();
private readonly id = generateUuid();
@@ -99,12 +98,10 @@ export class WebViewDialog extends Modal {
this._webview.mountTo(this._body);
this._webview.onMessage(message => {
this._onMessage.fire(message);
}, null, this.contentDisposables);
this._register(this._webview.onMessage(message => this._onMessage.fire(message)));
this.contentDisposables.push(this._webview);
this.contentDisposables.push(toDisposable(() => this._webview = null));
this._register(this._webview);
this._register(toDisposable(() => this._webview = null));
}
get onMessage(): Event<any> {
@@ -157,10 +154,4 @@ export class WebViewDialog extends Modal {
this.show();
this._okButton.focus();
}
public dispose(): void {
this.contentDisposables.forEach(element => {
element.dispose();
});
}
}