提交 6c5037f4 编写于 作者: R rebornix

handle notebook text model creation in notebook service

上级 399ae189
......@@ -18,7 +18,6 @@ import { CancellationToken } from 'vs/base/common/cancellation';
import { IAccessibilityService } from 'vs/platform/accessibility/common/accessibility';
import { IRelativePattern } from 'vs/base/common/glob';
import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IUndoRedoService } from 'vs/platform/undoRedo/common/undoRedo';
import { ITextModelService } from 'vs/editor/common/services/resolverService';
import { Emitter } from 'vs/base/common/event';
......@@ -168,7 +167,6 @@ class DocumentAndEditorState {
@extHostNamedCustomer(MainContext.MainThreadNotebook)
export class MainThreadNotebooks extends Disposable implements MainThreadNotebookShape {
static mainthreadNotebookDocumentHandle: number = 0;
private readonly _notebookProviders = new Map<string, IMainNotebookController>();
private readonly _notebookKernels = new Map<string, MainThreadNotebookKernel>();
private readonly _notebookKernelProviders = new Map<number, { extension: NotebookExtensionDescription, emitter: Emitter<void>, provider: IDisposable }>();
......@@ -183,8 +181,7 @@ export class MainThreadNotebooks extends Disposable implements MainThreadNoteboo
@INotebookService private _notebookService: INotebookService,
@IConfigurationService private readonly configurationService: IConfigurationService,
@IEditorService private readonly editorService: IEditorService,
@IAccessibilityService private readonly accessibilityService: IAccessibilityService,
@IInstantiationService private readonly _instantiationService: IInstantiationService
@IAccessibilityService private readonly accessibilityService: IAccessibilityService
) {
super();
......@@ -202,23 +199,6 @@ export class MainThreadNotebooks extends Disposable implements MainThreadNoteboo
return false;
}
createNotebookTextModelAndBindListeners(uri: URI, viewType: string, supportBackup: boolean) {
const disposableStore = new DisposableStore();
const textModel = this._instantiationService.createInstance(NotebookTextModel, MainThreadNotebooks.mainthreadNotebookDocumentHandle++, viewType, supportBackup, uri);
disposableStore.add(textModel.onDidModelChangeProxy(e => {
this._proxy.$acceptModelChanged(textModel.uri, e);
this._proxy.$acceptEditorPropertiesChanged(uri, { selections: { selections: textModel.selections }, metadata: null });
}));
disposableStore.add(textModel.onDidSelectionChange(e => {
const selectionsChange = e ? { selections: e } : null;
this._proxy.$acceptEditorPropertiesChanged(uri, { selections: selectionsChange, metadata: null });
}));
this._editorEventListenersMapping.set(textModel.uri.toString(), disposableStore);
return textModel;
}
async removeNotebookTextModel(uri: URI): Promise<void> {
// TODO@rebornix, remove cell should use emitDelta as well to ensure document/editor events are sent together
await this._proxy.$acceptDocumentAndEditorsDelta({ removedDocuments: [uri] });
......@@ -441,6 +421,7 @@ export class MainThreadNotebooks extends Disposable implements MainThreadNoteboo
async $registerNotebookProvider(_extension: NotebookExtensionDescription, _viewType: string, _supportBackup: boolean, _kernel: INotebookKernelInfoDto | undefined): Promise<void> {
const controller: IMainNotebookController = {
kernel: _kernel,
supportBackup: _supportBackup,
reloadNotebook: async (mainthreadTextModel: NotebookTextModel) => {
const data = await this._proxy.$resolveNotebookData(_viewType, mainthreadTextModel.uri);
if (!data) {
......@@ -463,10 +444,9 @@ export class MainThreadNotebooks extends Disposable implements MainThreadNoteboo
});
});
},
createNotebook: async (viewType: string, uri: URI, editorId?: string, backupId?: string) => {
const textModel = this.createNotebookTextModelAndBindListeners(uri, viewType, _supportBackup);
createNotebook: async (textModel: NotebookTextModel, backupId?: string) => {
// open notebook document
const data = await this._proxy.$resolveNotebookData(viewType, uri, backupId);
const data = await this._proxy.$resolveNotebookData(textModel.viewType, textModel.uri, backupId);
if (!data) {
return;
}
......@@ -481,9 +461,8 @@ export class MainThreadNotebooks extends Disposable implements MainThreadNoteboo
textModel.insertTemplateCell(mainCell);
}
this._proxy.$acceptEditorPropertiesChanged(uri, { selections: null, metadata: textModel.metadata });
return textModel;
this._proxy.$acceptEditorPropertiesChanged(textModel.uri, { selections: null, metadata: textModel.metadata });
return;
},
resolveNotebookEditor: async (viewType: string, uri: URI, editorId: string) => {
await this._proxy.$resolveNotebookEditor(viewType, uri, editorId);
......
......@@ -29,6 +29,7 @@ import { StorageScope, IStorageService } from 'vs/platform/storage/common/storag
import { IExtensionPointUser } from 'vs/workbench/services/extensions/common/extensionsRegistry';
import { generateUuid } from 'vs/base/common/uuid';
import { flatten } from 'vs/base/common/arrays';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
function MODEL_ID(resource: URI): string {
return resource.toString();
......@@ -166,6 +167,7 @@ class ModelData implements IDisposable {
}
export class NotebookService extends Disposable implements INotebookService, ICustomEditorViewTypesHandler {
declare readonly _serviceBrand: undefined;
static mainthreadNotebookDocumentHandle: number = 0;
private readonly _notebookProviders = new Map<string, { controller: IMainNotebookController, extensionData: NotebookExtensionDescription }>();
private readonly _notebookRenderers = new Map<string, INotebookRendererInfo>();
private readonly _notebookKernels = new Map<string, INotebookKernelInfo>();
......@@ -205,7 +207,8 @@ export class NotebookService extends Disposable implements INotebookService, ICu
@IEditorService private readonly _editorService: IEditorService,
@IConfigurationService private readonly _configurationService: IConfigurationService,
@IAccessibilityService private readonly _accessibilityService: IAccessibilityService,
@IStorageService private readonly _storageService: IStorageService
@IStorageService private readonly _storageService: IStorageService,
@IInstantiationService private readonly _instantiationService: IInstantiationService
) {
super();
......@@ -411,7 +414,8 @@ export class NotebookService extends Disposable implements INotebookService, ICu
return notebookModel;
} else {
notebookModel = await provider.controller.createNotebook(viewType, uri, editorId, backupId);
notebookModel = this._instantiationService.createInstance(NotebookTextModel, NotebookService.mainthreadNotebookDocumentHandle++, viewType, provider.controller.supportBackup, uri);
await provider.controller.createNotebook(notebookModel, backupId);
if (!notebookModel) {
return undefined;
......
......@@ -22,7 +22,8 @@ export const INotebookService = createDecorator<INotebookService>('notebookServi
export interface IMainNotebookController {
kernel: INotebookKernelInfoDto | undefined;
createNotebook(viewType: string, uri: URI, editorId?: string, backupId?: string): Promise<NotebookTextModel | undefined>;
supportBackup: boolean;
createNotebook(textModel: NotebookTextModel, editorId?: string, backupId?: string): Promise<void>;
reloadNotebook(mainthreadTextModel: NotebookTextModel): Promise<void>;
resolveNotebookEditor(viewType: string, uri: URI, editorId: string): Promise<void>;
executeNotebookByAttachedKernel(viewType: string, uri: URI, token: CancellationToken): Promise<void>;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册