Revert "Update more places where we are using an IDispoable[]"

This reverts commit 869e5921d8.
This commit is contained in:
Johannes Rieken
2019-06-06 15:30:05 +02:00
parent 37bc56de53
commit 2cd36100c4
5 changed files with 92 additions and 65 deletions

View File

@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import { Emitter, Event } from 'vs/base/common/event';
import { IDisposable, combinedDisposable, Disposable } from 'vs/base/common/lifecycle';
import { IDisposable, combinedDisposable, dispose } from 'vs/base/common/lifecycle';
import { values } from 'vs/base/common/map';
import { URI } from 'vs/base/common/uri';
import { ICodeEditor, isCodeEditor, isDiffEditor, IActiveCodeEditor } from 'vs/editor/browser/editorBrowser';
@@ -142,8 +142,9 @@ const enum ActiveEditorOrder {
Editor, Panel
}
class MainThreadDocumentAndEditorStateComputer extends Disposable {
class MainThreadDocumentAndEditorStateComputer {
private _toDispose: IDisposable[] = [];
private _toDisposeOnEditorRemove = new Map<string, IDisposable>();
private _currentState: DocumentAndEditorState;
private _activeEditorOrder: ActiveEditorOrder = ActiveEditorOrder.Editor;
@@ -155,22 +156,25 @@ class MainThreadDocumentAndEditorStateComputer extends Disposable {
@IEditorService private readonly _editorService: IEditorService,
@IPanelService private readonly _panelService: IPanelService
) {
super();
this._register(this._modelService.onModelAdded(this._updateStateOnModelAdd, this));
this._register(this._modelService.onModelRemoved(_ => this._updateState(), this));
this._register(this._editorService.onDidActiveEditorChange(_ => this._updateState(), this));
this._modelService.onModelAdded(this._updateStateOnModelAdd, this, this._toDispose);
this._modelService.onModelRemoved(_ => this._updateState(), this, this._toDispose);
this._editorService.onDidActiveEditorChange(_ => this._updateState(), this, this._toDispose);
this._register(this._codeEditorService.onCodeEditorAdd(this._onDidAddEditor, this));
this._register(this._codeEditorService.onCodeEditorRemove(this._onDidRemoveEditor, this));
this._codeEditorService.onCodeEditorAdd(this._onDidAddEditor, this, this._toDispose);
this._codeEditorService.onCodeEditorRemove(this._onDidRemoveEditor, this, this._toDispose);
this._codeEditorService.listCodeEditors().forEach(this._onDidAddEditor, this);
this._register(this._panelService.onDidPanelOpen(_ => this._activeEditorOrder = ActiveEditorOrder.Panel, undefined));
this._register(this._panelService.onDidPanelClose(_ => this._activeEditorOrder = ActiveEditorOrder.Editor, undefined));
this._register(this._editorService.onDidVisibleEditorsChange(_ => this._activeEditorOrder = ActiveEditorOrder.Editor, undefined));
this._panelService.onDidPanelOpen(_ => this._activeEditorOrder = ActiveEditorOrder.Panel, undefined, this._toDispose);
this._panelService.onDidPanelClose(_ => this._activeEditorOrder = ActiveEditorOrder.Editor, undefined, this._toDispose);
this._editorService.onDidVisibleEditorsChange(_ => this._activeEditorOrder = ActiveEditorOrder.Editor, undefined, this._toDispose);
this._updateState();
}
dispose(): void {
this._toDispose = dispose(this._toDispose);
}
private _onDidAddEditor(e: ICodeEditor): void {
this._toDisposeOnEditorRemove.set(e.getId(), combinedDisposable(
e.onDidChangeModel(() => this._updateState()),
@@ -298,15 +302,17 @@ class MainThreadDocumentAndEditorStateComputer extends Disposable {
}
@extHostCustomer
export class MainThreadDocumentsAndEditors extends Disposable {
export class MainThreadDocumentsAndEditors {
private _toDispose: IDisposable[];
private readonly _proxy: ExtHostDocumentsAndEditorsShape;
private readonly _stateComputer: MainThreadDocumentAndEditorStateComputer;
private _textEditors = <{ [id: string]: MainThreadTextEditor }>Object.create(null);
private _onTextEditorAdd = this._register(new Emitter<MainThreadTextEditor[]>());
private _onTextEditorRemove = this._register(new Emitter<string[]>());
private _onDocumentAdd = this._register(new Emitter<ITextModel[]>());
private _onDocumentRemove = this._register(new Emitter<URI[]>());
private _onTextEditorAdd = new Emitter<MainThreadTextEditor[]>();
private _onTextEditorRemove = new Emitter<string[]>();
private _onDocumentAdd = new Emitter<ITextModel[]>();
private _onDocumentRemove = new Emitter<URI[]>();
readonly onTextEditorAdd: Event<MainThreadTextEditor[]> = this._onTextEditorAdd.event;
readonly onTextEditorRemove: Event<string[]> = this._onTextEditorRemove.event;
@@ -328,17 +334,30 @@ export class MainThreadDocumentsAndEditors extends Disposable {
@IPanelService panelService: IPanelService,
@IWorkbenchEnvironmentService environmentService: IWorkbenchEnvironmentService
) {
super();
this._proxy = extHostContext.getProxy(ExtHostContext.ExtHostDocumentsAndEditors);
const mainThreadDocuments = this._register(new MainThreadDocuments(this, extHostContext, this._modelService, modeService, this._textFileService, fileService, textModelResolverService, untitledEditorService, environmentService));
const mainThreadDocuments = new MainThreadDocuments(this, extHostContext, this._modelService, modeService, this._textFileService, fileService, textModelResolverService, untitledEditorService, environmentService);
extHostContext.set(MainContext.MainThreadDocuments, mainThreadDocuments);
const mainThreadTextEditors = this._register(new MainThreadTextEditors(this, extHostContext, codeEditorService, bulkEditService, this._editorService, this._editorGroupService));
const mainThreadTextEditors = new MainThreadTextEditors(this, extHostContext, codeEditorService, bulkEditService, this._editorService, this._editorGroupService);
extHostContext.set(MainContext.MainThreadTextEditors, mainThreadTextEditors);
// It is expected that the ctor of the state computer calls our `_onDelta`.
this._register(new MainThreadDocumentAndEditorStateComputer(delta => this._onDelta(delta), _modelService, codeEditorService, this._editorService, panelService));
this._stateComputer = new MainThreadDocumentAndEditorStateComputer(delta => this._onDelta(delta), _modelService, codeEditorService, this._editorService, panelService);
this._toDispose = [
mainThreadDocuments,
mainThreadTextEditors,
this._stateComputer,
this._onTextEditorAdd,
this._onTextEditorRemove,
this._onDocumentAdd,
this._onDocumentRemove,
];
}
dispose(): void {
this._toDispose = dispose(this._toDispose);
}
private _onDelta(delta: DocumentAndEditorStateDelta): void {