From c540e81108033d54113d5b6653fabc650c954925 Mon Sep 17 00:00:00 2001 From: Anthony Dresser Date: Tue, 20 Aug 2019 14:34:13 -0700 Subject: [PATCH] clean up some disposable use (#6832) --- src/sql/base/browser/ui/panel/panel.ts | 14 ++-- .../plugins/mousewheelTableScroll.plugin.ts | 10 +-- .../credentials/common/credentialsService.ts | 14 +--- .../metadata/common/metadataService.ts | 13 +-- .../scripting/common/scriptingService.ts | 13 +-- .../common/serializationService.ts | 13 +-- .../browser/mainThreadAccountManagement.ts | 11 +-- .../browser/mainThreadConnectionManagement.ts | 11 +-- .../browser/mainThreadCredentialManagement.ts | 13 +-- .../api/browser/mainThreadDataProtocol.ts | 15 ++-- .../browser/mainThreadExtensionManagement.ts | 11 +-- .../mainThreadNotebookDocumentsAndEditors.ts | 26 +++--- .../api/browser/mainThreadObjectExplorer.ts | 18 +--- .../api/browser/mainThreadQueryEditor.ts | 13 +-- .../api/browser/mainThreadResourceProvider.ts | 11 +-- .../parts/backup/browser/backup.component.ts | 82 +++++++++---------- .../parts/charts/browser/chartView.ts | 2 +- .../parts/dashboard/browser/core/actions.ts | 10 +-- .../browser/dataExplorerViewlet.ts | 8 -- .../parts/editData/browser/editDataActions.ts | 19 ++--- .../editData/browser/gridParentComponent.ts | 11 ++- .../notebook/common/models/notebookModel.ts | 9 +- .../objectExplorer/browser/serverTreeView.ts | 36 ++++---- 23 files changed, 139 insertions(+), 244 deletions(-) diff --git a/src/sql/base/browser/ui/panel/panel.ts b/src/sql/base/browser/ui/panel/panel.ts index f55383e9d6..ae779bf32a 100644 --- a/src/sql/base/browser/ui/panel/panel.ts +++ b/src/sql/base/browser/ui/panel/panel.ts @@ -10,8 +10,8 @@ import * as DOM from 'vs/base/browser/dom'; import { IAction } from 'vs/base/common/actions'; import { IActionOptions, ActionBar } from 'vs/base/browser/ui/actionbar/actionbar'; import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent'; -import { KeyCode, KeyMod } from 'vs/base/common/keyCodes'; -import { Disposable, IDisposable, dispose } from 'vs/base/common/lifecycle'; +import { KeyCode } from 'vs/base/common/keyCodes'; +import { Disposable, DisposableStore } from 'vs/base/common/lifecycle'; import { Color } from 'vs/base/common/color'; import { isUndefinedOrNull } from 'vs/base/common/types'; import * as map from 'vs/base/common/map'; @@ -47,7 +47,7 @@ export interface IPanelTab { interface IInternalPanelTab { tab: IPanelTab; header: HTMLElement; - disposables: IDisposable[]; + disposables: DisposableStore; label: HTMLElement; body?: HTMLElement; destroyTabBody?: boolean; @@ -119,7 +119,7 @@ export class TabbedPanel extends Disposable { public pushTab(tab: IPanelTab, index?: number, destroyTabBody?: boolean): PanelTabIdentifier { let internalTab = { tab } as IInternalPanelTab; - internalTab.disposables = []; + internalTab.disposables = new DisposableStore(); internalTab.destroyTabBody = destroyTabBody; this._tabMap.set(tab.identifier, internalTab); this._createTab(internalTab, index); @@ -158,12 +158,12 @@ export class TabbedPanel extends Disposable { tab.tab.tabSelectedHandler(); } }; - tab.disposables.push(DOM.addDisposableListener(tabHeaderElement, DOM.EventType.CLICK, e => { + tab.disposables.add(DOM.addDisposableListener(tabHeaderElement, DOM.EventType.CLICK, e => { this.showTab(tab.tab.identifier); invokeTabSelectedHandler(); })); - tab.disposables.push(DOM.addDisposableListener(tabHeaderElement, DOM.EventType.KEY_DOWN, (e: KeyboardEvent) => { + tab.disposables.add(DOM.addDisposableListener(tabHeaderElement, DOM.EventType.KEY_DOWN, (e: KeyboardEvent) => { let event = new StandardKeyboardEvent(e); if (event.equals(KeyCode.Enter)) { this.showTab(tab.tab.identifier); @@ -265,7 +265,7 @@ export class TabbedPanel extends Disposable { if (actualTab.body && actualTab.body.remove) { actualTab.body.remove(); } - dispose(actualTab.disposables); + actualTab.disposables.dispose(); this._tabMap.delete(tab); let index = this._tabOrder.findIndex(t => t === tab); this._tabOrder.splice(index, 1); diff --git a/src/sql/base/browser/ui/table/plugins/mousewheelTableScroll.plugin.ts b/src/sql/base/browser/ui/table/plugins/mousewheelTableScroll.plugin.ts index 800ce03f45..a25527f26d 100644 --- a/src/sql/base/browser/ui/table/plugins/mousewheelTableScroll.plugin.ts +++ b/src/sql/base/browser/ui/table/plugins/mousewheelTableScroll.plugin.ts @@ -6,7 +6,7 @@ import * as DOM from 'vs/base/browser/dom'; import * as Platform from 'vs/base/common/platform'; import { StandardWheelEvent, IMouseWheelEvent } from 'vs/base/browser/mouseEvent'; -import { dispose, IDisposable } from 'vs/base/common/lifecycle'; +import { DisposableStore } from 'vs/base/common/lifecycle'; import { mixin } from 'vs/base/common/objects'; const SCROLL_WHEEL_SENSITIVITY = 50; @@ -25,7 +25,7 @@ export class MouseWheelSupport implements Slick.Plugin { private canvas: HTMLElement; private options: IMouseWheelSupportOptions; - private _disposables: IDisposable[] = []; + private _disposables = new DisposableStore(); constructor(options: IMouseWheelSupportOptions = {}) { this.options = defaultOptions; @@ -39,8 +39,8 @@ export class MouseWheelSupport implements Slick.Plugin { let e = new StandardWheelEvent(browserEvent); this._onMouseWheel(e); }; - this._disposables.push(DOM.addDisposableListener(this.viewport, 'mousewheel', onMouseWheel)); - this._disposables.push(DOM.addDisposableListener(this.viewport, 'DOMMouseScroll', onMouseWheel)); + this._disposables.add(DOM.addDisposableListener(this.viewport, 'mousewheel', onMouseWheel)); + this._disposables.add(DOM.addDisposableListener(this.viewport, 'DOMMouseScroll', onMouseWheel)); } private _onMouseWheel(e: StandardWheelEvent) { @@ -111,6 +111,6 @@ export class MouseWheelSupport implements Slick.Plugin { } destroy() { - dispose(this._disposables); + this._disposables.dispose(); } } diff --git a/src/sql/platform/credentials/common/credentialsService.ts b/src/sql/platform/credentials/common/credentialsService.ts index ee9b7c86cb..cdbbcdc118 100644 --- a/src/sql/platform/credentials/common/credentialsService.ts +++ b/src/sql/platform/credentials/common/credentialsService.ts @@ -3,8 +3,8 @@ * Licensed under the Source EULA. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { IDisposable, dispose } from 'vs/base/common/lifecycle'; -import { createDecorator } from 'vs/platform/instantiation/common/instantiation'; +import { IDisposable } from 'vs/base/common/lifecycle'; +import { createDecorator, ServiceIdentifier } from 'vs/platform/instantiation/common/instantiation'; import * as azdata from 'azdata'; import { Deferred } from 'sql/base/common/promise'; @@ -21,7 +21,7 @@ export interface CredentialManagementEvents { export const ICredentialsService = createDecorator(SERVICE_ID); export interface ICredentialsService { - _serviceBrand: any; + _serviceBrand: ServiceIdentifier; saveCredential(credentialId: string, password: string): Promise; @@ -34,9 +34,7 @@ export interface ICredentialsService { export class CredentialsService implements ICredentialsService { - _serviceBrand: any; - - private disposables: IDisposable[] = []; + _serviceBrand: ServiceIdentifier; private _serverEvents: { [handle: number]: CredentialManagementEvents; } = Object.create(null); @@ -71,8 +69,4 @@ export class CredentialsService implements ICredentialsService { public deleteCredential(credentialId: string): Promise { return this._onServerEventsReady.promise.then(() => this._serverEvents[this._lastHandle].onDeleteCredential(credentialId)); } - - public dispose(): void { - this.disposables = dispose(this.disposables); - } } diff --git a/src/sql/platform/metadata/common/metadataService.ts b/src/sql/platform/metadata/common/metadataService.ts index e6286d2794..5370d98069 100644 --- a/src/sql/platform/metadata/common/metadataService.ts +++ b/src/sql/platform/metadata/common/metadataService.ts @@ -3,8 +3,7 @@ * Licensed under the Source EULA. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { IDisposable, dispose } from 'vs/base/common/lifecycle'; -import { createDecorator } from 'vs/platform/instantiation/common/instantiation'; +import { createDecorator, ServiceIdentifier } from 'vs/platform/instantiation/common/instantiation'; import { IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement'; import * as azdata from 'azdata'; @@ -13,7 +12,7 @@ export const SERVICE_ID = 'metadataService'; export const IMetadataService = createDecorator(SERVICE_ID); export interface IMetadataService { - _serviceBrand: any; + _serviceBrand: ServiceIdentifier; getMetadata(connectionUri: string): Thenable; @@ -31,9 +30,7 @@ export interface IMetadataService { export class MetadataService implements IMetadataService { - public _serviceBrand: any; - - private _disposables: IDisposable[] = []; + public _serviceBrand: ServiceIdentifier; private _providers: { [handle: string]: azdata.MetadataProvider; } = Object.create(null); @@ -94,8 +91,4 @@ export class MetadataService implements IMetadataService { public registerProvider(providerId: string, provider: azdata.MetadataProvider): void { this._providers[providerId] = provider; } - - public dispose(): void { - this._disposables = dispose(this._disposables); - } } diff --git a/src/sql/platform/scripting/common/scriptingService.ts b/src/sql/platform/scripting/common/scriptingService.ts index 5c6a7660b3..b5eb134b58 100644 --- a/src/sql/platform/scripting/common/scriptingService.ts +++ b/src/sql/platform/scripting/common/scriptingService.ts @@ -3,8 +3,7 @@ * Licensed under the Source EULA. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { IDisposable, dispose } from 'vs/base/common/lifecycle'; -import { createDecorator } from 'vs/platform/instantiation/common/instantiation'; +import { createDecorator, ServiceIdentifier } from 'vs/platform/instantiation/common/instantiation'; import { IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement'; import * as azdata from 'azdata'; import { ILogService } from 'vs/platform/log/common/log'; @@ -24,7 +23,7 @@ export enum ScriptOperation { } export interface IScriptingService { - _serviceBrand: any; + _serviceBrand: ServiceIdentifier; script(connectionUri: string, metadata: azdata.ObjectMetadata, operation: ScriptOperation, paramDetails: azdata.ScriptingParamDetails): Thenable; @@ -51,9 +50,7 @@ export interface IScriptingService { export class ScriptingService implements IScriptingService { - public _serviceBrand: any; - - private disposables: IDisposable[] = []; + public _serviceBrand: ServiceIdentifier; private _providers: { [handle: string]: azdata.ScriptingProvider; } = Object.create(null); @@ -113,8 +110,4 @@ export class ScriptingService implements IScriptingService { let provider = this._providers[providerId]; return !!provider; } - - public dispose(): void { - this.disposables = dispose(this.disposables); - } } diff --git a/src/sql/platform/serialization/common/serializationService.ts b/src/sql/platform/serialization/common/serializationService.ts index 0ec3eee1bb..a52be7ac75 100644 --- a/src/sql/platform/serialization/common/serializationService.ts +++ b/src/sql/platform/serialization/common/serializationService.ts @@ -3,8 +3,7 @@ * Licensed under the Source EULA. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { IDisposable, dispose } from 'vs/base/common/lifecycle'; -import { createDecorator } from 'vs/platform/instantiation/common/instantiation'; +import { createDecorator, ServiceIdentifier } from 'vs/platform/instantiation/common/instantiation'; import { IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement'; import { ICapabilitiesService } from 'sql/platform/capabilities/common/capabilitiesService'; import * as azdata from 'azdata'; @@ -40,7 +39,7 @@ export interface SerializeDataParams { } export interface ISerializationService { - _serviceBrand: any; + _serviceBrand: ServiceIdentifier; registerProvider(providerId: string, provider: azdata.SerializationProvider): void; @@ -62,9 +61,7 @@ function getBatchSize(totalRows: number, currentIndex: number): number { export class SerializationService implements ISerializationService { - _serviceBrand: any; - - private disposables: IDisposable[] = []; + _serviceBrand: ServiceIdentifier; private providers: { providerId: string, provider: azdata.SerializationProvider }[] = []; @@ -197,8 +194,4 @@ export class SerializationService implements ISerializationService { }; return continueSerializeRequest; } - - public dispose(): void { - this.disposables = dispose(this.disposables); - } } diff --git a/src/sql/workbench/api/browser/mainThreadAccountManagement.ts b/src/sql/workbench/api/browser/mainThreadAccountManagement.ts index 65e690a4e2..8240f2c911 100644 --- a/src/sql/workbench/api/browser/mainThreadAccountManagement.ts +++ b/src/sql/workbench/api/browser/mainThreadAccountManagement.ts @@ -5,7 +5,7 @@ import * as azdata from 'azdata'; import { IAccountManagementService } from 'sql/platform/accounts/common/interfaces'; -import { dispose, IDisposable } from 'vs/base/common/lifecycle'; +import { Disposable } from 'vs/base/common/lifecycle'; import { ExtHostAccountManagementShape, MainThreadAccountManagementShape, @@ -17,20 +17,19 @@ import { extHostNamedCustomer } from 'vs/workbench/api/common/extHostCustomers'; import { UpdateAccountListEventParams } from 'sql/platform/accounts/common/eventTypes'; @extHostNamedCustomer(SqlMainContext.MainThreadAccountManagement) -export class MainThreadAccountManagement implements MainThreadAccountManagementShape { +export class MainThreadAccountManagement extends Disposable implements MainThreadAccountManagementShape { private _providerMetadata: { [handle: number]: azdata.AccountProviderMetadata }; private _proxy: ExtHostAccountManagementShape; - private _toDispose: IDisposable[]; constructor( extHostContext: IExtHostContext, @IAccountManagementService private _accountManagementService: IAccountManagementService ) { + super(); this._providerMetadata = {}; if (extHostContext) { this._proxy = extHostContext.getProxy(SqlExtHostContext.ExtHostAccountManagement); } - this._toDispose = []; this._accountManagementService.updateAccountListEvent((e: UpdateAccountListEventParams) => { if (!e) { @@ -97,8 +96,4 @@ export class MainThreadAccountManagement implements MainThreadAccountManagementS this._accountManagementService.unregisterProvider(this._providerMetadata[handle]); return Promise.resolve(null); } - - public dispose(): void { - this._toDispose = dispose(this._toDispose); - } } diff --git a/src/sql/workbench/api/browser/mainThreadConnectionManagement.ts b/src/sql/workbench/api/browser/mainThreadConnectionManagement.ts index 4e1e7d29dd..ce557f4dec 100644 --- a/src/sql/workbench/api/browser/mainThreadConnectionManagement.ts +++ b/src/sql/workbench/api/browser/mainThreadConnectionManagement.ts @@ -12,7 +12,7 @@ import { IObjectExplorerService } from 'sql/workbench/services/objectExplorer/co import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; import * as TaskUtilities from 'sql/workbench/browser/taskUtilities'; import { IConnectionProfile } from 'sql/platform/connection/common/interfaces'; -import { dispose, IDisposable } from 'vs/base/common/lifecycle'; +import { Disposable } from 'vs/base/common/lifecycle'; import { isUndefinedOrNull } from 'vs/base/common/types'; import { generateUuid } from 'vs/base/common/uuid'; import { ICapabilitiesService } from 'sql/platform/capabilities/common/capabilitiesService'; @@ -21,10 +21,9 @@ import { IConnectionDialogService } from 'sql/workbench/services/connection/comm import { deepClone } from 'vs/base/common/objects'; @extHostNamedCustomer(SqlMainContext.MainThreadConnectionManagement) -export class MainThreadConnectionManagement implements MainThreadConnectionManagementShape { +export class MainThreadConnectionManagement extends Disposable implements MainThreadConnectionManagementShape { private _proxy: ExtHostConnectionManagementShape; - private _toDispose: IDisposable[]; constructor( extHostContext: IExtHostContext, @@ -34,14 +33,10 @@ export class MainThreadConnectionManagement implements MainThreadConnectionManag @IConnectionDialogService private _connectionDialogService: IConnectionDialogService, @ICapabilitiesService private _capabilitiesService: ICapabilitiesService ) { + super(); if (extHostContext) { this._proxy = extHostContext.getProxy(SqlExtHostContext.ExtHostConnectionManagement); } - this._toDispose = []; - } - - public dispose(): void { - this._toDispose = dispose(this._toDispose); } public $registerConnectionEventListener(handle: number, providerId: string): void { diff --git a/src/sql/workbench/api/browser/mainThreadCredentialManagement.ts b/src/sql/workbench/api/browser/mainThreadCredentialManagement.ts index c9340da767..0734d21698 100644 --- a/src/sql/workbench/api/browser/mainThreadCredentialManagement.ts +++ b/src/sql/workbench/api/browser/mainThreadCredentialManagement.ts @@ -3,7 +3,7 @@ * Licensed under the Source EULA. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { IDisposable, dispose } from 'vs/base/common/lifecycle'; +import { IDisposable, Disposable } from 'vs/base/common/lifecycle'; import { SqlExtHostContext, ExtHostCredentialManagementShape, MainThreadCredentialManagementShape, SqlMainContext @@ -14,27 +14,22 @@ import { IExtHostContext } from 'vs/workbench/api/common/extHost.protocol'; import { extHostNamedCustomer } from 'vs/workbench/api/common/extHostCustomers'; @extHostNamedCustomer(SqlMainContext.MainThreadCredentialManagement) -export class MainThreadCredentialManagement implements MainThreadCredentialManagementShape { +export class MainThreadCredentialManagement extends Disposable implements MainThreadCredentialManagementShape { private _proxy: ExtHostCredentialManagementShape; - private _toDispose: IDisposable[]; - - private _registrations: { [handle: number]: IDisposable; } = Object.create(null); + private _registrations: { [handle: number]: IDisposable; } = Object.create(null); // should we be registering these disposables? constructor( extHostContext: IExtHostContext, @ICredentialsService private credentialService: ICredentialsService ) { + super(); if (extHostContext) { this._proxy = extHostContext.getProxy(SqlExtHostContext.ExtHostCredentialManagement); } } - public dispose(): void { - this._toDispose = dispose(this._toDispose); - } - public $registerCredentialProvider(handle: number): Promise { let self = this; diff --git a/src/sql/workbench/api/browser/mainThreadDataProtocol.ts b/src/sql/workbench/api/browser/mainThreadDataProtocol.ts index ac084f3fdc..2a7ca8a59d 100644 --- a/src/sql/workbench/api/browser/mainThreadDataProtocol.ts +++ b/src/sql/workbench/api/browser/mainThreadDataProtocol.ts @@ -3,7 +3,7 @@ * Licensed under the Source EULA. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { IDisposable, dispose } from 'vs/base/common/lifecycle'; +import { IDisposable, Disposable } from 'vs/base/common/lifecycle'; import { SqlExtHostContext, ExtHostDataProtocolShape, MainThreadDataProtocolShape, SqlMainContext @@ -30,13 +30,11 @@ import { extHostNamedCustomer } from 'vs/workbench/api/common/extHostCustomers'; * Main thread class for handling data protocol management registration. */ @extHostNamedCustomer(SqlMainContext.MainThreadDataProtocol) -export class MainThreadDataProtocol implements MainThreadDataProtocolShape { +export class MainThreadDataProtocol extends Disposable implements MainThreadDataProtocolShape { private _proxy: ExtHostDataProtocolShape; - private _toDispose: IDisposable[]; - - private _capabilitiesRegistrations: { [handle: number]: IDisposable; } = Object.create(null); + private _capabilitiesRegistrations: { [handle: number]: IDisposable; } = Object.create(null); // should we be registering these? constructor( extHostContext: IExtHostContext, @@ -55,18 +53,15 @@ export class MainThreadDataProtocol implements MainThreadDataProtocolShape { @ISerializationService private _serializationService: ISerializationService, @IFileBrowserService private _fileBrowserService: IFileBrowserService ) { + super(); if (extHostContext) { this._proxy = extHostContext.getProxy(SqlExtHostContext.ExtHostDataProtocol); } if (this._connectionManagementService) { - this._connectionManagementService.onLanguageFlavorChanged(e => this._proxy.$languageFlavorChanged(e), this, this._toDispose); + this._register(this._connectionManagementService.onLanguageFlavorChanged(e => this._proxy.$languageFlavorChanged(e))); } } - public dispose(): void { - this._toDispose = dispose(this._toDispose); - } - public $registerConnectionProvider(providerId: string, handle: number): Promise { const self = this; this._connectionManagementService.registerProvider(providerId, { diff --git a/src/sql/workbench/api/browser/mainThreadExtensionManagement.ts b/src/sql/workbench/api/browser/mainThreadExtensionManagement.ts index b4aa646a76..bd45191f53 100644 --- a/src/sql/workbench/api/browser/mainThreadExtensionManagement.ts +++ b/src/sql/workbench/api/browser/mainThreadExtensionManagement.ts @@ -6,7 +6,7 @@ import { SqlMainContext, MainThreadExtensionManagementShape } from 'sql/workbench/api/common/sqlExtHost.protocol'; import { IExtHostContext } from 'vs/workbench/api/common/extHost.protocol'; import { extHostNamedCustomer } from 'vs/workbench/api/common/extHostCustomers'; -import { dispose, IDisposable } from 'vs/base/common/lifecycle'; +import { Disposable } from 'vs/base/common/lifecycle'; import { IExtensionManagementService, ILocalExtension } from 'vs/platform/extensionManagement/common/extensionManagement'; import { URI } from 'vs/base/common/uri'; import { IConfigurationService, ConfigurationTarget } from 'vs/platform/configuration/common/configuration'; @@ -15,9 +15,8 @@ import { localize } from 'vs/nls'; import { IWindowService } from 'vs/platform/windows/common/windows'; @extHostNamedCustomer(SqlMainContext.MainThreadExtensionManagement) -export class MainThreadExtensionManagement implements MainThreadExtensionManagementShape { +export class MainThreadExtensionManagement extends Disposable implements MainThreadExtensionManagementShape { - private _toDispose: IDisposable[]; private _obsoleteExtensionApiUsageNotificationShown: boolean = false; constructor( @@ -27,11 +26,7 @@ export class MainThreadExtensionManagement implements MainThreadExtensionManagem @INotificationService private _notificationService: INotificationService, @IWindowService protected readonly _windowService: IWindowService ) { - this._toDispose = []; - } - - public dispose(): void { - this._toDispose = dispose(this._toDispose); + super(); } public $install(vsixPath: string): Thenable { diff --git a/src/sql/workbench/api/browser/mainThreadNotebookDocumentsAndEditors.ts b/src/sql/workbench/api/browser/mainThreadNotebookDocumentsAndEditors.ts index 84f7fc3fc6..174e11bb43 100644 --- a/src/sql/workbench/api/browser/mainThreadNotebookDocumentsAndEditors.ts +++ b/src/sql/workbench/api/browser/mainThreadNotebookDocumentsAndEditors.ts @@ -6,7 +6,7 @@ import * as azdata from 'azdata'; import * as path from 'vs/base/common/path'; import { extHostNamedCustomer } from 'vs/workbench/api/common/extHostCustomers'; -import { Disposable, IDisposable } from 'vs/base/common/lifecycle'; +import { Disposable, DisposableStore } from 'vs/base/common/lifecycle'; import { URI, UriComponents } from 'vs/base/common/uri'; import { Event, Emitter } from 'vs/base/common/event'; import { IExtHostContext, IUndoStopOptions } from 'vs/workbench/api/common/extHost.protocol'; @@ -22,7 +22,7 @@ import { INotebookDocumentsAndEditorsDelta, INotebookEditorAddData, INotebookShowOptions, INotebookModelAddedData, INotebookModelChangedData } from 'sql/workbench/api/common/sqlExtHost.protocol'; import { NotebookInput } from 'sql/workbench/parts/notebook/common/models/notebookInput'; -import { INotebookService, INotebookEditor, IProviderInfo } from 'sql/workbench/services/notebook/common/notebookService'; +import { INotebookService, INotebookEditor } from 'sql/workbench/services/notebook/common/notebookService'; import { ISingleNotebookEditOperation, NotebookChangeKind } from 'sql/workbench/api/common/sqlExtHostTypes'; import { disposed } from 'vs/base/common/errors'; import { ICellModel, NotebookContentChange, INotebookModel } from 'sql/workbench/parts/notebook/common/models/modelInterfaces'; @@ -320,7 +320,7 @@ class MainThreadNotebookDocumentAndEditorStateComputer extends Disposable { export class MainThreadNotebookDocumentsAndEditors extends Disposable implements MainThreadNotebookDocumentsAndEditorsShape { private _proxy: ExtHostNotebookDocumentsAndEditorsShape; private _notebookEditors = new Map(); - private _modelToDisposeMap = new Map(); + private _modelToDisposeMap = new Map(); constructor( extHostContext: IExtHostContext, @IUntitledEditorService private _untitledEditorService: IUntitledEditorService, @@ -558,11 +558,9 @@ export class MainThreadNotebookDocumentsAndEditors extends Disposable implements return; } removedDocuments.forEach(removedDoc => { - let listeners = this._modelToDisposeMap.get(removedDoc.toString()); - if (listeners && listeners.length) { - listeners.forEach(listener => { - listener.dispose(); - }); + const store = this._modelToDisposeMap.get(removedDoc.toString()); + if (store) { + store.dispose(); this._modelToDisposeMap.delete(removedDoc.toString()); } }); @@ -574,9 +572,9 @@ export class MainThreadNotebookDocumentsAndEditors extends Disposable implements } addedEditors.forEach(editor => { let modelUrl = editor.uri; - this._modelToDisposeMap.set(editor.uri.toString(), [editor.contentChanged((e) => { - this._proxy.$acceptModelChanged(modelUrl, this._toNotebookChangeData(e, editor)); - })]); + const store = new DisposableStore(); + store.add(editor.contentChanged((e) => this._proxy.$acceptModelChanged(modelUrl, this._toNotebookChangeData(e, editor)))); + this._modelToDisposeMap.set(editor.uri.toString(), store); }); } @@ -680,13 +678,13 @@ export class MainThreadNotebookDocumentsAndEditors extends Disposable implements } private async doChangeKernel(editor: MainThreadNotebookEditor, displayName: string): Promise { - let listeners = this._modelToDisposeMap.get(editor.id); + const store = this._modelToDisposeMap.get(editor.id); editor.model.changeKernel(displayName); return new Promise((resolve) => { - listeners.push(editor.model.kernelChanged((kernel) => { + store.add(editor.model.kernelChanged((kernel) => { resolve(true); })); - this._modelToDisposeMap.set(editor.id, listeners); + this._modelToDisposeMap.set(editor.id, store); }); } diff --git a/src/sql/workbench/api/browser/mainThreadObjectExplorer.ts b/src/sql/workbench/api/browser/mainThreadObjectExplorer.ts index 1a7675f7be..6f255f72ff 100644 --- a/src/sql/workbench/api/browser/mainThreadObjectExplorer.ts +++ b/src/sql/workbench/api/browser/mainThreadObjectExplorer.ts @@ -3,32 +3,22 @@ * Licensed under the Source EULA. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { SqlExtHostContext, SqlMainContext, ExtHostObjectExplorerShape, MainThreadObjectExplorerShape } from 'sql/workbench/api/common/sqlExtHost.protocol'; +import { SqlMainContext, MainThreadObjectExplorerShape } from 'sql/workbench/api/common/sqlExtHost.protocol'; import * as azdata from 'azdata'; import * as vscode from 'vscode'; import { IExtHostContext } from 'vs/workbench/api/common/extHost.protocol'; import { extHostNamedCustomer } from 'vs/workbench/api/common/extHostCustomers'; import { IObjectExplorerService, NodeInfoWithConnection } from 'sql/workbench/services/objectExplorer/common/objectExplorerService'; -import { dispose, IDisposable } from 'vs/base/common/lifecycle'; +import { Disposable } from 'vs/base/common/lifecycle'; @extHostNamedCustomer(SqlMainContext.MainThreadObjectExplorer) -export class MainThreadObjectExplorer implements MainThreadObjectExplorerShape { - - private _proxy: ExtHostObjectExplorerShape; - private _toDispose: IDisposable[]; +export class MainThreadObjectExplorer extends Disposable implements MainThreadObjectExplorerShape { constructor( extHostContext: IExtHostContext, @IObjectExplorerService private _objectExplorerService: IObjectExplorerService, ) { - if (extHostContext) { - this._proxy = extHostContext.getProxy(SqlExtHostContext.ExtHostObjectExplorer); - } - this._toDispose = []; - } - - public dispose(): void { - this._toDispose = dispose(this._toDispose); + super(); } public $getNode(connectionId: string, nodePath?: string): Thenable { diff --git a/src/sql/workbench/api/browser/mainThreadQueryEditor.ts b/src/sql/workbench/api/browser/mainThreadQueryEditor.ts index ec0ca64570..923bafe190 100644 --- a/src/sql/workbench/api/browser/mainThreadQueryEditor.ts +++ b/src/sql/workbench/api/browser/mainThreadQueryEditor.ts @@ -9,16 +9,15 @@ import { extHostNamedCustomer } from 'vs/workbench/api/common/extHostCustomers'; import { IConnectionManagementService, IConnectionCompletionOptions, ConnectionType, RunQueryOnConnectionMode } from 'sql/platform/connection/common/connectionManagement'; import { QueryEditor } from 'sql/workbench/parts/query/browser/queryEditor'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; -import { dispose, IDisposable } from 'vs/base/common/lifecycle'; +import { Disposable } from 'vs/base/common/lifecycle'; import { IQueryModelService } from 'sql/platform/query/common/queryModel'; import * as azdata from 'azdata'; import { IQueryManagementService } from 'sql/platform/query/common/queryManagement'; @extHostNamedCustomer(SqlMainContext.MainThreadQueryEditor) -export class MainThreadQueryEditor implements MainThreadQueryEditorShape { +export class MainThreadQueryEditor extends Disposable implements MainThreadQueryEditorShape { private _proxy: ExtHostQueryEditorShape; - private _toDispose: IDisposable[]; constructor( extHostContext: IExtHostContext, @@ -27,14 +26,10 @@ export class MainThreadQueryEditor implements MainThreadQueryEditorShape { @IEditorService private _editorService: IEditorService, @IQueryManagementService private _queryManagementService: IQueryManagementService ) { + super(); if (extHostContext) { this._proxy = extHostContext.getProxy(SqlExtHostContext.ExtHostQueryEditor); } - this._toDispose = []; - } - - public dispose(): void { - this._toDispose = dispose(this._toDispose); } public $connect(fileUri: string, connectionId: string): Thenable { @@ -83,7 +78,7 @@ export class MainThreadQueryEditor implements MainThreadQueryEditorShape { } public $registerQueryInfoListener(handle: number, providerId: string): void { - this._toDispose.push(this._queryModelService.onQueryEvent(event => { + this._register(this._queryModelService.onQueryEvent(event => { this._proxy.$onQueryEvent(handle, event.uri, event); })); } diff --git a/src/sql/workbench/api/browser/mainThreadResourceProvider.ts b/src/sql/workbench/api/browser/mainThreadResourceProvider.ts index f68eb80e48..e609c1e5cb 100644 --- a/src/sql/workbench/api/browser/mainThreadResourceProvider.ts +++ b/src/sql/workbench/api/browser/mainThreadResourceProvider.ts @@ -5,7 +5,7 @@ import * as azdata from 'azdata'; import { IResourceProviderService } from 'sql/workbench/services/resourceProvider/common/resourceProviderService'; -import { dispose, IDisposable } from 'vs/base/common/lifecycle'; +import { Disposable } from 'vs/base/common/lifecycle'; import { ExtHostResourceProviderShape, MainThreadResourceProviderShape, @@ -17,20 +17,19 @@ import { extHostNamedCustomer } from 'vs/workbench/api/common/extHostCustomers'; @extHostNamedCustomer(SqlMainContext.MainThreadResourceProvider) -export class MainThreadResourceProvider implements MainThreadResourceProviderShape { +export class MainThreadResourceProvider extends Disposable implements MainThreadResourceProviderShape { private _providerMetadata: { [handle: number]: azdata.AccountProviderMetadata }; private _proxy: ExtHostResourceProviderShape; - private _toDispose: IDisposable[]; constructor( extHostContext: IExtHostContext, @IResourceProviderService private _resourceProviderService: IResourceProviderService ) { + super(); this._providerMetadata = {}; if (extHostContext) { this._proxy = extHostContext.getProxy(SqlExtHostContext.ExtHostResourceProvider); } - this._toDispose = []; } public $registerResourceProvider(providerMetadata: azdata.ResourceProviderMetadata, handle: number): Thenable { @@ -55,8 +54,4 @@ export class MainThreadResourceProvider implements MainThreadResourceProviderSha this._resourceProviderService.unregisterProvider(this._providerMetadata[handle].id); return Promise.resolve(null); } - - public dispose(): void { - this._toDispose = dispose(this._toDispose); - } } diff --git a/src/sql/workbench/parts/backup/browser/backup.component.ts b/src/sql/workbench/parts/backup/browser/backup.component.ts index 0195bd93c1..94e5ff9e4b 100644 --- a/src/sql/workbench/parts/backup/browser/backup.component.ts +++ b/src/sql/workbench/parts/backup/browser/backup.component.ts @@ -22,7 +22,6 @@ import { IBackupUiService } from 'sql/workbench/services/backup/common/backupUiS import * as cr from 'vs/platform/theme/common/colorRegistry'; import { MessageType } from 'vs/base/browser/ui/inputbox/inputBox'; -import * as lifecycle from 'vs/base/common/lifecycle'; import { localize } from 'vs/nls'; import * as types from 'vs/base/common/types'; import * as strings from 'vs/base/common/strings'; @@ -33,6 +32,7 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti import { ISelectOptionItem } from 'vs/base/browser/ui/selectBox/selectBox'; import { KeyCode } from 'vs/base/common/keyCodes'; import { ITheme } from 'vs/platform/theme/common/themeService'; +import { AngularDisposable } from 'sql/base/browser/lifecycle'; export const BACKUP_SELECTOR: string = 'backup-component'; @@ -115,7 +115,7 @@ const LocalizedStrings = { selector: BACKUP_SELECTOR, templateUrl: decodeURI(require.toUrl('./backup.component.html')) }) -export class BackupComponent { +export class BackupComponent extends AngularDisposable { @ViewChild('pathContainer', { read: ElementRef }) pathElement; @ViewChild('backupTypeContainer', { read: ElementRef }) backupTypeElement; @ViewChild('backupsetName', { read: ElementRef }) backupNameElement; @@ -147,7 +147,6 @@ export class BackupComponent { private localizedStrings = LocalizedStrings; private _uri: string; - private _toDispose: lifecycle.IDisposable[] = []; private _advancedHeaderSize = 32; private connection: IConnectionProfile; @@ -209,6 +208,7 @@ export class BackupComponent { @Inject(IConnectionManagementService) private connectionManagementService: IConnectionManagementService, @Inject(IInstantiationService) private instantiationService: IInstantiationService ) { + super(); this._backupUiService.onShowBackupEvent((param) => this.onGetBackupConfigInfo(param)); } @@ -293,26 +293,26 @@ export class BackupComponent { this.pathListBox.render(this.pathElement.nativeElement); // Set backup path add/remove buttons - this.addPathButton = new Button(this.addPathElement.nativeElement); + this.addPathButton = this._register(new Button(this.addPathElement.nativeElement)); this.addPathButton.label = '+'; this.addPathButton.title = localize('addFile', "Add a file"); - this.removePathButton = new Button(this.removePathElement.nativeElement); + this.removePathButton = this._register(new Button(this.removePathElement.nativeElement)); this.removePathButton.label = '-'; this.removePathButton.title = localize('removeFile', "Remove files"); // Set compression - this.compressionSelectBox = new SelectBox(this.compressionOptions, this.compressionOptions[0], this.contextViewService, undefined, { ariaLabel: this.localizedStrings.SET_BACKUP_COMPRESSION }); + this.compressionSelectBox = this._register(new SelectBox(this.compressionOptions, this.compressionOptions[0], this.contextViewService, undefined, { ariaLabel: this.localizedStrings.SET_BACKUP_COMPRESSION })); this.compressionSelectBox.render(this.compressionElement.nativeElement); // Set encryption - this.algorithmSelectBox = new SelectBox(this.encryptionAlgorithms, this.encryptionAlgorithms[0], this.contextViewService, undefined, { ariaLabel: this.localizedStrings.ALGORITHM }); + this.algorithmSelectBox = this._register(new SelectBox(this.encryptionAlgorithms, this.encryptionAlgorithms[0], this.contextViewService, undefined, { ariaLabel: this.localizedStrings.ALGORITHM })); this.algorithmSelectBox.render(this.encryptionAlgorithmElement.nativeElement); - this.encryptorSelectBox = new SelectBox([], '', this.contextViewService, undefined, { ariaLabel: this.localizedStrings.CERTIFICATE_OR_ASYMMETRIC_KEY }); + this.encryptorSelectBox = this._register(new SelectBox([], '', this.contextViewService, undefined, { ariaLabel: this.localizedStrings.CERTIFICATE_OR_ASYMMETRIC_KEY })); this.encryptorSelectBox.render(this.encryptorElement.nativeElement); // Set media - this.mediaNameBox = new InputBox(this.mediaNameElement.nativeElement, + this.mediaNameBox = this._register(new InputBox(this.mediaNameElement.nativeElement, this.contextViewService, { validationOptions: { @@ -320,15 +320,15 @@ export class BackupComponent { }, ariaLabel: LocalizedStrings.NEW_MEDIA_SET_NAME } - ); + )); - this.mediaDescriptionBox = new InputBox(this.mediaDescriptionElement.nativeElement, this.contextViewService, { + this.mediaDescriptionBox = this._register(new InputBox(this.mediaDescriptionElement.nativeElement, this.contextViewService, { ariaLabel: LocalizedStrings.NEW_MEDIA_SET_DESCRIPTION - }); + })); // Set backup retain days let invalidInputMessage = localize('backupComponent.invalidInput', "Invalid input. Value must be greater than or equal 0."); - this.backupRetainDaysBox = new InputBox(this.backupDaysElement.nativeElement, + this.backupRetainDaysBox = this._register(new InputBox(this.backupDaysElement.nativeElement, this.contextViewService, { placeholder: '0', @@ -344,7 +344,7 @@ export class BackupComponent { } }, ariaLabel: LocalizedStrings.SET_BACKUP_RETAIN_DAYS - }); + })); // Disable elements this.recoveryBox.disable(); @@ -402,24 +402,24 @@ export class BackupComponent { private addFooterButtons(): void { // Set script footer button - this.scriptButton = new Button(this.scriptButtonElement.nativeElement); + this.scriptButton = this._register(new Button(this.scriptButtonElement.nativeElement)); this.scriptButton.label = localize('backupComponent.script', "Script"); this.addButtonClickHandler(this.scriptButton, () => this.onScript()); - this._toDispose.push(attachButtonStyler(this.scriptButton, this.themeService)); + this._register(attachButtonStyler(this.scriptButton, this.themeService)); this.scriptButton.enabled = false; // Set backup footer button - this.backupButton = new Button(this.backupButtonElement.nativeElement); + this.backupButton = this._register(new Button(this.backupButtonElement.nativeElement)); this.backupButton.label = localize('backupComponent.backup', "Backup"); this.addButtonClickHandler(this.backupButton, () => this.onOk()); - this._toDispose.push(attachButtonStyler(this.backupButton, this.themeService)); + this._register(attachButtonStyler(this.backupButton, this.themeService)); this.backupEnabled = false; // Set cancel footer button - this.cancelButton = new Button(this.cancelButtonElement.nativeElement); + this.cancelButton = this._register(new Button(this.cancelButtonElement.nativeElement)); this.cancelButton.label = localize('backupComponent.cancel', "Cancel"); this.addButtonClickHandler(this.cancelButton, () => this.onCancel()); - this._toDispose.push(attachButtonStyler(this.cancelButton, this.themeService)); + this._register(attachButtonStyler(this.cancelButton, this.themeService)); } private initialize(isMetadataPopulated: boolean): void { @@ -523,35 +523,35 @@ export class BackupComponent { private registerListeners(): void { // Theme styler - this._toDispose.push(attachInputBoxStyler(this.backupNameBox, this.themeService)); - this._toDispose.push(attachInputBoxStyler(this.recoveryBox, this.themeService)); - this._toDispose.push(attachSelectBoxStyler(this.backupTypeSelectBox, this.themeService)); - this._toDispose.push(attachListBoxStyler(this.pathListBox, this.themeService)); - this._toDispose.push(attachButtonStyler(this.addPathButton, this.themeService)); - this._toDispose.push(attachButtonStyler(this.removePathButton, this.themeService)); - this._toDispose.push(attachSelectBoxStyler(this.compressionSelectBox, this.themeService)); - this._toDispose.push(attachSelectBoxStyler(this.algorithmSelectBox, this.themeService)); - this._toDispose.push(attachSelectBoxStyler(this.encryptorSelectBox, this.themeService)); - this._toDispose.push(attachInputBoxStyler(this.mediaNameBox, this.themeService)); - this._toDispose.push(attachInputBoxStyler(this.mediaDescriptionBox, this.themeService)); - this._toDispose.push(attachInputBoxStyler(this.backupRetainDaysBox, this.themeService)); - this._toDispose.push(attachCheckboxStyler(this.copyOnlyCheckBox, this.themeService)); - this._toDispose.push(attachCheckboxStyler(this.encryptCheckBox, this.themeService)); - this._toDispose.push(attachCheckboxStyler(this.verifyCheckBox, this.themeService)); - this._toDispose.push(attachCheckboxStyler(this.checksumCheckBox, this.themeService)); - this._toDispose.push(attachCheckboxStyler(this.continueOnErrorCheckBox, this.themeService)); + this._register(attachInputBoxStyler(this.backupNameBox, this.themeService)); + this._register(attachInputBoxStyler(this.recoveryBox, this.themeService)); + this._register(attachSelectBoxStyler(this.backupTypeSelectBox, this.themeService)); + this._register(attachListBoxStyler(this.pathListBox, this.themeService)); + this._register(attachButtonStyler(this.addPathButton, this.themeService)); + this._register(attachButtonStyler(this.removePathButton, this.themeService)); + this._register(attachSelectBoxStyler(this.compressionSelectBox, this.themeService)); + this._register(attachSelectBoxStyler(this.algorithmSelectBox, this.themeService)); + this._register(attachSelectBoxStyler(this.encryptorSelectBox, this.themeService)); + this._register(attachInputBoxStyler(this.mediaNameBox, this.themeService)); + this._register(attachInputBoxStyler(this.mediaDescriptionBox, this.themeService)); + this._register(attachInputBoxStyler(this.backupRetainDaysBox, this.themeService)); + this._register(attachCheckboxStyler(this.copyOnlyCheckBox, this.themeService)); + this._register(attachCheckboxStyler(this.encryptCheckBox, this.themeService)); + this._register(attachCheckboxStyler(this.verifyCheckBox, this.themeService)); + this._register(attachCheckboxStyler(this.checksumCheckBox, this.themeService)); + this._register(attachCheckboxStyler(this.continueOnErrorCheckBox, this.themeService)); - this._toDispose.push(this.backupTypeSelectBox.onDidSelect(selected => this.onBackupTypeChanged())); + this._register(this.backupTypeSelectBox.onDidSelect(selected => this.onBackupTypeChanged())); this.addButtonClickHandler(this.addPathButton, () => this.onAddClick()); this.addButtonClickHandler(this.removePathButton, () => this.onRemoveClick()); - this._toDispose.push(this.mediaNameBox.onDidChange(mediaName => { + this._register(this.mediaNameBox.onDidChange(mediaName => { this.mediaNameChanged(mediaName); })); - this._toDispose.push(this.backupRetainDaysBox.onDidChange(days => { + this._register(this.backupRetainDaysBox.onDidChange(days => { this.backupRetainDaysChanged(days); })); - this._toDispose.push(this.themeService.onDidColorThemeChange(e => this.updateTheme(e))); + this._register(this.themeService.onDidColorThemeChange(e => this.updateTheme(e))); } // Update theming that is specific to backup dialog diff --git a/src/sql/workbench/parts/charts/browser/chartView.ts b/src/sql/workbench/parts/charts/browser/chartView.ts index 3cc7c6ab79..98bd0cba73 100644 --- a/src/sql/workbench/parts/charts/browser/chartView.ts +++ b/src/sql/workbench/parts/charts/browser/chartView.ts @@ -200,7 +200,7 @@ export class ChartView extends Disposable implements IPanelView { private buildOptions() { // The first element in the disposables list is for the chart type: the master dropdown that controls other option controls. // whiling rebuilding the options we should not dispose it, otherwise it would react to the theme change event - if (this.optionDisposables.length > 1) { + if (this.optionDisposables.length > 1) { // this logic needs to be rewritten dispose(this.optionDisposables.slice(1)); this.optionDisposables.splice(1); } diff --git a/src/sql/workbench/parts/dashboard/browser/core/actions.ts b/src/sql/workbench/parts/dashboard/browser/core/actions.ts index 62542afcf9..a65375846b 100644 --- a/src/sql/workbench/parts/dashboard/browser/core/actions.ts +++ b/src/sql/workbench/parts/dashboard/browser/core/actions.ts @@ -7,7 +7,6 @@ import { Action, IAction } from 'vs/base/common/actions'; import * as nls from 'vs/nls'; import { IContextMenuService } from 'vs/platform/contextview/browser/contextView'; import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent'; -import { IDisposable } from 'vs/base/common/lifecycle'; import { IAngularEventingService, AngularEventType, IAngularEvent } from 'sql/platform/angularEventing/common/angularEventingService'; import { INewDashboardTabDialogService } from 'sql/workbench/services/dashboard/browser/newDashboardTabDialog'; @@ -157,8 +156,6 @@ export class AddFeatureTabAction extends Action { private static readonly LABEL = nls.localize('addFeatureAction.openInstalledFeatures', "Open installed features"); private static readonly ICON = 'new'; - private _disposables: IDisposable[] = []; - constructor( private _dashboardTabs: Array, private _openedTabs: Array, @@ -167,7 +164,7 @@ export class AddFeatureTabAction extends Action { @IAngularEventingService private _angularEventService: IAngularEventingService ) { super(AddFeatureTabAction.ID, AddFeatureTabAction.LABEL, AddFeatureTabAction.ICON); - this._disposables.push(subscriptionToDisposable(this._angularEventService.onAngularEvent(this._uri, (event) => this.handleDashboardEvent(event)))); + this._register(subscriptionToDisposable(this._angularEventService.onAngularEvent(this._uri, (event) => this.handleDashboardEvent(event)))); } run(): Promise { @@ -175,11 +172,6 @@ export class AddFeatureTabAction extends Action { return Promise.resolve(true); } - dispose() { - super.dispose(); - this._disposables.forEach((item) => item.dispose()); - } - private handleDashboardEvent(event: IAngularEvent): void { switch (event.event) { case AngularEventType.NEW_TABS: diff --git a/src/sql/workbench/parts/dataExplorer/browser/dataExplorerViewlet.ts b/src/sql/workbench/parts/dataExplorer/browser/dataExplorerViewlet.ts index c6e251a5a9..82bec6ac9f 100644 --- a/src/sql/workbench/parts/dataExplorer/browser/dataExplorerViewlet.ts +++ b/src/sql/workbench/parts/dataExplorer/browser/dataExplorerViewlet.ts @@ -5,7 +5,6 @@ import { localize } from 'vs/nls'; import { IWorkbenchContribution } from 'vs/workbench/common/contributions'; -import { IDisposable, dispose } from 'vs/base/common/lifecycle'; import { IAction } from 'vs/base/common/actions'; import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet'; import { append, $, addClass, toggleClass, Dimension } from 'vs/base/browser/dom'; @@ -74,13 +73,11 @@ export class DataExplorerViewlet extends ViewContainerViewlet { private root: HTMLElement; private dataSourcesBox: HTMLElement; - private disposables: IDisposable[] = []; constructor( @IWorkbenchLayoutService layoutService: IWorkbenchLayoutService, @ITelemetryService telemetryService: ITelemetryService, @IInstantiationService instantiationService: IInstantiationService, - @IViewletService private viewletService: IViewletService, @IThemeService themeService: IThemeService, @IStorageService storageService: IStorageService, @IWorkspaceContextService contextService: IWorkspaceContextService, @@ -144,9 +141,4 @@ export class DataExplorerViewlet extends ViewContainerViewlet { this._register(viewletPanel); return viewletPanel; } - - dispose(): void { - this.disposables = dispose(this.disposables); - super.dispose(); - } } diff --git a/src/sql/workbench/parts/editData/browser/editDataActions.ts b/src/sql/workbench/parts/editData/browser/editDataActions.ts index a006f47a10..c1af96315c 100644 --- a/src/sql/workbench/parts/editData/browser/editDataActions.ts +++ b/src/sql/workbench/parts/editData/browser/editDataActions.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import { Action, IActionViewItem, IActionRunner } from 'vs/base/common/actions'; -import { IDisposable, dispose } from 'vs/base/common/lifecycle'; +import { DisposableStore, Disposable } from 'vs/base/common/lifecycle'; import { IQueryModelService } from 'sql/platform/query/common/queryModel'; import { SelectBox } from 'sql/base/browser/ui/selectBox/selectBox'; import { IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement'; @@ -150,14 +150,13 @@ export class ChangeMaxRowsAction extends EditDataAction { * Action item that handles the dropdown (combobox) that lists the avaliable number of row selections * for an edit data session */ -export class ChangeMaxRowsActionItem implements IActionViewItem { +export class ChangeMaxRowsActionItem extends Disposable implements IActionViewItem { public actionRunner: IActionRunner; public defaultRowCount: number; private container: HTMLElement; private start: HTMLElement; private selectBox: SelectBox; - private toDispose: IDisposable[]; private context: any; private _options: string[]; private _currentOptionsIndex: number; @@ -166,15 +165,15 @@ export class ChangeMaxRowsActionItem implements IActionViewItem { private _editor: EditDataEditor, @IContextViewService contextViewService: IContextViewService, @IThemeService private _themeService: IThemeService) { + super(); this._options = ['200', '1000', '10000']; this._currentOptionsIndex = 0; - this.toDispose = []; this.selectBox = new SelectBox(this._options, this._options[this._currentOptionsIndex], contextViewService); this._registerListeners(); this._refreshOptions(); this.defaultRowCount = Number(this._options[this._currentOptionsIndex]); - this.toDispose.push(attachSelectBoxStyler(this.selectBox, _themeService)); + this._register(attachSelectBoxStyler(this.selectBox, _themeService)); } public render(container: HTMLElement): void { @@ -211,20 +210,16 @@ export class ChangeMaxRowsActionItem implements IActionViewItem { this.container.blur(); } - public dispose(): void { - this.toDispose = dispose(this.toDispose); - } - private _refreshOptions(databaseIndex?: number): void { this.selectBox.setOptions(this._options, this._currentOptionsIndex); } private _registerListeners(): void { - this.toDispose.push(this.selectBox.onDidSelect(selection => { + this._register(this.selectBox.onDidSelect(selection => { this._currentOptionsIndex = this._options.findIndex(x => x === selection.selected); this._editor.editDataInput.onRowDropDownSet(Number(selection.selected)); })); - this.toDispose.push(attachSelectBoxStyler(this.selectBox, this._themeService)); + this._register(attachSelectBoxStyler(this.selectBox, this._themeService)); } } @@ -263,4 +258,4 @@ export class ShowQueryPaneAction extends EditDataAction { this.updateLabel(this.editor.queryPaneEnabled()); return Promise.resolve(null); } -} \ No newline at end of file +} diff --git a/src/sql/workbench/parts/editData/browser/gridParentComponent.ts b/src/sql/workbench/parts/editData/browser/gridParentComponent.ts index 53bdbee5d1..ace4245098 100644 --- a/src/sql/workbench/parts/editData/browser/gridParentComponent.ts +++ b/src/sql/workbench/parts/editData/browser/gridParentComponent.ts @@ -25,7 +25,7 @@ import { ResolvedKeybinding } from 'vs/base/common/keyCodes'; import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; import { IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey'; import { IContextMenuService } from 'vs/platform/contextview/browser/contextView'; -import { IDisposable, dispose } from 'vs/base/common/lifecycle'; +import { DisposableStore } from 'vs/base/common/lifecycle'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService'; import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent'; @@ -54,7 +54,7 @@ export abstract class GridParentComponent { protected dataService: DataService; protected actionProvider: actions.GridActionProvider; - protected toDispose: IDisposable[]; + protected toDispose = new DisposableStore(); // Context keys to set when keybindings are available @@ -97,7 +97,6 @@ export abstract class GridParentComponent { protected queryEditorService: IQueryEditorService, protected logService: ILogService ) { - this.toDispose = []; } protected baseInit(): void { @@ -177,7 +176,7 @@ export abstract class GridParentComponent { */ protected subscribeWithDispose(subject: Subject, event: (value: any) => void): void { let sub: Subscription = subject.subscribe(event); - this.toDispose.push(subscriptionToDisposable(sub)); + this.toDispose.add(subscriptionToDisposable(sub)); } private bindKeys(contextKeyService: IContextKeyService): void { @@ -186,7 +185,7 @@ export abstract class GridParentComponent { this.queryEditorVisible.set(true); let gridContextKeyService = this.contextKeyService.createScoped(this._el.nativeElement); - this.toDispose.push(gridContextKeyService); + this.toDispose.add(gridContextKeyService); this.resultsVisibleContextKey = ResultsVisibleContext.bindTo(gridContextKeyService); this.resultsVisibleContextKey.set(true); @@ -196,7 +195,7 @@ export abstract class GridParentComponent { } protected baseDestroy(): void { - this.toDispose = dispose(this.toDispose); + this.toDispose.dispose(); } protected toggleResultPane(): void { diff --git a/src/sql/workbench/parts/notebook/common/models/notebookModel.ts b/src/sql/workbench/parts/notebook/common/models/notebookModel.ts index 954593e777..df331e7929 100644 --- a/src/sql/workbench/parts/notebook/common/models/notebookModel.ts +++ b/src/sql/workbench/parts/notebook/common/models/notebookModel.ts @@ -7,7 +7,7 @@ import { nb, connection } from 'azdata'; import { localize } from 'vs/nls'; import { Event, Emitter } from 'vs/base/common/event'; -import { Disposable, IDisposable } from 'vs/base/common/lifecycle'; +import { Disposable, DisposableStore } from 'vs/base/common/lifecycle'; import { IClientSession, INotebookModel, IDefaultConnection, INotebookModelOptions, ICellModel, NotebookContentChange, notebookConstants } from 'sql/workbench/parts/notebook/common/models/modelInterfaces'; import { NotebookChangeType, CellType, CellTypes } from 'sql/workbench/parts/notebook/common/models/contracts'; @@ -73,7 +73,7 @@ export class NotebookModel extends Disposable implements INotebookModel { private _kernelDisplayNameToNotebookProviderIds: Map = new Map(); private _onValidConnectionSelected = new Emitter(); private _oldKernel: nb.IKernel; - private _clientSessionListeners: IDisposable[] = []; + private _clientSessionListeners = new DisposableStore(); // should this be registered? private _connectionUrisToDispose: string[] = []; private _textCellsLoading: number = 0; private _standardKernels: notebookUtils.IStandardKernelWithProvider[]; @@ -486,12 +486,11 @@ export class NotebookModel extends Disposable implements INotebookModel { private updateActiveClientSession(clientSession: IClientSession) { this.clearClientSessionListeners(); this._activeClientSession = clientSession; - this._clientSessionListeners.push(this._activeClientSession.kernelChanged(e => this._kernelChangedEmitter.fire(e))); + this._clientSessionListeners.add(this._activeClientSession.kernelChanged(e => this._kernelChangedEmitter.fire(e))); } private clearClientSessionListeners() { - this._clientSessionListeners.forEach(listener => listener.dispose()); - this._clientSessionListeners = []; + this._clientSessionListeners.clear(); } public setDefaultKernelAndProviderId() { diff --git a/src/sql/workbench/parts/objectExplorer/browser/serverTreeView.ts b/src/sql/workbench/parts/objectExplorer/browser/serverTreeView.ts index 5ffe8d56da..becb805518 100644 --- a/src/sql/workbench/parts/objectExplorer/browser/serverTreeView.ts +++ b/src/sql/workbench/parts/objectExplorer/browser/serverTreeView.ts @@ -10,7 +10,7 @@ import Severity from 'vs/base/common/severity'; 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 { IDisposable, dispose, Disposable } from 'vs/base/common/lifecycle'; import { localize } from 'vs/nls'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { Event, Emitter } from 'vs/base/common/event'; @@ -39,14 +39,13 @@ import { CommandsRegistry } from 'vs/platform/commands/common/commands'; /** * ServerTreeview implements the dynamic tree view. */ -export class ServerTreeView { +export class ServerTreeView extends Disposable { public messages: HTMLElement; private _buttonSection: HTMLElement; private _treeSelectionHandler: TreeSelectionHandler; private _activeConnectionsFilterAction: ActiveConnectionsFilterAction; private _tree: ITree; - private _toDispose: IDisposable[] = []; private _onSelectionOrFocusChange: Emitter; private _actionProvider: ServerTreeActionProvider; @@ -59,6 +58,7 @@ export class ServerTreeView { @IConfigurationService private _configurationService: IConfigurationService, @ICapabilitiesService capabilitiesService: ICapabilitiesService ) { + super(); this._activeConnectionsFilterAction = this._instantiationService.createInstance( ActiveConnectionsFilterAction, ActiveConnectionsFilterAction.ID, @@ -133,35 +133,35 @@ export class ServerTreeView { this._buttonSection = append(container, $('.button-section')); const connectButton = new Button(this._buttonSection); connectButton.label = localize('serverTree.addConnection', "Add Connection"); - this._toDispose.push(attachButtonStyler(connectButton, this._themeService)); - this._toDispose.push(connectButton.onDidClick(() => { + this._register(attachButtonStyler(connectButton, this._themeService)); + this._register(connectButton.onDidClick(() => { this._connectionManagementService.showConnectionDialog(); })); } - this._tree = TreeCreationUtils.createRegisteredServersTree(container, this._instantiationService); + this._tree = this._register(TreeCreationUtils.createRegisteredServersTree(container, this._instantiationService)); //this._tree.setInput(undefined); - this._toDispose.push(this._tree.onDidChangeSelection((event) => this.onSelected(event))); - this._toDispose.push(this._tree.onDidBlur(() => this._onSelectionOrFocusChange.fire())); - this._toDispose.push(this._tree.onDidChangeFocus(() => this._onSelectionOrFocusChange.fire())); + this._register(this._tree.onDidChangeSelection((event) => this.onSelected(event))); + this._register(this._tree.onDidBlur(() => this._onSelectionOrFocusChange.fire())); + this._register(this._tree.onDidChangeFocus(() => this._onSelectionOrFocusChange.fire())); // Theme styler - this._toDispose.push(attachListStyler(this._tree, this._themeService)); + this._register(attachListStyler(this._tree, this._themeService)); // Refresh Tree when these events are emitted - this._toDispose.push(this._connectionManagementService.onAddConnectionProfile((newProfile: IConnectionProfile) => { + this._register(this._connectionManagementService.onAddConnectionProfile((newProfile: IConnectionProfile) => { this.handleAddConnectionProfile(newProfile); })); - this._toDispose.push(this._connectionManagementService.onDeleteConnectionProfile(() => { + this._register(this._connectionManagementService.onDeleteConnectionProfile(() => { this.refreshTree(); })); - this._toDispose.push(this._connectionManagementService.onDisconnect((connectionParams) => { + this._register(this._connectionManagementService.onDisconnect((connectionParams) => { if (this.isObjectExplorerConnectionUri(connectionParams.connectionUri)) { this.deleteObjectExplorerNodeAndRefreshTree(connectionParams.connectionProfile); } })); if (this._objectExplorerService && this._objectExplorerService.onUpdateObjectExplorerNodes) { - this._toDispose.push(this._objectExplorerService.onUpdateObjectExplorerNodes(args => { + this._register(this._objectExplorerService.onUpdateObjectExplorerNodes(args => { if (args.errorMessage) { this.showError(args.errorMessage); } @@ -511,12 +511,4 @@ export class ServerTreeView { public isExpanded(element: TreeNode | ConnectionProfile): boolean { return this._tree.isExpanded(element); } - - /** - * dispose the server tree view - */ - public dispose(): void { - this._tree.dispose(); - this._toDispose = dispose(this._toDispose); - } }