@@ -251,23 +251,56 @@ suite('ExtHost Testing', () => {
251
251
] ) ;
252
252
} ) ;
253
253
254
+ test ( 'replaces on uri change' , ( ) => {
255
+ single . expand ( single . root . id , Infinity ) ;
256
+ single . collectDiff ( ) ;
257
+
258
+ const oldA = single . root . children . get ( 'id-a' ) as TestItemImpl ;
259
+ const uri = single . root . children . get ( 'id-a' ) ! . uri ?. with ( { path : '/different' } ) ;
260
+ const newA = new TestItemImpl ( 'ctrlId' , 'id-a' , 'Hello world' , uri ) ;
261
+ newA . children . replace ( [ ...oldA . children ] . map ( ( [ _ , item ] ) => item ) ) ;
262
+ single . root . children . replace ( [ ...single . root . children ] . map ( ( [ id , i ] ) => id === 'id-a' ? newA : i ) ) ;
263
+
264
+ assert . deepStrictEqual ( single . collectDiff ( ) , [
265
+ { op : TestDiffOpType . Remove , itemId : new TestId ( [ 'ctrlId' , 'id-a' ] ) . toString ( ) } ,
266
+ {
267
+ op : TestDiffOpType . Add ,
268
+ item : { controllerId : 'ctrlId' , expand : TestItemExpandState . NotExpandable , item : { ...convert . TestItem . from ( newA ) } }
269
+ } ,
270
+ {
271
+ op : TestDiffOpType . Add ,
272
+ item : { controllerId : 'ctrlId' , expand : TestItemExpandState . NotExpandable , item : convert . TestItem . from ( newA . children . get ( 'id-aa' ) as TestItemImpl ) }
273
+ } ,
274
+ {
275
+ op : TestDiffOpType . Add ,
276
+ item : { controllerId : 'ctrlId' , expand : TestItemExpandState . NotExpandable , item : convert . TestItem . from ( newA . children . get ( 'id-ab' ) as TestItemImpl ) }
277
+ } ,
278
+ ] ) ;
279
+ } ) ;
280
+
254
281
test ( 'treats in-place replacement as mutation' , ( ) => {
255
282
single . expand ( single . root . id , Infinity ) ;
256
283
single . collectDiff ( ) ;
257
284
258
285
const oldA = single . root . children . get ( 'id-a' ) as TestItemImpl ;
259
- const newA = new TestItemImpl ( 'ctrlId' , 'id-a' , 'Hello world' , undefined ) ;
286
+ const uri = single . root . children . get ( 'id-a' ) ! . uri ;
287
+ const newA = new TestItemImpl ( 'ctrlId' , 'id-a' , 'Hello world' , uri ) ;
260
288
newA . children . replace ( [ ...oldA . children ] . map ( ( [ _ , item ] ) => item ) ) ;
261
289
single . root . children . replace ( [
262
290
newA ,
263
- new TestItemImpl ( 'ctrlId' , 'id-b' , single . root . children . get ( 'id-b' ) ! . label , undefined ) ,
291
+ new TestItemImpl ( 'ctrlId' , 'id-b' , single . root . children . get ( 'id-b' ) ! . label , uri ) ,
264
292
] ) ;
265
293
266
294
assert . deepStrictEqual ( single . collectDiff ( ) , [
267
295
{
268
296
op : TestDiffOpType . Update ,
269
297
item : { extId : new TestId ( [ 'ctrlId' , 'id-a' ] ) . toString ( ) , expand : TestItemExpandState . Expanded , item : { label : 'Hello world' } } ,
270
298
} ,
299
+ {
300
+ op : TestDiffOpType . DocumentSynced ,
301
+ docv : undefined ,
302
+ uri : uri
303
+ }
271
304
] ) ;
272
305
273
306
newA . label = 'still connected' ;
@@ -287,10 +320,11 @@ suite('ExtHost Testing', () => {
287
320
single . collectDiff ( ) ;
288
321
289
322
const oldA = single . root . children . get ( 'id-a' ) ! ;
290
- const newA = new TestItemImpl ( 'ctrlId' , 'id-a' , single . root . children . get ( 'id-a' ) ! . label , undefined ) ;
323
+ const uri = oldA . uri ;
324
+ const newA = new TestItemImpl ( 'ctrlId' , 'id-a' , single . root . children . get ( 'id-a' ) ! . label , uri ) ;
291
325
const oldAA = oldA . children . get ( 'id-aa' ) ! ;
292
326
const oldAB = oldA . children . get ( 'id-ab' ) ! ;
293
- const newAB = new TestItemImpl ( 'ctrlId' , 'id-ab' , 'Hello world' , undefined ) ;
327
+ const newAB = new TestItemImpl ( 'ctrlId' , 'id-ab' , 'Hello world' , uri ) ;
294
328
newA . children . replace ( [ oldAA , newAB ] ) ;
295
329
single . root . children . replace ( [ newA , single . root . children . get ( 'id-b' ) ! ] ) ;
296
330
@@ -303,6 +337,11 @@ suite('ExtHost Testing', () => {
303
337
op : TestDiffOpType . Update ,
304
338
item : { extId : TestId . fromExtHostTestItem ( oldAB , 'ctrlId' ) . toString ( ) , item : { label : 'Hello world' } } ,
305
339
} ,
340
+ {
341
+ op : TestDiffOpType . DocumentSynced ,
342
+ docv : undefined ,
343
+ uri : uri
344
+ }
306
345
] ) ;
307
346
308
347
oldAA . label = 'still connected1' ;
@@ -393,14 +432,15 @@ suite('ExtHost Testing', () => {
393
432
] ) ;
394
433
395
434
// sends on a child replacement
396
- const a2 = new TestItemImpl ( 'ctrlId' , 'id-a' , 'a' , URI . file ( '/' ) ) ;
435
+ const uri = URI . file ( '/' ) ;
436
+ const a2 = new TestItemImpl ( 'ctrlId' , 'id-a' , 'a' , uri ) ;
397
437
a2 . range = a . range ;
398
438
single . root . children . replace ( [ a2 , single . root . children . get ( 'id-b' ) ! ] ) ;
399
439
assert . deepStrictEqual ( single . collectDiff ( ) , [
400
440
{
401
441
op : TestDiffOpType . DocumentSynced ,
402
442
docv : undefined ,
403
- uri : URI . file ( '/' )
443
+ uri
404
444
} ,
405
445
] ) ;
406
446
} ) ;
0 commit comments