From 7e49c5f7f158634cc64a18ceaa5727e163e35997 Mon Sep 17 00:00:00 2001 From: Jonah Iden Date: Mon, 11 Mar 2024 11:07:19 +0100 Subject: [PATCH 1/7] only initialize notebbok cell editor when in viewport Signed-off-by: Jonah Iden --- packages/notebook/src/browser/view/notebook-cell-editor.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/notebook/src/browser/view/notebook-cell-editor.tsx b/packages/notebook/src/browser/view/notebook-cell-editor.tsx index 1ad807a14cfb3..d6ccd9d581dd7 100644 --- a/packages/notebook/src/browser/view/notebook-cell-editor.tsx +++ b/packages/notebook/src/browser/view/notebook-cell-editor.tsx @@ -116,7 +116,7 @@ export class CellEditor extends React.Component { override render(): React.ReactNode { return
this.setContainer(container)} style={{ height: this.editor ? undefined : this.estimateHeight() }}> -
; + ; } } From 25ef1894503fd4b45db60e8b74d0ababfa87cfa8 Mon Sep 17 00:00:00 2001 From: Jonah Iden Date: Wed, 13 Mar 2024 14:19:18 +0100 Subject: [PATCH 2/7] optimzied notebook loading time by bulk creating notebook cell editor text models Signed-off-by: Jonah Iden --- .../src/browser/notebook-frontend-module.ts | 4 +- .../notebook-monaco-text-model-service.ts | 45 +++++++++++++++++++ .../src/browser/service/notebook-service.ts | 9 +++- .../browser/view-model/notebook-cell-model.ts | 5 ++- .../src/main/browser/documents-main.ts | 4 ++ .../src/main/browser/main-context.ts | 8 ++-- .../notebooks/notebook-documents-main.ts | 22 ++++++--- .../src/plugin/notebook/notebooks.ts | 13 +++++- 8 files changed, 96 insertions(+), 14 deletions(-) create mode 100644 packages/notebook/src/browser/service/notebook-monaco-text-model-service.ts diff --git a/packages/notebook/src/browser/notebook-frontend-module.ts b/packages/notebook/src/browser/notebook-frontend-module.ts index cb6814b219bd6..3278120259ccb 100644 --- a/packages/notebook/src/browser/notebook-frontend-module.ts +++ b/packages/notebook/src/browser/notebook-frontend-module.ts @@ -41,7 +41,7 @@ import { NotebookEditorWidgetService } from './service/notebook-editor-widget-se import { NotebookRendererMessagingService } from './service/notebook-renderer-messaging-service'; import { NotebookColorContribution } from './contributions/notebook-color-contribution'; -export default new ContainerModule(bind => { +export default new ContainerModule((bind, unbind, isBound, rebind) => { bind(NotebookColorContribution).toSelf().inSingletonScope(); bind(ColorContribution).toService(NotebookColorContribution); @@ -86,4 +86,6 @@ export default new ContainerModule(bind => { bind(NotebookCellModelFactory).toFactory(ctx => (props: NotebookCellModelProps) => createNotebookCellModelContainer(ctx.container, props).get(NotebookCellModel) ); + + rebind(MonacoTextModelService).to(NotebookMonacoTextModelService).inSingletonScope(); }); diff --git a/packages/notebook/src/browser/service/notebook-monaco-text-model-service.ts b/packages/notebook/src/browser/service/notebook-monaco-text-model-service.ts new file mode 100644 index 0000000000000..3d4a3314239f5 --- /dev/null +++ b/packages/notebook/src/browser/service/notebook-monaco-text-model-service.ts @@ -0,0 +1,45 @@ +// ***************************************************************************** +// Copyright (C) 2024 TypeFox and others. +// +// This program and the accompanying materials are made available under the +// terms of the Eclipse Public License v. 2.0 which is available at +// http://www.eclipse.org/legal/epl-2.0. +// +// This Source Code may also be made available under the following Secondary +// Licenses when the conditions for such availability set forth in the Eclipse +// Public License v. 2.0 are satisfied: GNU General Public License, version 2 +// with the GNU Classpath Exception which is available at +// https://www.gnu.org/software/classpath/license.html. +// +// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 +// ***************************************************************************** + +import { ReferenceCollection, URI, Reference, Event } from '@theia/core'; +import { injectable } from '@theia/core/shared/inversify'; +import { MonacoTextModelService } from '@theia/monaco/lib/browser/monaco-text-model-service'; +import { MonacoEditorModel } from '@theia/monaco/lib/browser/monaco-editor-model'; +import { NotebookModel } from '../view-model/notebook-model'; + +/** + * special service for creating monaco textmodels for notebook cells. + * Its for optimization purposes since there is alot of overhead otherwise with calling the backend to create a document for each cell and other smaller things. + */ +@injectable() +export class NotebookMonacoTextModelService extends MonacoTextModelService { + + protected readonly cellmodels = new ReferenceCollection( + uri => this.loadModel(new URI(uri)) + ); + + getOrCreateNotebookCellModelReference(uri: URI): Promise> { + return this.cellmodels.acquire(uri.toString()); + } + + async createTextModelsForNotebook(notebook: NotebookModel): Promise { + await Promise.all(notebook.cells.map(cell => this.getOrCreateNotebookCellModelReference(cell.uri))); + } + + get onDidCreateNotebookCellModel(): Event { + return this.cellmodels.onDidCreate; + } +} diff --git a/packages/notebook/src/browser/service/notebook-service.ts b/packages/notebook/src/browser/service/notebook-service.ts index 583dac957a0f5..ab5e0053acc12 100644 --- a/packages/notebook/src/browser/service/notebook-service.ts +++ b/packages/notebook/src/browser/service/notebook-service.ts @@ -23,6 +23,7 @@ import { FileService } from '@theia/filesystem/lib/browser/file-service'; import { MonacoTextModelService } from '@theia/monaco/lib/browser/monaco-text-model-service'; import { NotebookCellModel, NotebookCellModelFactory, NotebookCellModelProps } from '../view-model/notebook-cell-model'; import { Deferred } from '@theia/core/lib/common/promise-util'; +import { NotebookMonacoTextModelService } from './notebook-monaco-text-model-service'; export const NotebookProvider = Symbol('notebook provider'); @@ -52,6 +53,9 @@ export class NotebookService implements Disposable { @inject(NotebookCellModelFactory) protected notebookCellModelFactory: (props: NotebookCellModelProps) => NotebookCellModel; + @inject(MonacoTextModelService) + protected textModelService: NotebookMonacoTextModelService; + protected willUseNotebookSerializerEmitter = new Emitter(); readonly onWillUseNotebookSerializer = this.willUseNotebookSerializerEmitter.event; @@ -102,6 +106,7 @@ export class NotebookService implements Disposable { } async createNotebookModel(data: NotebookData, viewType: string, resource: Resource): Promise { + const start = Date.now(); const serializer = this.notebookProviders.get(viewType)?.serializer; if (!serializer) { throw new Error('no notebook serializer for ' + viewType); @@ -111,8 +116,10 @@ export class NotebookService implements Disposable { this.notebookModels.set(resource.uri.toString(), model); // Resolve cell text models right after creating the notebook model // This ensures that all text models are available in the plugin host - await Promise.all(model.cells.map(e => e.resolveTextModel())); + // model.cells.map(e => e.resolveTextModel()); + this.textModelService.createTextModelsForNotebook(model); this.didAddNotebookDocumentEmitter.fire(model); + console.log(`Created notebook model in ${Date.now() - start}ms`); return model; } diff --git a/packages/notebook/src/browser/view-model/notebook-cell-model.ts b/packages/notebook/src/browser/view-model/notebook-cell-model.ts index 015295117a3ff..f8e300708d6fd 100644 --- a/packages/notebook/src/browser/view-model/notebook-cell-model.ts +++ b/packages/notebook/src/browser/view-model/notebook-cell-model.ts @@ -28,6 +28,7 @@ import { } from '../../common'; import { NotebookCellOutputsSplice } from '../notebook-types'; import { NotebookCellOutputModel } from './notebook-cell-output-model'; +import { NotebookMonacoTextModelService } from '../service/notebook-monaco-text-model-service'; export const NotebookCellModelFactory = Symbol('NotebookModelFactory'); export type NotebookCellModelFactory = (props: NotebookCellModelProps) => NotebookCellModel; @@ -103,7 +104,7 @@ export class NotebookCellModel implements NotebookCell, Disposable { @inject(NotebookCellModelProps) protected readonly props: NotebookCellModelProps; @inject(MonacoTextModelService) - protected readonly textModelService: MonacoTextModelService; + protected readonly textModelService: NotebookMonacoTextModelService; get outputs(): NotebookCellOutputModel[] { return this._outputs; @@ -277,7 +278,7 @@ export class NotebookCellModel implements NotebookCell, Disposable { return this.textModel; } - const ref = await this.textModelService.createModelReference(this.uri); + const ref = await this.textModelService.getOrCreateNotebookCellModelReference(this.uri); this.textModel = ref.object; this.textModel.onDidChangeContent(e => { this.props.source = e.model.getText(); diff --git a/packages/plugin-ext/src/main/browser/documents-main.ts b/packages/plugin-ext/src/main/browser/documents-main.ts index 798738759d998..deed64a60d2d5 100644 --- a/packages/plugin-ext/src/main/browser/documents-main.ts +++ b/packages/plugin-ext/src/main/browser/documents-main.ts @@ -32,6 +32,7 @@ import { dispose } from '../../common/disposable-util'; import { MonacoLanguages } from '@theia/monaco/lib/browser/monaco-languages'; import * as monaco from '@theia/monaco-editor-core'; import { TextDocumentChangeReason } from '../../plugin/types-impl'; +import { NotebookDocumentsMainImpl } from './notebooks/notebook-documents-main'; /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. @@ -90,6 +91,7 @@ export class DocumentsMainImpl implements DocumentsMain, Disposable { constructor( editorsAndDocuments: EditorsAndDocumentsMain, + notebookDocuments: NotebookDocumentsMainImpl, private readonly modelService: EditorModelService, rpc: RPCProtocol, private editorManager: EditorManager, @@ -105,6 +107,8 @@ export class DocumentsMainImpl implements DocumentsMain, Disposable { this.toDispose.push(editorsAndDocuments.onDocumentRemove(documents => documents.forEach(this.onModelRemoved, this))); this.toDispose.push(modelService.onModelModeChanged(this.onModelChanged, this)); + this.toDispose.push(notebookDocuments.onDidAddNotebookCellModel(this.onModelAdded, this)); + this.toDispose.push(modelService.onModelSaved(m => { this.proxy.$acceptModelSaved(m.textEditorModel.uri); })); diff --git a/packages/plugin-ext/src/main/browser/main-context.ts b/packages/plugin-ext/src/main/browser/main-context.ts index 95cef28663854..31cf2f19aba1e 100644 --- a/packages/plugin-ext/src/main/browser/main-context.ts +++ b/packages/plugin-ext/src/main/browser/main-context.ts @@ -91,21 +91,23 @@ export function setUpPluginApi(rpc: RPCProtocol, container: interfaces.Container const editorsAndDocuments = new EditorsAndDocumentsMain(rpc, container); + const notebookDocumentsMain = new NotebookDocumentsMainImpl(rpc, container); + rpc.set(PLUGIN_RPC_CONTEXT.NOTEBOOK_DOCUMENTS_MAIN, notebookDocumentsMain); + const modelService = container.get(EditorModelService); const editorManager = container.get(EditorManager); const openerService = container.get(OpenerService); const shell = container.get(ApplicationShell); const untitledResourceResolver = container.get(UntitledResourceResolver); const languageService = container.get(MonacoLanguages); - const documentsMain = new DocumentsMainImpl(editorsAndDocuments, modelService, rpc, editorManager, openerService, shell, untitledResourceResolver, languageService); + const documentsMain = new DocumentsMainImpl(editorsAndDocuments, notebookDocumentsMain, modelService, rpc, + editorManager, openerService, shell, untitledResourceResolver, languageService); rpc.set(PLUGIN_RPC_CONTEXT.DOCUMENTS_MAIN, documentsMain); rpc.set(PLUGIN_RPC_CONTEXT.NOTEBOOKS_MAIN, new NotebooksMainImpl(rpc, container, commandRegistryMain)); rpc.set(PLUGIN_RPC_CONTEXT.NOTEBOOK_RENDERERS_MAIN, new NotebookRenderersMainImpl(rpc, container)); const notebookEditorsMain = new NotebookEditorsMainImpl(rpc, container); rpc.set(PLUGIN_RPC_CONTEXT.NOTEBOOK_EDITORS_MAIN, notebookEditorsMain); - const notebookDocumentsMain = new NotebookDocumentsMainImpl(rpc, container); - rpc.set(PLUGIN_RPC_CONTEXT.NOTEBOOK_DOCUMENTS_MAIN, notebookDocumentsMain); rpc.set(PLUGIN_RPC_CONTEXT.NOTEBOOK_DOCUMENTS_AND_EDITORS_MAIN, new NotebooksAndEditorsMain(rpc, container, notebookDocumentsMain, notebookEditorsMain)); rpc.set(PLUGIN_RPC_CONTEXT.NOTEBOOK_KERNELS_MAIN, new NotebookKernelsMainImpl(rpc, container)); diff --git a/packages/plugin-ext/src/main/browser/notebooks/notebook-documents-main.ts b/packages/plugin-ext/src/main/browser/notebooks/notebook-documents-main.ts index 04fe85dbcaacc..a9d7eb6254537 100644 --- a/packages/plugin-ext/src/main/browser/notebooks/notebook-documents-main.ts +++ b/packages/plugin-ext/src/main/browser/notebooks/notebook-documents-main.ts @@ -14,28 +14,33 @@ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 // ***************************************************************************** -import { DisposableCollection } from '@theia/core'; +import { DisposableCollection, Event } from '@theia/core'; import { URI, UriComponents } from '@theia/core/lib/common/uri'; import { interfaces } from '@theia/core/shared/inversify'; +import { MonacoTextModelService } from '@theia/monaco/lib/browser/monaco-text-model-service'; import { NotebookModelResolverService } from '@theia/notebook/lib/browser'; import { NotebookModel } from '@theia/notebook/lib/browser/view-model/notebook-model'; import { NotebookCellsChangeType } from '@theia/notebook/lib/common'; +import { NotebookMonacoTextModelService } from '@theia/notebook/lib/browser/service/notebook-monaco-text-model-service'; import { MAIN_RPC_CONTEXT, NotebookCellsChangedEventDto, NotebookDataDto, NotebookDocumentsExt, NotebookDocumentsMain } from '../../../common'; import { RPCProtocol } from '../../../common/rpc-protocol'; import { NotebookDto } from './notebook-dto'; +import { MonacoEditorModel } from '@theia/monaco/lib/browser/monaco-editor-model'; export class NotebookDocumentsMainImpl implements NotebookDocumentsMain { - private readonly disposables = new DisposableCollection(); + protected readonly disposables = new DisposableCollection(); - private readonly proxy: NotebookDocumentsExt; - private readonly documentEventListenersMapping = new Map(); + protected readonly proxy: NotebookDocumentsExt; + protected readonly documentEventListenersMapping = new Map(); - private readonly notebookModelResolverService: NotebookModelResolverService; + protected readonly notebookModelResolverService: NotebookModelResolverService; + + protected notebookMonacoTextModelService: NotebookMonacoTextModelService; constructor( rpc: RPCProtocol, - container: interfaces.Container + container: interfaces.Container, ) { this.proxy = rpc.getProxy(MAIN_RPC_CONTEXT.NOTEBOOK_DOCUMENTS_EXT); this.notebookModelResolverService = container.get(NotebookModelResolverService); @@ -44,6 +49,11 @@ export class NotebookDocumentsMainImpl implements NotebookDocumentsMain { this.disposables.push(this.notebookModelResolverService.onDidChangeDirty(model => this.proxy.$acceptDirtyStateChanged(model.uri.toComponents(), model.isDirty()))); this.disposables.push(this.notebookModelResolverService.onDidSaveNotebook(e => this.proxy.$acceptModelSaved(e))); + this.notebookMonacoTextModelService = container.get(MonacoTextModelService) as NotebookMonacoTextModelService; + } + + get onDidAddNotebookCellModel(): Event { + return this.notebookMonacoTextModelService.onDidCreateNotebookCellModel; } dispose(): void { diff --git a/packages/plugin-ext/src/plugin/notebook/notebooks.ts b/packages/plugin-ext/src/plugin/notebook/notebooks.ts index 01034fd711fe8..8556414434f66 100644 --- a/packages/plugin-ext/src/plugin/notebook/notebooks.ts +++ b/packages/plugin-ext/src/plugin/notebook/notebooks.ts @@ -76,7 +76,7 @@ export class NotebooksExtImpl implements NotebooksExt { rpc: RPCProtocol, commands: CommandRegistryExt, private textDocumentsAndEditors: EditorsAndDocumentsExtImpl, - private textDocuments: DocumentsExtImpl + private textDocuments: DocumentsExtImpl, ) { this.notebookProxy = rpc.getProxy(PLUGIN_RPC_CONTEXT.NOTEBOOKS_MAIN); this.notebookDocumentsProxy = rpc.getProxy(PLUGIN_RPC_CONTEXT.NOTEBOOK_DOCUMENTS_MAIN); @@ -236,6 +236,17 @@ export class NotebooksExtImpl implements NotebooksExt { this.documents.get(uri.toString())?.dispose(); this.documents.set(uri.toString(), document); + this.textDocumentsAndEditors.$acceptEditorsAndDocumentsDelta({ + addedDocuments: modelData.cells.map(cell => ({ + uri: cell.uri, + versionId: 1, + lines: cell.source, + EOL: cell.eol, + modeId: '', + isDirty: false + })) + }); + this.onDidOpenNotebookDocumentEmitter.fire(document.apiNotebook); } } From 0544deb99dbddc48883b462ba8fcaac25576bed1 Mon Sep 17 00:00:00 2001 From: Jonah Iden Date: Wed, 13 Mar 2024 14:29:57 +0100 Subject: [PATCH 3/7] remove measurement Signed-off-by: Jonah Iden --- packages/notebook/src/browser/service/notebook-service.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/notebook/src/browser/service/notebook-service.ts b/packages/notebook/src/browser/service/notebook-service.ts index ab5e0053acc12..c3940dd3fe9a2 100644 --- a/packages/notebook/src/browser/service/notebook-service.ts +++ b/packages/notebook/src/browser/service/notebook-service.ts @@ -106,7 +106,6 @@ export class NotebookService implements Disposable { } async createNotebookModel(data: NotebookData, viewType: string, resource: Resource): Promise { - const start = Date.now(); const serializer = this.notebookProviders.get(viewType)?.serializer; if (!serializer) { throw new Error('no notebook serializer for ' + viewType); @@ -116,10 +115,8 @@ export class NotebookService implements Disposable { this.notebookModels.set(resource.uri.toString(), model); // Resolve cell text models right after creating the notebook model // This ensures that all text models are available in the plugin host - // model.cells.map(e => e.resolveTextModel()); this.textModelService.createTextModelsForNotebook(model); this.didAddNotebookDocumentEmitter.fire(model); - console.log(`Created notebook model in ${Date.now() - start}ms`); return model; } From 5c0387a5bd6ba83ad636c9176272fc5b8e7d6b21 Mon Sep 17 00:00:00 2001 From: Jonah Iden Date: Thu, 14 Mar 2024 13:25:50 +0100 Subject: [PATCH 4/7] add document for cell when creating new one Signed-off-by: Jonah Iden --- .../src/plugin/notebook/notebook-document.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/plugin-ext/src/plugin/notebook/notebook-document.ts b/packages/plugin-ext/src/plugin/notebook/notebook-document.ts index 66b63479be6fb..6dabd9fd75be1 100644 --- a/packages/plugin-ext/src/plugin/notebook/notebook-document.ts +++ b/packages/plugin-ext/src/plugin/notebook/notebook-document.ts @@ -357,6 +357,18 @@ export class NotebookDocument implements Disposable { const extCell = new Cell(this, this.editorsAndDocuments, cell); if (!initialization) { addedCellDocuments.push(Cell.asModelAddData(this.apiNotebook, cell)); + this.editorsAndDocuments.$acceptEditorsAndDocumentsDelta({ + addedDocuments: [ + { + uri: cell.uri, + versionId: 1, + lines: cell.source, + EOL: cell.eol, + modeId: '', + isDirty: false + } + ] + }); } return extCell; }); From 19d55c550798c4cef41c335ad062d8bffc202232 Mon Sep 17 00:00:00 2001 From: Jonah Iden Date: Tue, 19 Mar 2024 09:28:13 +0100 Subject: [PATCH 5/7] review changes --- .../src/main/browser/notebooks/notebook-documents-main.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/plugin-ext/src/main/browser/notebooks/notebook-documents-main.ts b/packages/plugin-ext/src/main/browser/notebooks/notebook-documents-main.ts index a9d7eb6254537..2cc4f9d297eea 100644 --- a/packages/plugin-ext/src/main/browser/notebooks/notebook-documents-main.ts +++ b/packages/plugin-ext/src/main/browser/notebooks/notebook-documents-main.ts @@ -40,7 +40,7 @@ export class NotebookDocumentsMainImpl implements NotebookDocumentsMain { constructor( rpc: RPCProtocol, - container: interfaces.Container, + container: interfaces.Container ) { this.proxy = rpc.getProxy(MAIN_RPC_CONTEXT.NOTEBOOK_DOCUMENTS_EXT); this.notebookModelResolverService = container.get(NotebookModelResolverService); From 680b7849ac57065133ed1e3f3e386498bbd2dd4d Mon Sep 17 00:00:00 2001 From: Jonah Iden Date: Tue, 19 Mar 2024 12:02:12 +0100 Subject: [PATCH 6/7] rebase build fixe Signed-off-by: Jonah Iden --- packages/notebook/src/browser/notebook-frontend-module.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/notebook/src/browser/notebook-frontend-module.ts b/packages/notebook/src/browser/notebook-frontend-module.ts index 3278120259ccb..c023cdc366f53 100644 --- a/packages/notebook/src/browser/notebook-frontend-module.ts +++ b/packages/notebook/src/browser/notebook-frontend-module.ts @@ -40,6 +40,8 @@ import { NotebookKernelHistoryService } from './service/notebook-kernel-history- import { NotebookEditorWidgetService } from './service/notebook-editor-widget-service'; import { NotebookRendererMessagingService } from './service/notebook-renderer-messaging-service'; import { NotebookColorContribution } from './contributions/notebook-color-contribution'; +import { MonacoTextModelService } from '@theia/monaco/lib/browser/monaco-text-model-service'; +import { NotebookMonacoTextModelService } from './service/notebook-monaco-text-model-service'; export default new ContainerModule((bind, unbind, isBound, rebind) => { bind(NotebookColorContribution).toSelf().inSingletonScope(); From 0544a1ab33231450861a217bd5fed195b5ca5a54 Mon Sep 17 00:00:00 2001 From: Jonah Iden Date: Wed, 27 Mar 2024 14:09:37 +0100 Subject: [PATCH 7/7] create unmaged models for monacto text model service Signed-off-by: Jonah Iden --- .../monaco/src/browser/monaco-text-model-service.ts | 10 +++++++++- .../notebook/src/browser/notebook-frontend-module.ts | 3 +-- .../service/notebook-monaco-text-model-service.ts | 9 ++++++--- .../notebook/src/browser/service/notebook-service.ts | 6 +----- .../src/browser/view-model/notebook-cell-model.ts | 6 +++--- .../main/browser/notebooks/notebook-documents-main.ts | 3 +-- 6 files changed, 21 insertions(+), 16 deletions(-) diff --git a/packages/monaco/src/browser/monaco-text-model-service.ts b/packages/monaco/src/browser/monaco-text-model-service.ts index bd1ecf07c5a97..318de5575ba9e 100644 --- a/packages/monaco/src/browser/monaco-text-model-service.ts +++ b/packages/monaco/src/browser/monaco-text-model-service.ts @@ -109,7 +109,15 @@ export class MonacoTextModelService implements ITextModelService { return this._models.acquire(raw.toString()); } - protected async loadModel(uri: URI): Promise { + /** + * creates a model which is not saved by the model service. + * this will therefore also not be created on backend side. + */ + createUnmangedModel(raw: monaco.Uri | URI): Promise { + return this.loadModel(new URI(raw.toString())); + } + + async loadModel(uri: URI): Promise { await this.editorPreferences.ready; const resource = await this.resourceProvider(uri); const model = await (await this.createModel(resource)).load(); diff --git a/packages/notebook/src/browser/notebook-frontend-module.ts b/packages/notebook/src/browser/notebook-frontend-module.ts index c023cdc366f53..f74e129578d67 100644 --- a/packages/notebook/src/browser/notebook-frontend-module.ts +++ b/packages/notebook/src/browser/notebook-frontend-module.ts @@ -40,7 +40,6 @@ import { NotebookKernelHistoryService } from './service/notebook-kernel-history- import { NotebookEditorWidgetService } from './service/notebook-editor-widget-service'; import { NotebookRendererMessagingService } from './service/notebook-renderer-messaging-service'; import { NotebookColorContribution } from './contributions/notebook-color-contribution'; -import { MonacoTextModelService } from '@theia/monaco/lib/browser/monaco-text-model-service'; import { NotebookMonacoTextModelService } from './service/notebook-monaco-text-model-service'; export default new ContainerModule((bind, unbind, isBound, rebind) => { @@ -89,5 +88,5 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => { createNotebookCellModelContainer(ctx.container, props).get(NotebookCellModel) ); - rebind(MonacoTextModelService).to(NotebookMonacoTextModelService).inSingletonScope(); + bind(NotebookMonacoTextModelService).toSelf().inSingletonScope(); }); diff --git a/packages/notebook/src/browser/service/notebook-monaco-text-model-service.ts b/packages/notebook/src/browser/service/notebook-monaco-text-model-service.ts index 3d4a3314239f5..6b0c5e8576206 100644 --- a/packages/notebook/src/browser/service/notebook-monaco-text-model-service.ts +++ b/packages/notebook/src/browser/service/notebook-monaco-text-model-service.ts @@ -15,7 +15,7 @@ // ***************************************************************************** import { ReferenceCollection, URI, Reference, Event } from '@theia/core'; -import { injectable } from '@theia/core/shared/inversify'; +import { inject, injectable } from '@theia/core/shared/inversify'; import { MonacoTextModelService } from '@theia/monaco/lib/browser/monaco-text-model-service'; import { MonacoEditorModel } from '@theia/monaco/lib/browser/monaco-editor-model'; import { NotebookModel } from '../view-model/notebook-model'; @@ -25,10 +25,13 @@ import { NotebookModel } from '../view-model/notebook-model'; * Its for optimization purposes since there is alot of overhead otherwise with calling the backend to create a document for each cell and other smaller things. */ @injectable() -export class NotebookMonacoTextModelService extends MonacoTextModelService { +export class NotebookMonacoTextModelService { + + @inject(MonacoTextModelService) + protected readonly monacoTextModelService: MonacoTextModelService; protected readonly cellmodels = new ReferenceCollection( - uri => this.loadModel(new URI(uri)) + uri => this.monacoTextModelService.createUnmangedModel(new URI(uri)) ); getOrCreateNotebookCellModelReference(uri: URI): Promise> { diff --git a/packages/notebook/src/browser/service/notebook-service.ts b/packages/notebook/src/browser/service/notebook-service.ts index c3940dd3fe9a2..85d228b050ce9 100644 --- a/packages/notebook/src/browser/service/notebook-service.ts +++ b/packages/notebook/src/browser/service/notebook-service.ts @@ -20,7 +20,6 @@ import { BinaryBuffer } from '@theia/core/lib/common/buffer'; import { NotebookData, TransientOptions } from '../../common'; import { NotebookModel, NotebookModelFactory, NotebookModelProps } from '../view-model/notebook-model'; import { FileService } from '@theia/filesystem/lib/browser/file-service'; -import { MonacoTextModelService } from '@theia/monaco/lib/browser/monaco-text-model-service'; import { NotebookCellModel, NotebookCellModelFactory, NotebookCellModelProps } from '../view-model/notebook-cell-model'; import { Deferred } from '@theia/core/lib/common/promise-util'; import { NotebookMonacoTextModelService } from './notebook-monaco-text-model-service'; @@ -44,16 +43,13 @@ export class NotebookService implements Disposable { @inject(FileService) protected fileService: FileService; - @inject(MonacoTextModelService) - protected modelService: MonacoTextModelService; - @inject(NotebookModelFactory) protected notebookModelFactory: (props: NotebookModelProps) => NotebookModel; @inject(NotebookCellModelFactory) protected notebookCellModelFactory: (props: NotebookCellModelProps) => NotebookCellModel; - @inject(MonacoTextModelService) + @inject(NotebookMonacoTextModelService) protected textModelService: NotebookMonacoTextModelService; protected willUseNotebookSerializerEmitter = new Emitter(); diff --git a/packages/notebook/src/browser/view-model/notebook-cell-model.ts b/packages/notebook/src/browser/view-model/notebook-cell-model.ts index f8e300708d6fd..98f79fa3ec0fb 100644 --- a/packages/notebook/src/browser/view-model/notebook-cell-model.ts +++ b/packages/notebook/src/browser/view-model/notebook-cell-model.ts @@ -21,14 +21,13 @@ import { Disposable, DisposableCollection, Emitter, Event, URI } from '@theia/core'; import { inject, injectable, interfaces, postConstruct } from '@theia/core/shared/inversify'; import { MonacoEditorModel } from '@theia/monaco/lib/browser/monaco-editor-model'; -import { MonacoTextModelService } from '@theia/monaco/lib/browser/monaco-text-model-service'; import { CellKind, NotebookCellCollapseState, NotebookCellInternalMetadata, NotebookCellMetadata, CellOutput, CellData, CellOutputItem } from '../../common'; import { NotebookCellOutputsSplice } from '../notebook-types'; -import { NotebookCellOutputModel } from './notebook-cell-output-model'; import { NotebookMonacoTextModelService } from '../service/notebook-monaco-text-model-service'; +import { NotebookCellOutputModel } from './notebook-cell-output-model'; export const NotebookCellModelFactory = Symbol('NotebookModelFactory'); export type NotebookCellModelFactory = (props: NotebookCellModelProps) => NotebookCellModel; @@ -103,7 +102,8 @@ export class NotebookCellModel implements NotebookCell, Disposable { @inject(NotebookCellModelProps) protected readonly props: NotebookCellModelProps; - @inject(MonacoTextModelService) + + @inject(NotebookMonacoTextModelService) protected readonly textModelService: NotebookMonacoTextModelService; get outputs(): NotebookCellOutputModel[] { diff --git a/packages/plugin-ext/src/main/browser/notebooks/notebook-documents-main.ts b/packages/plugin-ext/src/main/browser/notebooks/notebook-documents-main.ts index 2cc4f9d297eea..89a32253f1788 100644 --- a/packages/plugin-ext/src/main/browser/notebooks/notebook-documents-main.ts +++ b/packages/plugin-ext/src/main/browser/notebooks/notebook-documents-main.ts @@ -17,7 +17,6 @@ import { DisposableCollection, Event } from '@theia/core'; import { URI, UriComponents } from '@theia/core/lib/common/uri'; import { interfaces } from '@theia/core/shared/inversify'; -import { MonacoTextModelService } from '@theia/monaco/lib/browser/monaco-text-model-service'; import { NotebookModelResolverService } from '@theia/notebook/lib/browser'; import { NotebookModel } from '@theia/notebook/lib/browser/view-model/notebook-model'; import { NotebookCellsChangeType } from '@theia/notebook/lib/common'; @@ -49,7 +48,7 @@ export class NotebookDocumentsMainImpl implements NotebookDocumentsMain { this.disposables.push(this.notebookModelResolverService.onDidChangeDirty(model => this.proxy.$acceptDirtyStateChanged(model.uri.toComponents(), model.isDirty()))); this.disposables.push(this.notebookModelResolverService.onDidSaveNotebook(e => this.proxy.$acceptModelSaved(e))); - this.notebookMonacoTextModelService = container.get(MonacoTextModelService) as NotebookMonacoTextModelService; + this.notebookMonacoTextModelService = container.get(NotebookMonacoTextModelService) as NotebookMonacoTextModelService; } get onDidAddNotebookCellModel(): Event {