@theia/notebook 1.53.0-next.4 → 1.53.0-next.55

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/README.md +30 -30
  2. package/lib/browser/contributions/cell-operations.d.ts.map +1 -1
  3. package/lib/browser/contributions/cell-operations.js +8 -1
  4. package/lib/browser/contributions/cell-operations.js.map +1 -1
  5. package/lib/browser/contributions/notebook-actions-contribution.d.ts +1 -0
  6. package/lib/browser/contributions/notebook-actions-contribution.d.ts.map +1 -1
  7. package/lib/browser/contributions/notebook-actions-contribution.js +31 -6
  8. package/lib/browser/contributions/notebook-actions-contribution.js.map +1 -1
  9. package/lib/browser/contributions/notebook-cell-actions-contribution.d.ts +4 -0
  10. package/lib/browser/contributions/notebook-cell-actions-contribution.d.ts.map +1 -1
  11. package/lib/browser/contributions/notebook-cell-actions-contribution.js +49 -12
  12. package/lib/browser/contributions/notebook-cell-actions-contribution.js.map +1 -1
  13. package/lib/browser/contributions/notebook-status-bar-contribution.d.ts +14 -0
  14. package/lib/browser/contributions/notebook-status-bar-contribution.d.ts.map +1 -0
  15. package/lib/browser/contributions/notebook-status-bar-contribution.js +75 -0
  16. package/lib/browser/contributions/notebook-status-bar-contribution.js.map +1 -0
  17. package/lib/browser/notebook-editor-widget.d.ts.map +1 -1
  18. package/lib/browser/notebook-editor-widget.js +3 -5
  19. package/lib/browser/notebook-editor-widget.js.map +1 -1
  20. package/lib/browser/notebook-frontend-module.d.ts.map +1 -1
  21. package/lib/browser/notebook-frontend-module.js +3 -0
  22. package/lib/browser/notebook-frontend-module.js.map +1 -1
  23. package/lib/browser/notebook-open-handler.d.ts +3 -2
  24. package/lib/browser/notebook-open-handler.d.ts.map +1 -1
  25. package/lib/browser/notebook-open-handler.js +12 -5
  26. package/lib/browser/notebook-open-handler.js.map +1 -1
  27. package/lib/browser/service/notebook-options.d.ts +1 -0
  28. package/lib/browser/service/notebook-options.d.ts.map +1 -1
  29. package/lib/browser/service/notebook-options.js +1 -0
  30. package/lib/browser/service/notebook-options.js.map +1 -1
  31. package/lib/browser/service/notebook-service.d.ts +1 -0
  32. package/lib/browser/service/notebook-service.d.ts.map +1 -1
  33. package/lib/browser/service/notebook-service.js +7 -0
  34. package/lib/browser/service/notebook-service.js.map +1 -1
  35. package/lib/browser/view/notebook-cell-editor.d.ts +1 -0
  36. package/lib/browser/view/notebook-cell-editor.d.ts.map +1 -1
  37. package/lib/browser/view/notebook-cell-editor.js +30 -16
  38. package/lib/browser/view/notebook-cell-editor.js.map +1 -1
  39. package/lib/browser/view/notebook-cell-list-view.d.ts +7 -4
  40. package/lib/browser/view/notebook-cell-list-view.d.ts.map +1 -1
  41. package/lib/browser/view/notebook-cell-list-view.js +39 -29
  42. package/lib/browser/view/notebook-cell-list-view.js.map +1 -1
  43. package/lib/browser/view-model/notebook-cell-model.d.ts +3 -0
  44. package/lib/browser/view-model/notebook-cell-model.d.ts.map +1 -1
  45. package/lib/browser/view-model/notebook-cell-model.js +5 -0
  46. package/lib/browser/view-model/notebook-cell-model.js.map +1 -1
  47. package/package.json +8 -8
  48. package/src/browser/contributions/cell-operations.ts +44 -39
  49. package/src/browser/contributions/notebook-actions-contribution.ts +379 -351
  50. package/src/browser/contributions/notebook-cell-actions-contribution.ts +525 -485
  51. package/src/browser/contributions/notebook-color-contribution.ts +268 -268
  52. package/src/browser/contributions/notebook-context-keys.ts +113 -113
  53. package/src/browser/contributions/notebook-label-provider-contribution.ts +85 -85
  54. package/src/browser/contributions/notebook-outline-contribution.ts +114 -114
  55. package/src/browser/contributions/notebook-output-action-contribution.ts +82 -82
  56. package/src/browser/contributions/notebook-preferences.ts +92 -92
  57. package/src/browser/contributions/notebook-status-bar-contribution.ts +77 -0
  58. package/src/browser/contributions/notebook-undo-redo-handler.ts +41 -41
  59. package/src/browser/index.ts +27 -27
  60. package/src/browser/notebook-cell-resource-resolver.ts +130 -130
  61. package/src/browser/notebook-editor-widget-factory.ts +82 -82
  62. package/src/browser/notebook-editor-widget.tsx +330 -331
  63. package/src/browser/notebook-frontend-module.ts +119 -115
  64. package/src/browser/notebook-open-handler.ts +120 -114
  65. package/src/browser/notebook-output-utils.ts +119 -119
  66. package/src/browser/notebook-renderer-registry.ts +85 -85
  67. package/src/browser/notebook-type-registry.ts +54 -54
  68. package/src/browser/notebook-types.ts +186 -186
  69. package/src/browser/renderers/cell-output-webview.ts +33 -33
  70. package/src/browser/service/notebook-clipboard-service.ts +43 -43
  71. package/src/browser/service/notebook-context-manager.ts +162 -162
  72. package/src/browser/service/notebook-editor-widget-service.ts +101 -101
  73. package/src/browser/service/notebook-execution-service.ts +139 -139
  74. package/src/browser/service/notebook-execution-state-service.ts +311 -311
  75. package/src/browser/service/notebook-kernel-history-service.ts +124 -124
  76. package/src/browser/service/notebook-kernel-quick-pick-service.ts +479 -479
  77. package/src/browser/service/notebook-kernel-service.ts +357 -357
  78. package/src/browser/service/notebook-model-resolver-service.ts +160 -160
  79. package/src/browser/service/notebook-monaco-text-model-service.ts +48 -48
  80. package/src/browser/service/notebook-options.ts +155 -154
  81. package/src/browser/service/notebook-renderer-messaging-service.ts +121 -121
  82. package/src/browser/service/notebook-service.ts +215 -209
  83. package/src/browser/style/index.css +483 -467
  84. package/src/browser/view/notebook-cell-editor.tsx +263 -247
  85. package/src/browser/view/notebook-cell-list-view.tsx +279 -259
  86. package/src/browser/view/notebook-cell-toolbar-factory.tsx +102 -102
  87. package/src/browser/view/notebook-cell-toolbar.tsx +74 -74
  88. package/src/browser/view/notebook-code-cell-view.tsx +350 -350
  89. package/src/browser/view/notebook-find-widget.tsx +335 -335
  90. package/src/browser/view/notebook-main-toolbar.tsx +235 -235
  91. package/src/browser/view/notebook-markdown-cell-view.tsx +208 -208
  92. package/src/browser/view/notebook-viewport-service.ts +61 -61
  93. package/src/browser/view-model/notebook-cell-model.ts +473 -466
  94. package/src/browser/view-model/notebook-cell-output-model.ts +100 -100
  95. package/src/browser/view-model/notebook-model.ts +550 -550
  96. package/src/common/index.ts +18 -18
  97. package/src/common/notebook-common.ts +337 -337
  98. package/src/common/notebook-protocol.ts +35 -35
  99. package/src/common/notebook-range.ts +30 -30
@@ -1,160 +1,160 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2023 TypeFox and others.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import { Emitter, Resource, ResourceProvider, UNTITLED_SCHEME, URI } from '@theia/core';
18
- import { inject, injectable } from '@theia/core/shared/inversify';
19
- import { UriComponents } from '@theia/core/lib/common/uri';
20
- import { FileService } from '@theia/filesystem/lib/browser/file-service';
21
- import { NotebookData } from '../../common';
22
- import { NotebookModel } from '../view-model/notebook-model';
23
- import { NotebookService } from './notebook-service';
24
- import { NotebookTypeRegistry } from '../notebook-type-registry';
25
- import { NotebookFileSelector } from '../../common/notebook-protocol';
26
- import { match } from '@theia/core/lib/common/glob';
27
-
28
- export interface UntitledResource {
29
- untitledResource: URI | undefined
30
- }
31
-
32
- @injectable()
33
- export class NotebookModelResolverService {
34
-
35
- @inject(FileService)
36
- protected fileService: FileService;
37
-
38
- @inject(ResourceProvider)
39
- protected resourceProvider: ResourceProvider;
40
-
41
- @inject(NotebookService)
42
- protected notebookService: NotebookService;
43
-
44
- @inject(NotebookTypeRegistry)
45
- protected notebookTypeRegistry: NotebookTypeRegistry;
46
-
47
- protected onDidChangeDirtyEmitter = new Emitter<NotebookModel>();
48
- readonly onDidChangeDirty = this.onDidChangeDirtyEmitter.event;
49
- protected onDidSaveNotebookEmitter = new Emitter<UriComponents>();
50
- readonly onDidSaveNotebook = this.onDidSaveNotebookEmitter.event;
51
-
52
- async resolve(resource: URI, viewType?: string): Promise<NotebookModel> {
53
- const existingModel = this.notebookService.getNotebookEditorModel(resource);
54
- if (!viewType) {
55
- if (existingModel) {
56
- return existingModel;
57
- } else {
58
- viewType = this.findViewTypeForResource(resource);
59
- }
60
- } else if (existingModel?.viewType === viewType) {
61
- return existingModel;
62
- }
63
-
64
- if (!viewType) {
65
- throw new Error(`Missing viewType for '${resource}'`);
66
- }
67
-
68
- const actualResource = await this.resourceProvider(resource);
69
- const notebookData = await this.resolveExistingNotebookData(actualResource, viewType!);
70
- const notebookModel = await this.notebookService.createNotebookModel(notebookData, viewType, actualResource);
71
-
72
- notebookModel.onDirtyChanged(() => this.onDidChangeDirtyEmitter.fire(notebookModel));
73
- notebookModel.onDidSaveNotebook(() => this.onDidSaveNotebookEmitter.fire(notebookModel.uri.toComponents()));
74
-
75
- return notebookModel;
76
- }
77
-
78
- async resolveUntitledResource(arg: UntitledResource, viewType: string): Promise<NotebookModel> {
79
- let resource: URI;
80
- // let hasAssociatedFilePath = false;
81
- arg = arg as UntitledResource;
82
- if (!arg.untitledResource) {
83
- const notebookTypeInfo = this.notebookTypeRegistry.notebookTypes.find(info => info.type === viewType);
84
- if (!notebookTypeInfo) {
85
- throw new Error('UNKNOWN view type: ' + viewType);
86
- }
87
-
88
- const suffix = this.getPossibleFileEnding(notebookTypeInfo.selector ?? []) ?? '';
89
- for (let counter = 1; ; counter++) {
90
- const candidate = new URI()
91
- .withScheme(UNTITLED_SCHEME)
92
- .withPath(`Untitled-notebook-${counter}${suffix}`)
93
- .withQuery(viewType);
94
- if (!this.notebookService.getNotebookEditorModel(candidate)) {
95
- resource = candidate;
96
- break;
97
- }
98
- }
99
- } else if (arg.untitledResource.scheme === UNTITLED_SCHEME) {
100
- resource = arg.untitledResource;
101
- } else {
102
- throw new Error('Invalid untitled resource: ' + arg.untitledResource.toString() + ' untitled resources with associated file path are not supported yet');
103
- // TODO implement associated file path support
104
- // resource = arg.untitledResource.withScheme('untitled');
105
- // hasAssociatedFilePath = true;
106
- }
107
-
108
- return this.resolve(resource, viewType);
109
- }
110
-
111
- async resolveExistingNotebookData(resource: Resource, viewType: string): Promise<NotebookData> {
112
- if (resource.uri.scheme === 'untitled') {
113
- return {
114
- cells: [],
115
- metadata: {}
116
- };
117
- } else {
118
- const [dataProvider, contents] = await Promise.all([
119
- this.notebookService.getNotebookDataProvider(viewType),
120
- this.fileService.readFile(resource.uri)
121
- ]);
122
- const notebook = await dataProvider.serializer.toNotebook(contents.value);
123
-
124
- return notebook;
125
- }
126
- }
127
-
128
- protected getPossibleFileEnding(selectors: readonly NotebookFileSelector[]): string | undefined {
129
- for (const selector of selectors) {
130
- const ending = this.possibleFileEnding(selector);
131
- if (ending) {
132
- return ending;
133
- }
134
- }
135
- return undefined;
136
- }
137
-
138
- protected possibleFileEnding(selector: NotebookFileSelector): string | undefined {
139
-
140
- const pattern = /^.*(\.[a-zA-Z0-9_-]+)$/;
141
-
142
- const candidate = typeof selector === 'string' ? selector : selector.filenamePattern;
143
-
144
- if (candidate) {
145
- const matches = pattern.exec(candidate);
146
- if (matches) {
147
- return matches[1];
148
- }
149
- }
150
-
151
- return undefined;
152
- }
153
-
154
- protected findViewTypeForResource(resource: URI): string | undefined {
155
- return this.notebookTypeRegistry.notebookTypes.find(info =>
156
- info.selector?.some(selector => selector.filenamePattern && match(selector.filenamePattern, resource.path.name + resource.path.ext))
157
- )?.type;
158
- }
159
-
160
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2023 TypeFox and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { Emitter, Resource, ResourceProvider, UNTITLED_SCHEME, URI } from '@theia/core';
18
+ import { inject, injectable } from '@theia/core/shared/inversify';
19
+ import { UriComponents } from '@theia/core/lib/common/uri';
20
+ import { FileService } from '@theia/filesystem/lib/browser/file-service';
21
+ import { NotebookData } from '../../common';
22
+ import { NotebookModel } from '../view-model/notebook-model';
23
+ import { NotebookService } from './notebook-service';
24
+ import { NotebookTypeRegistry } from '../notebook-type-registry';
25
+ import { NotebookFileSelector } from '../../common/notebook-protocol';
26
+ import { match } from '@theia/core/lib/common/glob';
27
+
28
+ export interface UntitledResource {
29
+ untitledResource: URI | undefined
30
+ }
31
+
32
+ @injectable()
33
+ export class NotebookModelResolverService {
34
+
35
+ @inject(FileService)
36
+ protected fileService: FileService;
37
+
38
+ @inject(ResourceProvider)
39
+ protected resourceProvider: ResourceProvider;
40
+
41
+ @inject(NotebookService)
42
+ protected notebookService: NotebookService;
43
+
44
+ @inject(NotebookTypeRegistry)
45
+ protected notebookTypeRegistry: NotebookTypeRegistry;
46
+
47
+ protected onDidChangeDirtyEmitter = new Emitter<NotebookModel>();
48
+ readonly onDidChangeDirty = this.onDidChangeDirtyEmitter.event;
49
+ protected onDidSaveNotebookEmitter = new Emitter<UriComponents>();
50
+ readonly onDidSaveNotebook = this.onDidSaveNotebookEmitter.event;
51
+
52
+ async resolve(resource: URI, viewType?: string): Promise<NotebookModel> {
53
+ const existingModel = this.notebookService.getNotebookEditorModel(resource);
54
+ if (!viewType) {
55
+ if (existingModel) {
56
+ return existingModel;
57
+ } else {
58
+ viewType = this.findViewTypeForResource(resource);
59
+ }
60
+ } else if (existingModel?.viewType === viewType) {
61
+ return existingModel;
62
+ }
63
+
64
+ if (!viewType) {
65
+ throw new Error(`Missing viewType for '${resource}'`);
66
+ }
67
+
68
+ const actualResource = await this.resourceProvider(resource);
69
+ const notebookData = await this.resolveExistingNotebookData(actualResource, viewType!);
70
+ const notebookModel = await this.notebookService.createNotebookModel(notebookData, viewType, actualResource);
71
+
72
+ notebookModel.onDirtyChanged(() => this.onDidChangeDirtyEmitter.fire(notebookModel));
73
+ notebookModel.onDidSaveNotebook(() => this.onDidSaveNotebookEmitter.fire(notebookModel.uri.toComponents()));
74
+
75
+ return notebookModel;
76
+ }
77
+
78
+ async resolveUntitledResource(arg: UntitledResource, viewType: string): Promise<NotebookModel> {
79
+ let resource: URI;
80
+ // let hasAssociatedFilePath = false;
81
+ arg = arg as UntitledResource;
82
+ if (!arg.untitledResource) {
83
+ const notebookTypeInfo = this.notebookTypeRegistry.notebookTypes.find(info => info.type === viewType);
84
+ if (!notebookTypeInfo) {
85
+ throw new Error('UNKNOWN view type: ' + viewType);
86
+ }
87
+
88
+ const suffix = this.getPossibleFileEnding(notebookTypeInfo.selector ?? []) ?? '';
89
+ for (let counter = 1; ; counter++) {
90
+ const candidate = new URI()
91
+ .withScheme(UNTITLED_SCHEME)
92
+ .withPath(`Untitled-notebook-${counter}${suffix}`)
93
+ .withQuery(viewType);
94
+ if (!this.notebookService.getNotebookEditorModel(candidate)) {
95
+ resource = candidate;
96
+ break;
97
+ }
98
+ }
99
+ } else if (arg.untitledResource.scheme === UNTITLED_SCHEME) {
100
+ resource = arg.untitledResource;
101
+ } else {
102
+ throw new Error('Invalid untitled resource: ' + arg.untitledResource.toString() + ' untitled resources with associated file path are not supported yet');
103
+ // TODO implement associated file path support
104
+ // resource = arg.untitledResource.withScheme('untitled');
105
+ // hasAssociatedFilePath = true;
106
+ }
107
+
108
+ return this.resolve(resource, viewType);
109
+ }
110
+
111
+ async resolveExistingNotebookData(resource: Resource, viewType: string): Promise<NotebookData> {
112
+ if (resource.uri.scheme === 'untitled') {
113
+ return {
114
+ cells: [],
115
+ metadata: {}
116
+ };
117
+ } else {
118
+ const [dataProvider, contents] = await Promise.all([
119
+ this.notebookService.getNotebookDataProvider(viewType),
120
+ this.fileService.readFile(resource.uri)
121
+ ]);
122
+ const notebook = await dataProvider.serializer.toNotebook(contents.value);
123
+
124
+ return notebook;
125
+ }
126
+ }
127
+
128
+ protected getPossibleFileEnding(selectors: readonly NotebookFileSelector[]): string | undefined {
129
+ for (const selector of selectors) {
130
+ const ending = this.possibleFileEnding(selector);
131
+ if (ending) {
132
+ return ending;
133
+ }
134
+ }
135
+ return undefined;
136
+ }
137
+
138
+ protected possibleFileEnding(selector: NotebookFileSelector): string | undefined {
139
+
140
+ const pattern = /^.*(\.[a-zA-Z0-9_-]+)$/;
141
+
142
+ const candidate = typeof selector === 'string' ? selector : selector.filenamePattern;
143
+
144
+ if (candidate) {
145
+ const matches = pattern.exec(candidate);
146
+ if (matches) {
147
+ return matches[1];
148
+ }
149
+ }
150
+
151
+ return undefined;
152
+ }
153
+
154
+ protected findViewTypeForResource(resource: URI): string | undefined {
155
+ return this.notebookTypeRegistry.notebookTypes.find(info =>
156
+ info.selector?.some(selector => selector.filenamePattern && match(selector.filenamePattern, resource.path.name + resource.path.ext))
157
+ )?.type;
158
+ }
159
+
160
+ }
@@ -1,48 +1,48 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2024 TypeFox and others.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import { ReferenceCollection, URI, Reference, Event } from '@theia/core';
18
- import { inject, injectable } from '@theia/core/shared/inversify';
19
- import { MonacoTextModelService } from '@theia/monaco/lib/browser/monaco-text-model-service';
20
- import { MonacoEditorModel } from '@theia/monaco/lib/browser/monaco-editor-model';
21
- import { NotebookModel } from '../view-model/notebook-model';
22
-
23
- /**
24
- * special service for creating monaco textmodels for notebook cells.
25
- * 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.
26
- */
27
- @injectable()
28
- export class NotebookMonacoTextModelService {
29
-
30
- @inject(MonacoTextModelService)
31
- protected readonly monacoTextModelService: MonacoTextModelService;
32
-
33
- protected readonly cellmodels = new ReferenceCollection<string, MonacoEditorModel>(
34
- uri => this.monacoTextModelService.createUnmanagedModel(new URI(uri))
35
- );
36
-
37
- getOrCreateNotebookCellModelReference(uri: URI): Promise<Reference<MonacoEditorModel>> {
38
- return this.cellmodels.acquire(uri.toString());
39
- }
40
-
41
- async createTextModelsForNotebook(notebook: NotebookModel): Promise<void> {
42
- await Promise.all(notebook.cells.map(cell => cell.resolveTextModel()));
43
- }
44
-
45
- get onDidCreateNotebookCellModel(): Event<MonacoEditorModel> {
46
- return this.cellmodels.onDidCreate;
47
- }
48
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2024 TypeFox and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { ReferenceCollection, URI, Reference, Event } from '@theia/core';
18
+ import { inject, injectable } from '@theia/core/shared/inversify';
19
+ import { MonacoTextModelService } from '@theia/monaco/lib/browser/monaco-text-model-service';
20
+ import { MonacoEditorModel } from '@theia/monaco/lib/browser/monaco-editor-model';
21
+ import { NotebookModel } from '../view-model/notebook-model';
22
+
23
+ /**
24
+ * special service for creating monaco textmodels for notebook cells.
25
+ * 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.
26
+ */
27
+ @injectable()
28
+ export class NotebookMonacoTextModelService {
29
+
30
+ @inject(MonacoTextModelService)
31
+ protected readonly monacoTextModelService: MonacoTextModelService;
32
+
33
+ protected readonly cellmodels = new ReferenceCollection<string, MonacoEditorModel>(
34
+ uri => this.monacoTextModelService.createUnmanagedModel(new URI(uri))
35
+ );
36
+
37
+ getOrCreateNotebookCellModelReference(uri: URI): Promise<Reference<MonacoEditorModel>> {
38
+ return this.cellmodels.acquire(uri.toString());
39
+ }
40
+
41
+ async createTextModelsForNotebook(notebook: NotebookModel): Promise<void> {
42
+ await Promise.all(notebook.cells.map(cell => cell.resolveTextModel()));
43
+ }
44
+
45
+ get onDidCreateNotebookCellModel(): Event<MonacoEditorModel> {
46
+ return this.cellmodels.onDidCreate;
47
+ }
48
+ }