Use Disposable in a few more places
There were a few instances where we were not manually diposing of one of the emitters/disposables on a class. This is easy to forget to add, so switching to use `_register` instead which puts everything on a single line
This commit is contained in:
parent
920c34a13d
commit
de9cc71487
|
@ -273,17 +273,15 @@ class NotebookComparator implements IOutlineComparator<OutlineEntry> {
|
|||
}
|
||||
}
|
||||
|
||||
export class NotebookCellOutline implements IOutline<OutlineEntry> {
|
||||
export class NotebookCellOutline extends Disposable implements IOutline<OutlineEntry> {
|
||||
|
||||
private readonly _dispoables = new DisposableStore();
|
||||
|
||||
private readonly _onDidChange = new Emitter<OutlineChangeEvent>();
|
||||
private readonly _onDidChange = this._register(new Emitter<OutlineChangeEvent>());
|
||||
|
||||
readonly onDidChange: Event<OutlineChangeEvent> = this._onDidChange.event;
|
||||
|
||||
private _entries: OutlineEntry[] = [];
|
||||
private _activeEntry?: OutlineEntry;
|
||||
private readonly _entriesDisposables = new DisposableStore();
|
||||
private readonly _entriesDisposables = this._register(new DisposableStore());
|
||||
|
||||
readonly config: IOutlineListConfig<OutlineEntry>;
|
||||
readonly outlineKind = 'notebookCells';
|
||||
|
@ -301,8 +299,8 @@ export class NotebookCellOutline implements IOutline<OutlineEntry> {
|
|||
@IMarkerService private readonly _markerService: IMarkerService,
|
||||
@IConfigurationService private readonly _configurationService: IConfigurationService,
|
||||
) {
|
||||
const selectionListener = new MutableDisposable();
|
||||
this._dispoables.add(selectionListener);
|
||||
super();
|
||||
const selectionListener = this._register(new MutableDisposable());
|
||||
const installSelectionListener = () => {
|
||||
if (!_editor.viewModel) {
|
||||
selectionListener.clear();
|
||||
|
@ -314,18 +312,18 @@ export class NotebookCellOutline implements IOutline<OutlineEntry> {
|
|||
}
|
||||
};
|
||||
|
||||
this._dispoables.add(_editor.onDidChangeModel(() => {
|
||||
this._register(_editor.onDidChangeModel(() => {
|
||||
this._recomputeState();
|
||||
installSelectionListener();
|
||||
}));
|
||||
|
||||
this._dispoables.add(_configurationService.onDidChangeConfiguration(e => {
|
||||
this._register(_configurationService.onDidChangeConfiguration(e => {
|
||||
if (e.affectsConfiguration('notebook.outline.showCodeCells')) {
|
||||
this._recomputeState();
|
||||
}
|
||||
}));
|
||||
|
||||
this._dispoables.add(themeService.onDidFileIconThemeChange(() => {
|
||||
this._register(themeService.onDidFileIconThemeChange(() => {
|
||||
this._onDidChange.fire({});
|
||||
}));
|
||||
|
||||
|
@ -367,12 +365,6 @@ export class NotebookCellOutline implements IOutline<OutlineEntry> {
|
|||
};
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
this._onDidChange.dispose();
|
||||
this._dispoables.dispose();
|
||||
this._entriesDisposables.dispose();
|
||||
}
|
||||
|
||||
private _recomputeState(): void {
|
||||
this._entriesDisposables.clear();
|
||||
this._activeEntry = undefined;
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { Event, Emitter } from 'vs/base/common/event';
|
||||
import { DisposableStore, IDisposable, toDisposable } from 'vs/base/common/lifecycle';
|
||||
import { Disposable, IDisposable, toDisposable } from 'vs/base/common/lifecycle';
|
||||
import { INotebookTextModel } from 'vs/workbench/contrib/notebook/common/notebookCommon';
|
||||
import { INotebookKernel, ISelectedNotebooksChangeEvent, INotebookKernelMatchResult, INotebookKernelService, INotebookTextModelLike } from 'vs/workbench/contrib/notebook/common/notebookKernelService';
|
||||
import { LRUCache, ResourceMap } from 'vs/base/common/map';
|
||||
|
@ -43,20 +43,19 @@ class NotebookTextModelLikeId {
|
|||
}
|
||||
}
|
||||
|
||||
export class NotebookKernelService implements INotebookKernelService {
|
||||
export class NotebookKernelService extends Disposable implements INotebookKernelService {
|
||||
|
||||
declare _serviceBrand: undefined;
|
||||
|
||||
private readonly _disposables = new DisposableStore();
|
||||
private readonly _kernels = new Map<string, KernelInfo>();
|
||||
|
||||
private readonly _typeBindings = new LRUCache<string, string>(100, 0.7);
|
||||
private readonly _notebookBindings = new LRUCache<string, string>(1000, 0.7);
|
||||
|
||||
private readonly _onDidChangeNotebookKernelBinding = new Emitter<ISelectedNotebooksChangeEvent>();
|
||||
private readonly _onDidAddKernel = new Emitter<INotebookKernel>();
|
||||
private readonly _onDidRemoveKernel = new Emitter<INotebookKernel>();
|
||||
private readonly _onDidChangeNotebookAffinity = new Emitter<void>();
|
||||
private readonly _onDidChangeNotebookKernelBinding = this._register(new Emitter<ISelectedNotebooksChangeEvent>());
|
||||
private readonly _onDidAddKernel = this._register(new Emitter<INotebookKernel>());
|
||||
private readonly _onDidRemoveKernel = this._register(new Emitter<INotebookKernel>());
|
||||
private readonly _onDidChangeNotebookAffinity = this._register(new Emitter<void>());
|
||||
|
||||
readonly onDidChangeSelectedNotebooks: Event<ISelectedNotebooksChangeEvent> = this._onDidChangeNotebookKernelBinding.event;
|
||||
readonly onDidAddKernel: Event<INotebookKernel> = this._onDidAddKernel.event;
|
||||
|
@ -70,11 +69,12 @@ export class NotebookKernelService implements INotebookKernelService {
|
|||
@INotebookService private readonly _notebookService: INotebookService,
|
||||
@IStorageService private readonly _storageService: IStorageService,
|
||||
) {
|
||||
super();
|
||||
|
||||
// auto associate kernels to new notebook documents, also emit event when
|
||||
// a notebook has been closed (but don't update the memento)
|
||||
this._disposables.add(_notebookService.onDidAddNotebookDocument(this._tryAutoBindNotebook, this));
|
||||
this._disposables.add(_notebookService.onWillRemoveNotebookDocument(notebook => {
|
||||
this._register(_notebookService.onDidAddNotebookDocument(this._tryAutoBindNotebook, this));
|
||||
this._register(_notebookService.onWillRemoveNotebookDocument(notebook => {
|
||||
const kernelId = this._notebookBindings.get(NotebookTextModelLikeId.str(notebook));
|
||||
if (kernelId) {
|
||||
this._onDidChangeNotebookKernelBinding.fire({ notebook: notebook.uri, oldKernel: kernelId, newKernel: undefined });
|
||||
|
@ -96,12 +96,9 @@ export class NotebookKernelService implements INotebookKernelService {
|
|||
}
|
||||
}
|
||||
|
||||
dispose() {
|
||||
this._disposables.dispose();
|
||||
this._onDidChangeNotebookKernelBinding.dispose();
|
||||
this._onDidAddKernel.dispose();
|
||||
this._onDidRemoveKernel.dispose();
|
||||
override dispose() {
|
||||
this._kernels.clear();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
private _persistSoonHandle?: IDisposable;
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { Emitter } from 'vs/base/common/event';
|
||||
import { IDisposable } from 'vs/base/common/lifecycle';
|
||||
import { Disposable } from 'vs/base/common/lifecycle';
|
||||
import { IConfigurationChangeEvent, IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
||||
import { CellToolbarLocation, CellToolbarVisibility, CompactView, ConsolidatedOutputButton, ConsolidatedRunButton, DragAndDropEnabled, ExperimentalInsertToolbarAlignment, FocusIndicator, GlobalToolbar, InsertToolbarLocation, NotebookCellEditorOptionsCustomizations, NotebookCellInternalMetadata, ShowCellStatusBar, ShowCellStatusBarType, ShowFoldingControls } from 'vs/workbench/contrib/notebook/common/notebookCommon';
|
||||
|
||||
|
@ -100,13 +100,13 @@ const compactConfigConstants = {
|
|||
focusIndicatorLeftMargin: 4
|
||||
};
|
||||
|
||||
export class NotebookOptions {
|
||||
export class NotebookOptions extends Disposable {
|
||||
private _layoutConfiguration: NotebookLayoutConfiguration;
|
||||
protected readonly _onDidChangeOptions = new Emitter<NotebookOptionsChangeEvent>();
|
||||
protected readonly _onDidChangeOptions = this._register(new Emitter<NotebookOptionsChangeEvent>());
|
||||
readonly onDidChangeOptions = this._onDidChangeOptions.event;
|
||||
private _disposables: IDisposable[];
|
||||
|
||||
constructor(private readonly configurationService: IConfigurationService) {
|
||||
super();
|
||||
const showCellStatusBar = this.configurationService.getValue<ShowCellStatusBarType>(ShowCellStatusBar);
|
||||
const globalToolbar = this.configurationService.getValue<boolean | undefined>(GlobalToolbar) ?? true;
|
||||
const consolidatedOutputButton = this.configurationService.getValue<boolean | undefined>(ConsolidatedOutputButton) ?? true;
|
||||
|
@ -123,7 +123,6 @@ export class NotebookOptions {
|
|||
const fontSize = this.configurationService.getValue<number>('editor.fontSize');
|
||||
const editorOptionsCustomizations = this.configurationService.getValue(NotebookCellEditorOptionsCustomizations);
|
||||
|
||||
this._disposables = [];
|
||||
this._layoutConfiguration = {
|
||||
...(compactView ? compactConfigConstants : defaultConfigConstants),
|
||||
cellTopMargin: 6,
|
||||
|
@ -155,11 +154,11 @@ export class NotebookOptions {
|
|||
editorOptionsCustomizations,
|
||||
};
|
||||
|
||||
this._disposables.push(this.configurationService.onDidChangeConfiguration(e => {
|
||||
this._register(this.configurationService.onDidChangeConfiguration(e => {
|
||||
this._updateConfiguration(e);
|
||||
}));
|
||||
|
||||
this._disposables.push(EditorTopPaddingChangeEvent(() => {
|
||||
this._register(EditorTopPaddingChangeEvent(() => {
|
||||
const configuration = Object.assign({}, this._layoutConfiguration);
|
||||
configuration.editorTopPadding = getEditorTopPadding();
|
||||
this._layoutConfiguration = configuration;
|
||||
|
@ -486,9 +485,4 @@ export class NotebookOptions {
|
|||
this._layoutConfiguration = { ...this._layoutConfiguration, ...{ cellBreakpointMarginActive: active } };
|
||||
this._onDidChangeOptions.fire({ cellBreakpointMargin: true });
|
||||
}
|
||||
|
||||
dispose() {
|
||||
this._disposables.forEach(d => d.dispose());
|
||||
this._disposables = [];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue