@@ -170,11 +170,18 @@ namespace ts.projectSystem {
170
170
return host ;
171
171
}
172
172
173
+ class TestSession extends server . Session {
174
+ getProjectService ( ) {
175
+ return this . projectService ;
176
+ }
177
+ } ;
178
+
173
179
export function createSession ( host : server . ServerHost , typingsInstaller ?: server . ITypingsInstaller , projectServiceEventHandler ?: server . ProjectServiceEventHandler ) {
174
180
if ( typingsInstaller === undefined ) {
175
181
typingsInstaller = new TestTypingsInstaller ( "/a/data/" , /*throttleLimit*/ 5 , host ) ;
176
182
}
177
- return new server . Session ( host , nullCancellationToken , /*useSingleInferredProject*/ false , typingsInstaller , Utils . byteLength , process . hrtime , nullLogger , /*canUseEvents*/ projectServiceEventHandler !== undefined , projectServiceEventHandler ) ;
183
+
184
+ return new TestSession ( host , nullCancellationToken , /*useSingleInferredProject*/ false , typingsInstaller , Utils . byteLength , process . hrtime , nullLogger , /*canUseEvents*/ projectServiceEventHandler !== undefined , projectServiceEventHandler ) ;
178
185
}
179
186
180
187
export interface CreateProjectServiceParameters {
@@ -515,11 +522,13 @@ namespace ts.projectSystem {
515
522
this . reloadFS ( filesOrFolders ) ;
516
523
}
517
524
525
+ write ( s : string ) {
526
+ }
527
+
518
528
readonly readFile = ( s : string ) => ( < File > this . fs . get ( this . toPath ( s ) ) ) . content ;
519
529
readonly resolvePath = ( s : string ) => s ;
520
530
readonly getExecutingFilePath = ( ) => this . executingFilePath ;
521
531
readonly getCurrentDirectory = ( ) => this . currentDirectory ;
522
- readonly write = ( s : string ) => notImplemented ( ) ;
523
532
readonly exit = ( ) => notImplemented ( ) ;
524
533
readonly getEnvironmentVariable = ( v : string ) => notImplemented ( ) ;
525
534
}
@@ -2420,4 +2429,53 @@ namespace ts.projectSystem {
2420
2429
assert . isTrue ( inferredProject . containsFile ( < server . NormalizedPath > file1 . path ) ) ;
2421
2430
} ) ;
2422
2431
} ) ;
2432
+
2433
+ describe ( "reload" , ( ) => {
2434
+ it ( "should work with temp file" , ( ) => {
2435
+ const f1 = {
2436
+ path : "/a/b/app.ts" ,
2437
+ content : "let x = 1"
2438
+ } ;
2439
+ const tmp = {
2440
+ path : "/a/b/app.tmp" ,
2441
+ content : "const y = 42"
2442
+ } ;
2443
+ const host = createServerHost ( [ f1 , tmp ] ) ;
2444
+ const session = createSession ( host ) ;
2445
+
2446
+ // send open request
2447
+ session . executeCommand ( < server . protocol . OpenRequest > {
2448
+ type : "request" ,
2449
+ command : "open" ,
2450
+ seq : 1 ,
2451
+ arguments : { file : f1 . path }
2452
+ } ) ;
2453
+
2454
+ // reload from tmp file
2455
+ session . executeCommand ( < server . protocol . ReloadRequest > {
2456
+ type : "request" ,
2457
+ command : "reload" ,
2458
+ seq : 2 ,
2459
+ arguments : { file : f1 . path , tmpfile : tmp . path }
2460
+ } ) ;
2461
+
2462
+ // verify content
2463
+ const projectServiice = session . getProjectService ( ) ;
2464
+ const snap1 = projectServiice . getScriptInfo ( f1 . path ) . snap ( ) ;
2465
+ assert . equal ( snap1 . getText ( 0 , snap1 . getLength ( ) ) , tmp . content , "content should be equal to the content of temp file" ) ;
2466
+
2467
+ // reload from original file file
2468
+ session . executeCommand ( < server . protocol . ReloadRequest > {
2469
+ type : "request" ,
2470
+ command : "reload" ,
2471
+ seq : 2 ,
2472
+ arguments : { file : f1 . path }
2473
+ } ) ;
2474
+
2475
+ // verify content
2476
+ const snap2 = projectServiice . getScriptInfo ( f1 . path ) . snap ( ) ;
2477
+ assert . equal ( snap2 . getText ( 0 , snap2 . getLength ( ) ) , f1 . content , "content should be equal to the content of original file" ) ;
2478
+
2479
+ } ) ;
2480
+ } ) ;
2423
2481
}
0 commit comments