-
Notifications
You must be signed in to change notification settings - Fork 29.5k
/
notebook.contribution.ts
637 lines (544 loc) · 25.6 KB
/
notebook.contribution.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { coalesce, distinct } from 'vs/base/common/arrays';
import { Schemas } from 'vs/base/common/network';
import { IDisposable, Disposable } from 'vs/base/common/lifecycle';
import { parse } from 'vs/base/common/marshalling';
import { isEqual } from 'vs/base/common/resources';
import { assertType } from 'vs/base/common/types';
import { URI } from 'vs/base/common/uri';
import { ITextModel, ITextBufferFactory, DefaultEndOfLine, ITextBuffer } from 'vs/editor/common/model';
import { IModelService } from 'vs/editor/common/services/modelService';
import { IModeService } from 'vs/editor/common/services/modeService';
import { ITextModelContentProvider, ITextModelService } from 'vs/editor/common/services/resolverService';
import * as nls from 'vs/nls';
import { Extensions, IConfigurationRegistry } from 'vs/platform/configuration/common/configurationRegistry';
import { IEditorOptions, ITextEditorOptions, IResourceEditorInput } from 'vs/platform/editor/common/editor';
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle';
import { Registry } from 'vs/platform/registry/common/platform';
import { EditorDescriptor, Extensions as EditorExtensions, IEditorRegistry } from 'vs/workbench/browser/editor';
import { Extensions as WorkbenchExtensions, IWorkbenchContribution, IWorkbenchContributionsRegistry } from 'vs/workbench/common/contributions';
import { EditorInput, Extensions as EditorInputExtensions, IEditorInput, IEditorInputFactory, IEditorInputFactoryRegistry } from 'vs/workbench/common/editor';
import { IBackupFileService } from 'vs/workbench/services/backup/common/backup';
import { NotebookEditor } from 'vs/workbench/contrib/notebook/browser/notebookEditor';
import { NotebookEditorInput } from 'vs/workbench/contrib/notebook/browser/notebookEditorInput';
import { INotebookService } from 'vs/workbench/contrib/notebook/common/notebookService';
import { NotebookService } from 'vs/workbench/contrib/notebook/browser/notebookServiceImpl';
import { CellKind, CellToolbarLocKey, CellUri, DisplayOrderKey, getCellUndoRedoComparisonKey, NotebookDocumentBackupData, NotebookEditorPriority, NotebookTextDiffEditorPreview, ShowCellStatusBarKey } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { NotebookProviderInfo } from 'vs/workbench/contrib/notebook/common/notebookProvider';
import { IEditorGroup } from 'vs/workbench/services/editor/common/editorGroupsService';
import { IEditorService, IOpenEditorOverride } from 'vs/workbench/services/editor/common/editorService';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { CustomEditorsAssociations, customEditorsAssociationsSettingId } from 'vs/workbench/services/editor/common/editorOpenWith';
import { CustomEditorInfo } from 'vs/workbench/contrib/customEditor/common/customEditor';
import { INotebookEditor, NotebookEditorOptions } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { IUndoRedoService } from 'vs/platform/undoRedo/common/undoRedo';
import { INotebookEditorModelResolverService, NotebookModelResolverService } from 'vs/workbench/contrib/notebook/common/notebookEditorModelResolverService';
import { ResourceEditorInput } from 'vs/workbench/common/editor/resourceEditorInput';
import { DiffEditorInput } from 'vs/workbench/common/editor/diffEditorInput';
import { NotebookDiffEditorInput } from 'vs/workbench/contrib/notebook/browser/notebookDiffEditorInput';
import { NotebookTextDiffEditor } from 'vs/workbench/contrib/notebook/browser/diff/notebookTextDiffEditor';
import { INotebookEditorWorkerService } from 'vs/workbench/contrib/notebook/common/services/notebookWorkerService';
import { NotebookEditorWorkerServiceImpl } from 'vs/workbench/contrib/notebook/common/services/notebookWorkerServiceImpl';
import { INotebookCellStatusBarService } from 'vs/workbench/contrib/notebook/common/notebookCellStatusBarService';
import { NotebookCellStatusBarService } from 'vs/workbench/contrib/notebook/browser/notebookCellStatusBarServiceImpl';
import { IJSONContributionRegistry, Extensions as JSONExtensions } from 'vs/platform/jsonschemas/common/jsonContributionRegistry';
import { IJSONSchema } from 'vs/base/common/jsonSchema';
import { IWorkingCopyService } from 'vs/workbench/services/workingCopy/common/workingCopyService';
import { Event } from 'vs/base/common/event';
import { IAccessibilityService } from 'vs/platform/accessibility/common/accessibility';
// Editor Contribution
import 'vs/workbench/contrib/notebook/browser/contrib/coreActions';
import 'vs/workbench/contrib/notebook/browser/contrib/find/findController';
import 'vs/workbench/contrib/notebook/browser/contrib/fold/folding';
import 'vs/workbench/contrib/notebook/browser/contrib/format/formatting';
import 'vs/workbench/contrib/notebook/browser/contrib/toc/tocProvider';
import 'vs/workbench/contrib/notebook/browser/contrib/marker/markerProvider';
import 'vs/workbench/contrib/notebook/browser/contrib/status/editorStatus';
// import 'vs/workbench/contrib/notebook/browser/contrib/scm/scm';
// Diff Editor Contribution
import 'vs/workbench/contrib/notebook/browser/diff/notebookDiffActions';
// Output renderers registration
import 'vs/workbench/contrib/notebook/browser/view/output/transforms/streamTransform';
import 'vs/workbench/contrib/notebook/browser/view/output/transforms/errorTransform';
import 'vs/workbench/contrib/notebook/browser/view/output/transforms/richTransform';
/*--------------------------------------------------------------------------------------------- */
Registry.as<IEditorRegistry>(EditorExtensions.Editors).registerEditor(
EditorDescriptor.create(
NotebookEditor,
NotebookEditor.ID,
'Notebook Editor'
),
[
new SyncDescriptor(NotebookEditorInput)
]
);
Registry.as<IEditorRegistry>(EditorExtensions.Editors).registerEditor(
EditorDescriptor.create(
NotebookTextDiffEditor,
NotebookTextDiffEditor.ID,
'Notebook Diff Editor'
),
[
new SyncDescriptor(NotebookDiffEditorInput)
]
);
class NotebookDiffEditorFactory implements IEditorInputFactory {
canSerialize(): boolean {
return true;
}
serialize(input: EditorInput): string {
assertType(input instanceof NotebookDiffEditorInput);
return JSON.stringify({
resource: input.resource,
originalResource: input.originalResource,
name: input.name,
originalName: input.originalName,
viewType: input.viewType,
});
}
deserialize(instantiationService: IInstantiationService, raw: string) {
type Data = { resource: URI, originalResource: URI, name: string, originalName: string, viewType: string, group: number };
const data = <Data>parse(raw);
if (!data) {
return undefined;
}
const { resource, originalResource, name, originalName, viewType } = data;
if (!data || !URI.isUri(resource) || !URI.isUri(originalResource) || typeof name !== 'string' || typeof originalName !== 'string' || typeof viewType !== 'string') {
return undefined;
}
const input = NotebookDiffEditorInput.create(instantiationService, resource, name, originalResource, originalName, viewType);
return input;
}
static canResolveBackup(editorInput: IEditorInput, backupResource: URI): boolean {
return false;
}
}
class NotebookEditorFactory implements IEditorInputFactory {
canSerialize(): boolean {
return true;
}
serialize(input: EditorInput): string {
assertType(input instanceof NotebookEditorInput);
return JSON.stringify({
resource: input.resource,
name: input.name,
viewType: input.viewType,
});
}
deserialize(instantiationService: IInstantiationService, raw: string) {
type Data = { resource: URI, name: string, viewType: string, group: number };
const data = <Data>parse(raw);
if (!data) {
return undefined;
}
const { resource, name, viewType } = data;
if (!data || !URI.isUri(resource) || typeof name !== 'string' || typeof viewType !== 'string') {
return undefined;
}
const input = NotebookEditorInput.create(instantiationService, resource, name, viewType);
return input;
}
static async createCustomEditorInput(resource: URI, instantiationService: IInstantiationService): Promise<NotebookEditorInput> {
return instantiationService.invokeFunction(async accessor => {
const backupFileService = accessor.get<IBackupFileService>(IBackupFileService);
const backup = await backupFileService.resolve<NotebookDocumentBackupData>(resource);
if (!backup?.meta) {
throw new Error(`No backup found for Notebook editor: ${resource}`);
}
const input = NotebookEditorInput.create(instantiationService, resource, backup.meta.name, backup.meta.viewType, { startDirty: true });
return input;
});
}
static canResolveBackup(editorInput: IEditorInput, backupResource: URI): boolean {
if (editorInput instanceof NotebookEditorInput) {
if (isEqual(editorInput.resource.with({ scheme: Schemas.vscodeNotebook }), backupResource)) {
return true;
}
}
return false;
}
}
Registry.as<IEditorInputFactoryRegistry>(EditorInputExtensions.EditorInputFactories).registerEditorInputFactory(
NotebookEditorInput.ID,
NotebookEditorFactory
);
Registry.as<IEditorInputFactoryRegistry>(EditorInputExtensions.EditorInputFactories).registerCustomEditorInputFactory(
Schemas.vscodeNotebook,
NotebookEditorFactory
);
Registry.as<IEditorInputFactoryRegistry>(EditorInputExtensions.EditorInputFactories).registerEditorInputFactory(
NotebookDiffEditorInput.ID,
NotebookDiffEditorFactory
);
function getFirstNotebookInfo(notebookService: INotebookService, uri: URI): NotebookProviderInfo | undefined {
return notebookService.getContributedNotebookProviders(uri)[0];
}
export class NotebookContribution extends Disposable implements IWorkbenchContribution {
constructor(
@IEditorService private readonly editorService: IEditorService,
@INotebookService private readonly notebookService: INotebookService,
@IInstantiationService private readonly instantiationService: IInstantiationService,
@IConfigurationService private readonly configurationService: IConfigurationService,
@IAccessibilityService private readonly _accessibilityService: IAccessibilityService,
@IUndoRedoService undoRedoService: IUndoRedoService,
) {
super();
this._register(undoRedoService.registerUriComparisonKeyComputer(CellUri.scheme, {
getComparisonKey: (uri: URI): string => {
return getCellUndoRedoComparisonKey(uri);
}
}));
this._register(this.editorService.overrideOpenEditor({
getEditorOverrides: (resource: URI, options: IEditorOptions | undefined, group: IEditorGroup | undefined) => {
const currentEditorForResource = group?.editors.find(editor => isEqual(editor.resource, resource));
const associatedEditors = distinct([
...this.getUserAssociatedNotebookEditors(resource),
...this.getContributedEditors(resource)
], editor => editor.id);
return associatedEditors.map(info => {
return {
label: info.displayName,
id: info.id,
active: currentEditorForResource instanceof NotebookEditorInput && currentEditorForResource.viewType === info.id,
detail: info.providerDisplayName
};
});
},
open: (editor, options, group) => {
return this.onEditorOpening2(editor, options, group);
}
}));
this._register(this.editorService.onDidVisibleEditorsChange(() => {
const visibleNotebookEditors = editorService.visibleEditorPanes
.filter(pane => (pane as unknown as { isNotebookEditor?: boolean }).isNotebookEditor)
.map(pane => pane.getControl() as INotebookEditor)
.filter(control => !!control)
.map(editor => editor.getId());
this.notebookService.updateVisibleNotebookEditor(visibleNotebookEditors);
}));
this._register(this.editorService.onDidActiveEditorChange(() => {
const activeEditorPane = editorService.activeEditorPane as { isNotebookEditor?: boolean } | undefined;
const notebookEditor = activeEditorPane?.isNotebookEditor ? (editorService.activeEditorPane?.getControl() as INotebookEditor) : undefined;
if (notebookEditor) {
this.notebookService.updateActiveNotebookEditor(notebookEditor);
} else {
this.notebookService.updateActiveNotebookEditor(null);
}
}));
}
getUserAssociatedEditors(resource: URI) {
const rawAssociations = this.configurationService.getValue<CustomEditorsAssociations>(customEditorsAssociationsSettingId) || [];
return coalesce(rawAssociations
.filter(association => CustomEditorInfo.selectorMatches(association, resource)));
}
getUserAssociatedNotebookEditors(resource: URI) {
const rawAssociations = this.configurationService.getValue<CustomEditorsAssociations>(customEditorsAssociationsSettingId) || [];
return coalesce(rawAssociations
.filter(association => CustomEditorInfo.selectorMatches(association, resource))
.map(association => this.notebookService.getContributedNotebookProvider(association.viewType)));
}
getContributedEditors(resource: URI) {
return this.notebookService.getContributedNotebookProviders(resource);
}
private onEditorOpening2(originalInput: IEditorInput, options: IEditorOptions | ITextEditorOptions | undefined, group: IEditorGroup): IOpenEditorOverride | undefined {
let id = typeof options?.override === 'string' ? options.override : undefined;
if (id === undefined && originalInput.isUntitled()) {
return undefined;
}
if (originalInput instanceof DiffEditorInput && this.configurationService.getValue(NotebookTextDiffEditorPreview) && !this._accessibilityService.isScreenReaderOptimized()) {
return this._handleDiffEditorInput(originalInput, options, group);
}
if (!originalInput.resource) {
return undefined;
}
if (originalInput instanceof NotebookEditorInput) {
return undefined;
}
let notebookUri: URI = originalInput.resource;
let cellOptions: IResourceEditorInput | undefined;
const data = CellUri.parse(originalInput.resource);
if (data) {
notebookUri = data.notebook;
cellOptions = { resource: originalInput.resource, options };
}
if (id === undefined && originalInput instanceof ResourceEditorInput) {
const exitingNotebookEditor = <NotebookEditorInput | undefined>group.editors.find(editor => editor instanceof NotebookEditorInput && isEqual(editor.resource, notebookUri));
id = exitingNotebookEditor?.viewType;
}
if (id === undefined) {
const existingEditors = group.editors.filter(editor => editor.resource && isEqual(editor.resource, notebookUri) && !(editor instanceof NotebookEditorInput));
if (existingEditors.length) {
return undefined;
}
const userAssociatedEditors = this.getUserAssociatedEditors(notebookUri);
const notebookEditor = userAssociatedEditors.filter(association => this.notebookService.getContributedNotebookProvider(association.viewType));
if (userAssociatedEditors.length && !notebookEditor.length) {
// user pick a non-notebook editor for this resource
return undefined;
}
// user might pick a notebook editor
const associatedEditors = distinct([
...this.getUserAssociatedNotebookEditors(notebookUri),
...(this.getContributedEditors(notebookUri).filter(editor => editor.priority === NotebookEditorPriority.default))
], editor => editor.id);
if (!associatedEditors.length) {
// there is no notebook editor contribution which is enabled by default
return undefined;
}
}
const infos = this.notebookService.getContributedNotebookProviders(notebookUri);
let info = infos.find(info => !id || info.id === id);
if (!info && id !== undefined) {
info = this.notebookService.getContributedNotebookProvider(id);
}
if (!info) {
return undefined;
}
/**
* Scenario: we are reopening a file editor input which is pinned, we should open in a new editor tab.
*/
let index = undefined;
if (group.activeEditor === originalInput && isEqual(originalInput.resource, notebookUri)) {
const originalEditorIndex = group.getIndexOfEditor(originalInput);
index = group.isPinned(originalInput) ? originalEditorIndex + 1 : originalEditorIndex;
}
const notebookInput = NotebookEditorInput.create(this.instantiationService, notebookUri, originalInput.getName(), info.id);
const notebookOptions = new NotebookEditorOptions({ ...options, cellOptions, override: false, index });
return { override: this.editorService.openEditor(notebookInput, notebookOptions, group) };
}
private _handleDiffEditorInput(diffEditorInput: DiffEditorInput, options: IEditorOptions | ITextEditorOptions | undefined, group: IEditorGroup): IOpenEditorOverride | undefined {
const modifiedInput = diffEditorInput.modifiedInput;
const originalInput = diffEditorInput.originalInput;
const notebookUri = modifiedInput.resource;
const originalNotebookUri = originalInput.resource;
if (!notebookUri || !originalNotebookUri) {
return undefined;
}
const existingEditors = group.editors.filter(editor => editor.resource && isEqual(editor.resource, notebookUri) && !(editor instanceof NotebookEditorInput));
if (existingEditors.length) {
return undefined;
}
const userAssociatedEditors = this.getUserAssociatedEditors(notebookUri);
const notebookEditor = userAssociatedEditors.filter(association => this.notebookService.getContributedNotebookProvider(association.viewType));
if (userAssociatedEditors.length && !notebookEditor.length) {
// user pick a non-notebook editor for this resource
return undefined;
}
// user might pick a notebook editor
const associatedEditors = distinct([
...this.getUserAssociatedNotebookEditors(notebookUri),
...(this.getContributedEditors(notebookUri).filter(editor => editor.priority === NotebookEditorPriority.default))
], editor => editor.id);
if (!associatedEditors.length) {
// there is no notebook editor contribution which is enabled by default
return undefined;
}
const info = associatedEditors[0];
const notebookInput = NotebookDiffEditorInput.create(this.instantiationService, notebookUri, modifiedInput.getName(), originalNotebookUri, originalInput.getName(), info.id);
const notebookOptions = new NotebookEditorOptions({ ...options, override: false });
return { override: this.editorService.openEditor(notebookInput, notebookOptions, group) };
}
}
class CellContentProvider implements ITextModelContentProvider {
private readonly _registration: IDisposable;
constructor(
@ITextModelService textModelService: ITextModelService,
@IModelService private readonly _modelService: IModelService,
@IModeService private readonly _modeService: IModeService,
@INotebookService private readonly _notebookService: INotebookService,
@INotebookEditorModelResolverService private readonly _notebookModelResolverService: INotebookEditorModelResolverService,
) {
this._registration = textModelService.registerTextModelContentProvider(CellUri.scheme, this);
}
dispose(): void {
this._registration.dispose();
}
async provideTextContent(resource: URI): Promise<ITextModel | null> {
const existing = this._modelService.getModel(resource);
if (existing) {
return existing;
}
const data = CellUri.parse(resource);
// const data = parseCellUri(resource);
if (!data) {
return null;
}
const info = getFirstNotebookInfo(this._notebookService, data.notebook);
if (!info) {
return null;
}
const ref = await this._notebookModelResolverService.resolve(data.notebook, info.id);
let result: ITextModel | null = null;
for (const cell of ref.object.notebook.cells) {
if (cell.uri.toString() === resource.toString()) {
const bufferFactory: ITextBufferFactory = {
create: (defaultEOL) => {
const newEOL = (defaultEOL === DefaultEndOfLine.CRLF ? '\r\n' : '\n');
(cell.textBuffer as ITextBuffer).setEOL(newEOL);
return cell.textBuffer as ITextBuffer;
},
getFirstLineText: (limit: number) => {
return cell.textBuffer.getLineContent(1).substr(0, limit);
}
};
const language = cell.cellKind === CellKind.Markdown ? this._modeService.create('markdown') : (cell.language ? this._modeService.create(cell.language) : this._modeService.createByFilepathOrFirstLine(resource, cell.textBuffer.getLineContent(1)));
result = this._modelService.createModel(
bufferFactory,
language,
resource
);
break;
}
}
if (result) {
const once = result.onWillDispose(() => {
once.dispose();
ref.dispose();
});
}
return result;
}
}
class RegisterSchemasContribution extends Disposable implements IWorkbenchContribution {
constructor() {
super();
this.registerMetadataSchemas();
}
private registerMetadataSchemas(): void {
const jsonRegistry = Registry.as<IJSONContributionRegistry>(JSONExtensions.JSONContribution);
const metadataSchema: IJSONSchema = {
properties: {
['language']: {
type: 'string',
description: 'The language for the cell'
},
['editable']: {
type: 'boolean',
description: `Controls whether a cell's editor is editable/readonly`
},
['runnable']: {
type: 'boolean',
description: 'Controls if the cell is executable'
},
['breakpointMargin']: {
type: 'boolean',
description: 'Controls if the cell has a margin to support the breakpoint UI'
},
['hasExecutionOrder']: {
type: 'boolean',
description: 'Whether the execution order indicator will be displayed'
},
['executionOrder']: {
type: 'number',
description: 'The order in which this cell was executed'
},
['statusMessage']: {
type: 'string',
description: `A status message to be shown in the cell's status bar`
},
['runState']: {
type: 'integer',
description: `The cell's current run state`
},
['runStartTime']: {
type: 'number',
description: 'If the cell is running, the time at which the cell started running'
},
['lastRunDuration']: {
type: 'number',
description: `The total duration of the cell's last run`
},
['inputCollapsed']: {
type: 'boolean',
description: `Whether a code cell's editor is collapsed`
},
['outputCollapsed']: {
type: 'boolean',
description: `Whether a code cell's outputs are collapsed`
}
},
// patternProperties: allSettings.patternProperties,
additionalProperties: true,
allowTrailingCommas: true,
allowComments: true
};
jsonRegistry.registerSchema('vscode://schemas/notebook/cellmetadata', metadataSchema);
}
}
// makes sure that every dirty notebook gets an editor
class NotebookFileTracker implements IWorkbenchContribution {
private readonly _dirtyListener: IDisposable;
constructor(
@INotebookService private readonly _notebookService: INotebookService,
@IEditorService private readonly _editorService: IEditorService,
@IWorkingCopyService private readonly _workingCopyService: IWorkingCopyService,
) {
this._dirtyListener = Event.debounce(_workingCopyService.onDidChangeDirty, () => { }, 100)(() => {
const inputs = this._createMissingNotebookEditors();
this._editorService.openEditors(inputs);
});
}
dispose(): void {
this._dirtyListener.dispose();
}
private _createMissingNotebookEditors(): IResourceEditorInput[] {
const result: IResourceEditorInput[] = [];
for (const notebook of this._notebookService.getNotebookTextModels()) {
if (this._workingCopyService.isDirty(notebook.uri.with({ scheme: Schemas.vscodeNotebook })) && !this._editorService.isOpen({ resource: notebook.uri })) {
result.push({
resource: notebook.uri,
options: { inactive: true, preserveFocus: true, pinned: true }
});
}
}
return result;
}
}
const workbenchContributionsRegistry = Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench);
workbenchContributionsRegistry.registerWorkbenchContribution(NotebookContribution, LifecyclePhase.Starting);
workbenchContributionsRegistry.registerWorkbenchContribution(CellContentProvider, LifecyclePhase.Starting);
workbenchContributionsRegistry.registerWorkbenchContribution(RegisterSchemasContribution, LifecyclePhase.Starting);
workbenchContributionsRegistry.registerWorkbenchContribution(NotebookFileTracker, LifecyclePhase.Ready);
registerSingleton(INotebookService, NotebookService);
registerSingleton(INotebookEditorWorkerService, NotebookEditorWorkerServiceImpl);
registerSingleton(INotebookEditorModelResolverService, NotebookModelResolverService, true);
registerSingleton(INotebookCellStatusBarService, NotebookCellStatusBarService, true);
const configurationRegistry = Registry.as<IConfigurationRegistry>(Extensions.Configuration);
configurationRegistry.registerConfiguration({
id: 'notebook',
order: 100,
title: nls.localize('notebookConfigurationTitle', "Notebook"),
type: 'object',
properties: {
[DisplayOrderKey]: {
description: nls.localize('notebook.displayOrder.description', "Priority list for output mime types"),
type: ['array'],
items: {
type: 'string'
},
default: []
},
[CellToolbarLocKey]: {
description: nls.localize('notebook.cellToolbarLocation.description', "Where the cell toolbar should be shown, or whether it should be hidden."),
type: 'string',
enum: ['left', 'right', 'hidden'],
default: 'right'
},
[ShowCellStatusBarKey]: {
description: nls.localize('notebook.showCellStatusbar.description', "Whether the cell status bar should be shown."),
type: 'boolean',
default: true
},
[NotebookTextDiffEditorPreview]: {
description: nls.localize('notebook.diff.enablePreview.description', "Whether to use the enhanced text diff editor for notebook."),
type: 'boolean',
default: true
}
}
});