@@ -88,7 +88,7 @@ interface Array<T> {}`
88
88
}
89
89
90
90
interface Folder extends FSEntry {
91
- entries : FSEntry [ ] ;
91
+ entries : SortedArray < FSEntry > ;
92
92
}
93
93
94
94
interface SymLink extends FSEntry {
@@ -276,12 +276,14 @@ interface Array<T> {}`
276
276
DynamicPolling = "RecursiveDirectoryUsingDynamicPriorityPolling"
277
277
}
278
278
279
+ const timeIncrements = 1000 ;
279
280
export class TestServerHost implements server . ServerHost , FormatDiagnosticsHost , ModuleResolutionHost {
280
281
args : string [ ] = [ ] ;
281
282
282
283
private readonly output : string [ ] = [ ] ;
283
284
284
285
private fs : Map < FSEntry > = createMap < FSEntry > ( ) ;
286
+ private time = timeIncrements ;
285
287
getCanonicalFileName : ( s : string ) => string ;
286
288
private toPath : ( f : string ) => Path ;
287
289
private timeoutCallbacks = new Callbacks ( ) ;
@@ -310,28 +312,31 @@ interface Array<T> {}`
310
312
const watchDirectory : HostWatchDirectory = ( directory , cb ) => this . watchFile ( directory , ( ) => cb ( directory ) , PollingInterval . Medium ) ;
311
313
this . customRecursiveWatchDirectory = createRecursiveDirectoryWatcher ( {
312
314
directoryExists : path => this . directoryExists ( path ) ,
313
- getAccessileSortedChildDirectories : path => this . getDirectories ( path ) ,
315
+ getAccessibleSortedChildDirectories : path => this . getDirectories ( path ) ,
314
316
filePathComparer : this . useCaseSensitiveFileNames ? compareStringsCaseSensitive : compareStringsCaseInsensitive ,
315
- watchDirectory
317
+ watchDirectory,
318
+ realpath : s => this . realpath ( s )
316
319
} ) ;
317
320
}
318
321
else if ( tscWatchDirectory === Tsc_WatchDirectory . NonRecursiveWatchDirectory ) {
319
322
const watchDirectory : HostWatchDirectory = ( directory , cb ) => this . watchDirectory ( directory , fileName => cb ( fileName ) , /*recursive*/ false ) ;
320
323
this . customRecursiveWatchDirectory = createRecursiveDirectoryWatcher ( {
321
324
directoryExists : path => this . directoryExists ( path ) ,
322
- getAccessileSortedChildDirectories : path => this . getDirectories ( path ) ,
325
+ getAccessibleSortedChildDirectories : path => this . getDirectories ( path ) ,
323
326
filePathComparer : this . useCaseSensitiveFileNames ? compareStringsCaseSensitive : compareStringsCaseInsensitive ,
324
- watchDirectory
327
+ watchDirectory,
328
+ realpath : s => this . realpath ( s )
325
329
} ) ;
326
330
}
327
331
else if ( tscWatchDirectory === Tsc_WatchDirectory . DynamicPolling ) {
328
332
const watchFile = createDynamicPriorityPollingWatchFile ( this ) ;
329
333
const watchDirectory : HostWatchDirectory = ( directory , cb ) => watchFile ( directory , ( ) => cb ( directory ) , PollingInterval . Medium ) ;
330
334
this . customRecursiveWatchDirectory = createRecursiveDirectoryWatcher ( {
331
335
directoryExists : path => this . directoryExists ( path ) ,
332
- getAccessileSortedChildDirectories : path => this . getDirectories ( path ) ,
336
+ getAccessibleSortedChildDirectories : path => this . getDirectories ( path ) ,
333
337
filePathComparer : this . useCaseSensitiveFileNames ? compareStringsCaseSensitive : compareStringsCaseInsensitive ,
334
- watchDirectory
338
+ watchDirectory,
339
+ realpath : s => this . realpath ( s )
335
340
} ) ;
336
341
}
337
342
}
@@ -355,6 +360,11 @@ interface Array<T> {}`
355
360
return s ;
356
361
}
357
362
363
+ private now ( ) {
364
+ this . time += timeIncrements ;
365
+ return new Date ( this . time ) ;
366
+ }
367
+
358
368
reloadFS ( fileOrFolderList : ReadonlyArray < FileOrFolder > , options ?: Partial < ReloadWatchInvokeOptions > ) {
359
369
const mapNewLeaves = createMap < true > ( ) ;
360
370
const isNewFs = this . fs . size === 0 ;
@@ -381,8 +391,8 @@ interface Array<T> {}`
381
391
}
382
392
else {
383
393
currentEntry . content = fileOrDirectory . content ;
384
- currentEntry . modifiedTime = new Date ( ) ;
385
- this . fs . get ( getDirectoryPath ( currentEntry . path ) ) . modifiedTime = new Date ( ) ;
394
+ currentEntry . modifiedTime = this . now ( ) ;
395
+ this . fs . get ( getDirectoryPath ( currentEntry . path ) ) . modifiedTime = this . now ( ) ;
386
396
if ( options && options . invokeDirectoryWatcherInsteadOfFileChanged ) {
387
397
this . invokeDirectoryWatcher ( getDirectoryPath ( currentEntry . fullPath ) , currentEntry . fullPath ) ;
388
398
}
@@ -406,7 +416,7 @@ interface Array<T> {}`
406
416
}
407
417
else {
408
418
// Folder update: Nothing to do.
409
- currentEntry . modifiedTime = new Date ( ) ;
419
+ currentEntry . modifiedTime = this . now ( ) ;
410
420
}
411
421
}
412
422
}
@@ -512,8 +522,8 @@ interface Array<T> {}`
512
522
}
513
523
514
524
private addFileOrFolderInFolder ( folder : Folder , fileOrDirectory : File | Folder | SymLink , ignoreWatch ?: boolean ) {
515
- folder . entries . push ( fileOrDirectory ) ;
516
- folder . modifiedTime = new Date ( ) ;
525
+ insertSorted ( folder . entries , fileOrDirectory , ( a , b ) => compareStringsCaseSensitive ( getBaseFileName ( a . path ) , getBaseFileName ( b . path ) ) ) ;
526
+ folder . modifiedTime = this . now ( ) ;
517
527
this . fs . set ( fileOrDirectory . path , fileOrDirectory ) ;
518
528
519
529
if ( ignoreWatch ) {
@@ -528,7 +538,7 @@ interface Array<T> {}`
528
538
const baseFolder = this . fs . get ( basePath ) as Folder ;
529
539
if ( basePath !== fileOrDirectory . path ) {
530
540
Debug . assert ( ! ! baseFolder ) ;
531
- baseFolder . modifiedTime = new Date ( ) ;
541
+ baseFolder . modifiedTime = this . now ( ) ;
532
542
filterMutate ( baseFolder . entries , entry => entry !== fileOrDirectory ) ;
533
543
}
534
544
this . fs . delete ( fileOrDirectory . path ) ;
@@ -603,7 +613,7 @@ interface Array<T> {}`
603
613
return {
604
614
path : this . toPath ( fullPath ) ,
605
615
fullPath,
606
- modifiedTime : new Date ( )
616
+ modifiedTime : this . now ( )
607
617
} ;
608
618
}
609
619
@@ -622,7 +632,7 @@ interface Array<T> {}`
622
632
623
633
private toFolder ( path : string ) : Folder {
624
634
const folder = this . toFsEntry ( path ) as Folder ;
625
- folder . entries = [ ] ;
635
+ folder . entries = [ ] as SortedArray < FSEntry > ;
626
636
return folder ;
627
637
}
628
638
@@ -642,7 +652,7 @@ interface Array<T> {}`
642
652
643
653
const realpath = this . realpath ( path ) ;
644
654
if ( path !== realpath ) {
645
- return this . getRealFsEntry ( isFsEntry , realpath as Path ) ;
655
+ return this . getRealFsEntry ( isFsEntry , this . toPath ( realpath ) ) ;
646
656
}
647
657
648
658
return undefined ;
0 commit comments