@@ -194,41 +194,52 @@ const apiTestContentProvider: vscode.NotebookContentProvider = {
194
194
const notebook = await openRandomNotebookDocument ( ) ;
195
195
const editor = await vscode . window . showNotebookDocument ( notebook ) ;
196
196
197
- const cellsChangeEvent = asPromise < vscode . NotebookCellsChangeEvent > ( vscode . notebooks . onDidChangeNotebookCells ) ;
197
+ const cellsChangeEvent = asPromise < vscode . NotebookDocumentChangeEvent > ( vscode . workspace . onDidChangeNotebookDocument ) ;
198
198
await vscode . commands . executeCommand ( 'notebook.cell.insertCodeCellBelow' ) ;
199
199
const cellChangeEventRet = await cellsChangeEvent ;
200
- assert . strictEqual ( cellChangeEventRet . document , editor . document ) ;
201
- assert . strictEqual ( cellChangeEventRet . changes . length , 1 ) ;
202
- assert . deepStrictEqual ( cellChangeEventRet . changes [ 0 ] , {
203
- start : 1 ,
204
- deletedCount : 0 ,
205
- deletedItems : [ ] ,
206
- items : [
207
- editor . document . cellAt ( 1 )
208
- ]
200
+ assert . strictEqual ( cellChangeEventRet . notebook , editor . document ) ;
201
+ assert . strictEqual ( cellChangeEventRet . contentChanges . length , 1 ) ;
202
+ assert . deepStrictEqual ( cellChangeEventRet . contentChanges [ 0 ] , < vscode . NotebookDocumentContentChange > {
203
+ range : new vscode . NotebookRange ( 1 , 1 ) ,
204
+ removedCells : [ ] ,
205
+ addedCells : [ editor . document . cellAt ( 1 ) ]
209
206
} ) ;
210
207
211
- const moveCellEvent = asPromise < vscode . NotebookCellsChangeEvent > ( vscode . notebooks . onDidChangeNotebookCells ) ;
208
+ const moveCellEvent = asPromise < vscode . NotebookDocumentChangeEvent > ( vscode . workspace . onDidChangeNotebookDocument ) ;
212
209
await vscode . commands . executeCommand ( 'notebook.cell.moveUp' ) ;
213
210
await moveCellEvent ;
214
211
215
- const cellOutputChange = asPromise < vscode . NotebookCellOutputsChangeEvent > ( vscode . notebooks . onDidChangeCellOutputs ) ;
212
+ const cellOutputChange = asPromise < vscode . NotebookDocumentChangeEvent > ( vscode . workspace . onDidChangeNotebookDocument ) ;
216
213
await vscode . commands . executeCommand ( 'notebook.cell.execute' ) ;
217
214
const cellOutputsAddedRet = await cellOutputChange ;
218
- assert . deepStrictEqual ( cellOutputsAddedRet , {
219
- document : editor . document ,
220
- cells : [ editor . document . cellAt ( 0 ) ]
221
- } ) ;
222
- assert . strictEqual ( cellOutputsAddedRet . cells [ 0 ] . outputs . length , 1 ) ;
223
215
224
- const cellOutputClear = asPromise < vscode . NotebookCellOutputsChangeEvent > ( vscode . notebooks . onDidChangeCellOutputs ) ;
216
+ assert . strictEqual ( cellOutputsAddedRet . notebook . uri . toString ( ) , editor . document . uri . toString ( ) ) ;
217
+ assert . strictEqual ( cellOutputsAddedRet . metadata , undefined ) ;
218
+ assert . strictEqual ( cellOutputsAddedRet . contentChanges . length , 0 ) ;
219
+ assert . strictEqual ( cellOutputsAddedRet . cellChanges . length , 1 ) ;
220
+ assert . deepStrictEqual ( cellOutputsAddedRet . cellChanges [ 0 ] . cell , editor . document . cellAt ( 0 ) ) ;
221
+ assert . deepStrictEqual ( cellOutputsAddedRet . cellChanges [ 0 ] . executionSummary , { executionOrder : undefined , success : undefined , timing : undefined } ) ; // TODO@jrieken should this be undefined instead all empty?
222
+ assert . strictEqual ( cellOutputsAddedRet . cellChanges [ 0 ] . document , undefined ) ;
223
+ assert . strictEqual ( cellOutputsAddedRet . cellChanges [ 0 ] . metadata , undefined ) ;
224
+ assert . strictEqual ( cellOutputsAddedRet . cellChanges [ 0 ] . outputs , undefined ) ;
225
+ assert . strictEqual ( cellOutputsAddedRet . cellChanges [ 0 ] . cell . outputs . length , 1 ) ;
226
+
227
+ const cellOutputClear = asPromise < vscode . NotebookDocumentChangeEvent > ( vscode . workspace . onDidChangeNotebookDocument ) ;
225
228
await vscode . commands . executeCommand ( 'notebook.cell.clearOutputs' ) ;
226
229
const cellOutputsCleardRet = await cellOutputClear ;
227
- assert . deepStrictEqual ( cellOutputsCleardRet , {
228
- document : editor . document ,
229
- cells : [ editor . document . cellAt ( 0 ) ]
230
+ assert . deepStrictEqual ( cellOutputsCleardRet , < vscode . NotebookDocumentChangeEvent > {
231
+ notebook : editor . document ,
232
+ metadata : undefined ,
233
+ contentChanges : [ ] ,
234
+ cellChanges : [ {
235
+ cell : editor . document . cellAt ( 0 ) ,
236
+ document : undefined ,
237
+ executionSummary : undefined ,
238
+ metadata : undefined ,
239
+ outputs : editor . document . cellAt ( 0 ) . outputs
240
+ } ] ,
230
241
} ) ;
231
- assert . strictEqual ( cellOutputsAddedRet . cells [ 0 ] . outputs . length , 0 ) ;
242
+ assert . strictEqual ( cellOutputsCleardRet . cellChanges [ 0 ] . cell . outputs . length , 0 ) ;
232
243
233
244
// const cellChangeLanguage = getEventOncePromise<vscode.NotebookCellLanguageChangeEvent>(vscode.notebooks.onDidChangeCellLanguage);
234
245
// await vscode.commands.executeCommand('notebook.cell.changeToMarkdown');
@@ -244,33 +255,29 @@ const apiTestContentProvider: vscode.NotebookContentProvider = {
244
255
const notebook = await openRandomNotebookDocument ( ) ;
245
256
const editor = await vscode . window . showNotebookDocument ( notebook ) ;
246
257
247
- const cellsChangeEvent = asPromise < vscode . NotebookCellsChangeEvent > ( vscode . notebooks . onDidChangeNotebookCells ) ;
248
- const cellMetadataChangeEvent = asPromise < vscode . NotebookCellMetadataChangeEvent > ( vscode . notebooks . onDidChangeCellMetadata ) ;
258
+ const notebookChangeEvent = asPromise < vscode . NotebookDocumentChangeEvent > ( vscode . workspace . onDidChangeNotebookDocument ) ;
249
259
const version = editor . document . version ;
250
260
await editor . edit ( editBuilder => {
251
261
editBuilder . replaceCells ( 1 , 0 , [ { kind : vscode . NotebookCellKind . Code , languageId : 'javascript' , value : 'test 2' , outputs : [ ] , metadata : undefined } ] ) ;
252
262
editBuilder . replaceCellMetadata ( 0 , { inputCollapsed : false } ) ;
253
263
} ) ;
254
264
255
- await cellsChangeEvent ;
256
- await cellMetadataChangeEvent ;
265
+ await notebookChangeEvent ;
257
266
assert . strictEqual ( version + 1 , editor . document . version ) ;
258
267
} ) ;
259
268
260
269
test ( 'edit API batch edits undo/redo' , async function ( ) {
261
270
const notebook = await openRandomNotebookDocument ( ) ;
262
271
const editor = await vscode . window . showNotebookDocument ( notebook ) ;
263
272
264
- const cellsChangeEvent = asPromise < vscode . NotebookCellsChangeEvent > ( vscode . notebooks . onDidChangeNotebookCells ) ;
265
- const cellMetadataChangeEvent = asPromise < vscode . NotebookCellMetadataChangeEvent > ( vscode . notebooks . onDidChangeCellMetadata ) ;
273
+ const notebookChangeEvent = asPromise < vscode . NotebookDocumentChangeEvent > ( vscode . workspace . onDidChangeNotebookDocument ) ;
266
274
const version = editor . document . version ;
267
275
await editor . edit ( editBuilder => {
268
276
editBuilder . replaceCells ( 1 , 0 , [ { kind : vscode . NotebookCellKind . Code , languageId : 'javascript' , value : 'test 2' , outputs : [ ] , metadata : undefined } ] ) ;
269
277
editBuilder . replaceCellMetadata ( 0 , { inputCollapsed : false } ) ;
270
278
} ) ;
271
279
272
- await cellsChangeEvent ;
273
- await cellMetadataChangeEvent ;
280
+ await notebookChangeEvent ;
274
281
assert . strictEqual ( editor . document . cellCount , 3 ) ;
275
282
assert . strictEqual ( editor . document . cellAt ( 0 ) ?. metadata . inputCollapsed , false ) ;
276
283
assert . strictEqual ( version + 1 , editor . document . version ) ;
@@ -285,7 +292,7 @@ const apiTestContentProvider: vscode.NotebookContentProvider = {
285
292
test . skip ( '#98841, initialzation should not emit cell change events.' , async function ( ) {
286
293
let count = 0 ;
287
294
288
- testDisposables . push ( vscode . notebooks . onDidChangeNotebookCells ( ( ) => {
295
+ testDisposables . push ( vscode . workspace . onDidChangeNotebookDocument ( ( ) => {
289
296
count ++ ;
290
297
} ) ) ;
291
298
@@ -387,9 +394,9 @@ const apiTestContentProvider: vscode.NotebookContentProvider = {
387
394
388
395
const activeCell = getFocusedCell ( editor ) ;
389
396
assert . strictEqual ( activeCell ?. index , 0 ) ;
390
- const moveChange = asPromise ( vscode . notebooks . onDidChangeNotebookCells ) ;
397
+ const notebookChangeEvent = asPromise ( vscode . workspace . onDidChangeNotebookDocument ) ;
391
398
await vscode . commands . executeCommand ( 'notebook.cell.moveDown' ) ;
392
- assert . ok ( await moveChange ) ;
399
+ assert . ok ( await notebookChangeEvent ) ;
393
400
394
401
const newActiveCell = getFocusedCell ( editor ) ;
395
402
assert . strictEqual ( newActiveCell ?. index , 1 ) ;
@@ -440,13 +447,13 @@ const apiTestContentProvider: vscode.NotebookContentProvider = {
440
447
const editor = vscode . window . activeNotebookEditor ! ;
441
448
const cell = editor . document . cellAt ( 0 ) ;
442
449
443
- await withEvent ( vscode . notebooks . onDidChangeCellOutputs , async ( event ) => {
450
+ await withEvent ( vscode . workspace . onDidChangeNotebookDocument , async ( event ) => {
444
451
await vscode . commands . executeCommand ( 'notebook.execute' ) ;
445
452
await event ;
446
453
assert . strictEqual ( cell . outputs . length , 1 , 'should execute' ) ; // runnable, it worked
447
454
} ) ;
448
455
449
- await withEvent ( vscode . notebooks . onDidChangeCellOutputs , async event => {
456
+ await withEvent ( vscode . workspace . onDidChangeNotebookDocument , async event => {
450
457
await vscode . commands . executeCommand ( 'notebook.cell.clearOutputs' ) ;
451
458
await event ;
452
459
assert . strictEqual ( cell . outputs . length , 0 , 'should clear' ) ;
@@ -455,7 +462,7 @@ const apiTestContentProvider: vscode.NotebookContentProvider = {
455
462
const secondResource = await createRandomNotebookFile ( ) ;
456
463
await vscode . commands . executeCommand ( 'vscode.openWith' , secondResource , 'notebookCoreTest' ) ;
457
464
458
- await withEvent < vscode . NotebookCellOutputsChangeEvent > ( vscode . notebooks . onDidChangeCellOutputs , async ( event ) => {
465
+ await withEvent < vscode . NotebookDocumentChangeEvent > ( vscode . workspace . onDidChangeNotebookDocument , async ( event ) => {
459
466
await vscode . commands . executeCommand ( 'notebook.cell.execute' , { start : 0 , end : 1 } , resource ) ;
460
467
await event ;
461
468
assert . strictEqual ( cell . outputs . length , 1 , 'should execute' ) ; // runnable, it worked
@@ -473,13 +480,13 @@ const apiTestContentProvider: vscode.NotebookContentProvider = {
473
480
let secondCellExecuted = false ;
474
481
let resolve : ( ) => void ;
475
482
const p = new Promise < void > ( r => resolve = r ) ;
476
- const listener = vscode . notebooks . onDidChangeCellOutputs ( e => {
477
- e . cells . forEach ( cell => {
478
- if ( cell . index === 0 ) {
483
+ const listener = vscode . workspace . onDidChangeNotebookDocument ( e => {
484
+ e . cellChanges . forEach ( change => {
485
+ if ( change . cell . index === 0 ) {
479
486
firstCellExecuted = true ;
480
487
}
481
488
482
- if ( cell . index === 1 ) {
489
+ if ( change . cell . index === 1 ) {
483
490
secondCellExecuted = true ;
484
491
}
485
492
} ) ;
@@ -501,21 +508,21 @@ const apiTestContentProvider: vscode.NotebookContentProvider = {
501
508
const editor = vscode . window . activeNotebookEditor ! ;
502
509
const cell = editor . document . cellAt ( 0 ) ;
503
510
504
- await withEvent < vscode . NotebookCellOutputsChangeEvent > ( vscode . notebooks . onDidChangeCellOutputs , async ( event ) => {
511
+ await withEvent < vscode . NotebookDocumentChangeEvent > ( vscode . workspace . onDidChangeNotebookDocument , async ( event ) => {
505
512
await vscode . commands . executeCommand ( 'notebook.execute' ) ;
506
513
await event ;
507
514
assert . strictEqual ( cell . outputs . length , 1 , 'should execute' ) ; // runnable, it worked
508
515
} ) ;
509
516
510
- const clearChangeEvent = asPromise < vscode . NotebookCellOutputsChangeEvent > ( vscode . notebooks . onDidChangeCellOutputs ) ;
517
+ const clearChangeEvent = asPromise < vscode . NotebookDocumentChangeEvent > ( vscode . workspace . onDidChangeNotebookDocument ) ;
511
518
await vscode . commands . executeCommand ( 'notebook.cell.clearOutputs' ) ;
512
519
await clearChangeEvent ;
513
520
assert . strictEqual ( cell . outputs . length , 0 , 'should clear' ) ;
514
521
515
522
const secondResource = await createRandomNotebookFile ( ) ;
516
523
await vscode . commands . executeCommand ( 'vscode.openWith' , secondResource , 'notebookCoreTest' ) ;
517
524
518
- await withEvent < vscode . NotebookCellOutputsChangeEvent > ( vscode . notebooks . onDidChangeCellOutputs , async ( event ) => {
525
+ await withEvent < vscode . NotebookDocumentChangeEvent > ( vscode . workspace . onDidChangeNotebookDocument , async ( event ) => {
519
526
await vscode . commands . executeCommand ( 'notebook.execute' , resource ) ;
520
527
await event ;
521
528
assert . strictEqual ( cell . outputs . length , 1 , 'should execute' ) ; // runnable, it worked
@@ -547,7 +554,7 @@ const apiTestContentProvider: vscode.NotebookContentProvider = {
547
554
} ;
548
555
testDisposables . push ( alternativeKernel . controller ) ;
549
556
550
- await withEvent < vscode . NotebookCellOutputsChangeEvent > ( vscode . notebooks . onDidChangeCellOutputs , async ( event ) => {
557
+ await withEvent < vscode . NotebookDocumentChangeEvent > ( vscode . workspace . onDidChangeNotebookDocument , async ( event ) => {
551
558
await assertKernel ( defaultKernel , notebook ) ;
552
559
await vscode . commands . executeCommand ( 'notebook.cell.execute' ) ;
553
560
await event ;
@@ -557,7 +564,7 @@ const apiTestContentProvider: vscode.NotebookContentProvider = {
557
564
assert . deepStrictEqual ( new TextDecoder ( ) . decode ( cell . outputs [ 0 ] . items [ 0 ] . data ) , cell . document . getText ( ) ) ;
558
565
} ) ;
559
566
560
- await withEvent < vscode . NotebookCellOutputsChangeEvent > ( vscode . notebooks . onDidChangeCellOutputs , async ( event ) => {
567
+ await withEvent < vscode . NotebookDocumentChangeEvent > ( vscode . workspace . onDidChangeNotebookDocument , async ( event ) => {
561
568
await assertKernel ( alternativeKernel , notebook ) ;
562
569
await vscode . commands . executeCommand ( 'notebook.cell.execute' ) ;
563
570
await event ;
@@ -798,16 +805,16 @@ const apiTestContentProvider: vscode.NotebookContentProvider = {
798
805
const notebook = await vscode . workspace . openNotebookDocument ( resource ) ;
799
806
const editor = await vscode . window . showNotebookDocument ( notebook ) ;
800
807
801
- const cellsChangeEvent = asPromise < vscode . NotebookCellsChangeEvent > ( vscode . notebooks . onDidChangeNotebookCells ) ;
808
+ const cellsChangeEvent = asPromise < vscode . NotebookDocumentChangeEvent > ( vscode . workspace . onDidChangeNotebookDocument ) ;
802
809
await editor . edit ( editBuilder => {
803
810
editBuilder . replaceCells ( 1 , 0 , [ { kind : vscode . NotebookCellKind . Code , languageId : 'javascript' , value : 'test 2' , outputs : [ ] , metadata : undefined } ] ) ;
804
811
} ) ;
805
812
806
813
const cellChangeEventRet = await cellsChangeEvent ;
807
- assert . strictEqual ( cellChangeEventRet . document === notebook , true ) ;
808
- assert . strictEqual ( cellChangeEventRet . document . isDirty , true ) ;
814
+ assert . strictEqual ( cellChangeEventRet . notebook === notebook , true ) ;
815
+ assert . strictEqual ( cellChangeEventRet . notebook . isDirty , true ) ;
809
816
810
- const saveEvent = asPromise ( vscode . notebooks . onDidSaveNotebookDocument ) ;
817
+ const saveEvent = asPromise ( vscode . workspace . onDidSaveNotebookDocument ) ;
811
818
812
819
await notebook . save ( ) ;
813
820
0 commit comments