Skip to content

Commit

Permalink
untangle notebook document, editors and their truth, microsoft#142724…
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Feb 22, 2022
1 parent db8c1f7 commit baa9d84
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 32 deletions.
8 changes: 2 additions & 6 deletions src/vs/workbench/api/browser/mainThreadNotebookDocuments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { NotebookCellsChangeType } from 'vs/workbench/contrib/notebook/common/no
import { INotebookEditorModelResolverService } from 'vs/workbench/contrib/notebook/common/notebookEditorModelResolverService';
import { IUriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentity';
import { ExtHostContext, ExtHostNotebookDocumentsShape, MainThreadNotebookDocumentsShape, NotebookCellDto, NotebookCellsChangedEventDto, NotebookDataDto } from '../common/extHost.protocol';
import { MainThreadNotebooksAndEditors } from 'vs/workbench/api/browser/mainThreadNotebookDocumentsAndEditors';
import { NotebookDto } from 'vs/workbench/api/browser/mainThreadNotebookDto';
import { SerializableObjectWithBuffers } from 'vs/workbench/services/extensions/common/proxyIdentifier';
import { IExtHostContext } from 'vs/workbench/services/extensions/common/extHostCustomers';
Expand All @@ -28,15 +27,12 @@ export class MainThreadNotebookDocuments implements MainThreadNotebookDocumentsS

constructor(
extHostContext: IExtHostContext,
notebooksAndEditors: MainThreadNotebooksAndEditors,
@INotebookEditorModelResolverService private readonly _notebookEditorModelResolverService: INotebookEditorModelResolverService,
@IUriIdentityService private readonly _uriIdentityService: IUriIdentityService
) {
this._proxy = extHostContext.getProxy(ExtHostContext.ExtHostNotebookDocuments);
this._modelReferenceCollection = new BoundModelReferenceCollection(this._uriIdentityService.extUri);

notebooksAndEditors.onDidAddNotebooks(this._handleNotebooksAdded, this, this._disposables);
notebooksAndEditors.onDidRemoveNotebooks(this._handleNotebooksRemoved, this, this._disposables);

// forward dirty and save events
this._disposables.add(this._notebookEditorModelResolverService.onDidChangeDirty(model => this._proxy.$acceptDirtyStateChanged(model.resource, model.isDirty())));
Expand All @@ -49,7 +45,7 @@ export class MainThreadNotebookDocuments implements MainThreadNotebookDocumentsS
dispose(this._documentEventListenersMapping.values());
}

private _handleNotebooksAdded(notebooks: readonly NotebookTextModel[]): void {
handleNotebooksAdded(notebooks: readonly NotebookTextModel[]): void {

for (const textModel of notebooks) {
const disposableStore = new DisposableStore();
Expand Down Expand Up @@ -120,7 +116,7 @@ export class MainThreadNotebookDocuments implements MainThreadNotebookDocumentsS
}
}

private _handleNotebooksRemoved(uris: URI[]): void {
handleNotebooksRemoved(uris: URI[]): void {
for (const uri of uris) {
this._documentEventListenersMapping.get(uri)?.dispose();
this._documentEventListenersMapping.delete(uri);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*--------------------------------------------------------------------------------------------*/

import { diffMaps, diffSets } from 'vs/base/common/collections';
import { Emitter, Event } from 'vs/base/common/event';
import { combinedDisposable, DisposableStore, IDisposable } from 'vs/base/common/lifecycle';
import { URI } from 'vs/base/common/uri';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
Expand Down Expand Up @@ -73,15 +72,15 @@ class NotebookAndEditorState {
@extHostCustomer
export class MainThreadNotebooksAndEditors {

private readonly _onDidAddNotebooks = new Emitter<NotebookTextModel[]>();
private readonly _onDidRemoveNotebooks = new Emitter<URI[]>();
private readonly _onDidAddEditors = new Emitter<IActiveNotebookEditor[]>();
private readonly _onDidRemoveEditors = new Emitter<string[]>();
// private readonly _onDidAddNotebooks = new Emitter<NotebookTextModel[]>();
// private readonly _onDidRemoveNotebooks = new Emitter<URI[]>();
// private readonly _onDidAddEditors = new Emitter<IActiveNotebookEditor[]>();
// private readonly _onDidRemoveEditors = new Emitter<string[]>();

readonly onDidAddNotebooks: Event<NotebookTextModel[]> = this._onDidAddNotebooks.event;
readonly onDidRemoveNotebooks: Event<URI[]> = this._onDidRemoveNotebooks.event;
readonly onDidAddEditors: Event<IActiveNotebookEditor[]> = this._onDidAddEditors.event;
readonly onDidRemoveEditors: Event<string[]> = this._onDidRemoveEditors.event;
// readonly onDidAddNotebooks: Event<NotebookTextModel[]> = this._onDidAddNotebooks.event;
// readonly onDidRemoveNotebooks: Event<URI[]> = this._onDidRemoveNotebooks.event;
// readonly onDidAddEditors: Event<IActiveNotebookEditor[]> = this._onDidAddEditors.event;
// readonly onDidRemoveEditors: Event<string[]> = this._onDidRemoveEditors.event;

private readonly _proxy: Pick<ExtHostNotebookShape, '$acceptDocumentAndEditorsDelta'>;
private readonly _disposables = new DisposableStore();
Expand All @@ -103,8 +102,8 @@ export class MainThreadNotebooksAndEditors {
) {
this._proxy = extHostContext.getProxy(ExtHostContext.ExtHostNotebook);

this._mainThreadNotebooks = instantiationService.createInstance(MainThreadNotebookDocuments, extHostContext, this);
this._mainThreadEditors = instantiationService.createInstance(MainThreadNotebookEditors, extHostContext, this);
this._mainThreadNotebooks = instantiationService.createInstance(MainThreadNotebookDocuments, extHostContext);
this._mainThreadEditors = instantiationService.createInstance(MainThreadNotebookEditors, extHostContext);

extHostContext.set(MainContext.MainThreadNotebookDocuments, this._mainThreadNotebooks);
extHostContext.set(MainContext.MainThreadNotebookEditors, this._mainThreadEditors);
Expand All @@ -121,10 +120,6 @@ export class MainThreadNotebooksAndEditors {
dispose() {
this._mainThreadNotebooks.dispose();
this._mainThreadEditors.dispose();
this._onDidAddEditors.dispose();
this._onDidRemoveEditors.dispose();
this._onDidAddNotebooks.dispose();
this._onDidRemoveNotebooks.dispose();
this._disposables.dispose();
}

Expand Down Expand Up @@ -194,10 +189,10 @@ export class MainThreadNotebooksAndEditors {
this._proxy.$acceptDocumentAndEditorsDelta(new SerializableObjectWithBuffers(dto));

// handle internally
this._onDidRemoveEditors.fire(delta.removedEditors);
this._onDidRemoveNotebooks.fire(delta.removedDocuments);
this._onDidAddNotebooks.fire(delta.addedDocuments);
this._onDidAddEditors.fire(delta.addedEditors);
this._mainThreadEditors.handleEditorsRemoved(delta.removedEditors);
this._mainThreadNotebooks.handleNotebooksRemoved(delta.removedDocuments);
this._mainThreadNotebooks.handleNotebooksAdded(delta.addedDocuments);
this._mainThreadEditors.handleEditorsAdded(delta.addedEditors);
}

private static _isDeltaEmpty(delta: INotebookAndEditorDelta): boolean {
Expand Down
9 changes: 2 additions & 7 deletions src/vs/workbench/api/browser/mainThreadNotebookEditors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { DisposableStore, dispose } from 'vs/base/common/lifecycle';
import { getNotebookEditorFromEditorPane, INotebookEditor, INotebookEditorOptions } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { INotebookEditorService } from 'vs/workbench/contrib/notebook/browser/notebookEditorService';
import { ExtHostContext, ExtHostNotebookEditorsShape, ICellEditOperationDto, INotebookDocumentShowOptions, INotebookEditorViewColumnInfo, MainThreadNotebookEditorsShape, NotebookEditorRevealType } from '../common/extHost.protocol';
import { MainThreadNotebooksAndEditors } from 'vs/workbench/api/browser/mainThreadNotebookDocumentsAndEditors';
import { INotebookDecorationRenderOptions } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { ICellRange } from 'vs/workbench/contrib/notebook/common/notebookRange';
import { ILogService } from 'vs/platform/log/common/log';
Expand Down Expand Up @@ -43,17 +42,13 @@ export class MainThreadNotebookEditors implements MainThreadNotebookEditorsShape

constructor(
extHostContext: IExtHostContext,
notebooksAndEditors: MainThreadNotebooksAndEditors,
@IEditorService private readonly _editorService: IEditorService,
@ILogService private readonly _logService: ILogService,
@INotebookEditorService private readonly _notebookEditorService: INotebookEditorService,
@IEditorGroupsService private readonly _editorGroupService: IEditorGroupsService
) {
this._proxy = extHostContext.getProxy(ExtHostContext.ExtHostNotebookEditors);

notebooksAndEditors.onDidAddEditors(this._handleEditorsAdded, this, this._disposables);
notebooksAndEditors.onDidRemoveEditors(this._handleEditorsRemoved, this, this._disposables);

this._editorService.onDidActiveEditorChange(() => this._updateEditorViewColumns(), this, this._disposables);
this._editorGroupService.onDidRemoveGroup(() => this._updateEditorViewColumns(), this, this._disposables);
this._editorGroupService.onDidMoveGroup(() => this._updateEditorViewColumns(), this, this._disposables);
Expand All @@ -64,7 +59,7 @@ export class MainThreadNotebookEditors implements MainThreadNotebookEditorsShape
dispose(this._mainThreadEditors.values());
}

private _handleEditorsAdded(editors: readonly INotebookEditor[]): void {
handleEditorsAdded(editors: readonly INotebookEditor[]): void {

for (const editor of editors) {

Expand All @@ -82,7 +77,7 @@ export class MainThreadNotebookEditors implements MainThreadNotebookEditorsShape
}
}

private _handleEditorsRemoved(editorIds: readonly string[]): void {
handleEditorsRemoved(editorIds: readonly string[]): void {
for (const id of editorIds) {
this._mainThreadEditors.get(id)?.dispose();
this._mainThreadEditors.delete(id);
Expand Down

0 comments on commit baa9d84

Please sign in to comment.