@@ -169,11 +169,18 @@ namespace ts.projectSystem {
169169 return host ;
170170 }
171171
172+ class TestSession extends server . Session {
173+ getProjectService ( ) {
174+ return this . projectService ;
175+ }
176+ } ;
177+
172178 export function createSession ( host : server . ServerHost , typingsInstaller ?: server . ITypingsInstaller , projectServiceEventHandler ?: server . ProjectServiceEventHandler ) {
173179 if ( typingsInstaller === undefined ) {
174180 typingsInstaller = new TestTypingsInstaller ( "/a/data/" , /*throttleLimit*/ 5 , host ) ;
175181 }
176- return new server . Session ( host , nullCancellationToken , /*useSingleInferredProject*/ false , typingsInstaller , Utils . byteLength , process . hrtime , nullLogger , /*canUseEvents*/ projectServiceEventHandler !== undefined , projectServiceEventHandler ) ;
182+
183+ return new TestSession ( host , nullCancellationToken , /*useSingleInferredProject*/ false , typingsInstaller , Utils . byteLength , process . hrtime , nullLogger , /*canUseEvents*/ projectServiceEventHandler !== undefined , projectServiceEventHandler ) ;
177184 }
178185
179186 export interface CreateProjectServiceParameters {
@@ -533,12 +540,13 @@ namespace ts.projectSystem {
533540 this . reloadFS ( filesOrFolders ) ;
534541 }
535542
543+ write ( s : string ) {
544+ }
545+
536546 readonly readFile = ( s : string ) => ( < File > this . fs . get ( this . toPath ( s ) ) ) . content ;
537547 readonly resolvePath = ( s : string ) => s ;
538548 readonly getExecutingFilePath = ( ) => this . executingFilePath ;
539549 readonly getCurrentDirectory = ( ) => this . currentDirectory ;
540- readonly writeCompressedData = ( ) => notImplemented ( ) ;
541- readonly write = ( s : string ) => notImplemented ( ) ;
542550 readonly exit = ( ) => notImplemented ( ) ;
543551 }
544552
@@ -2191,4 +2199,53 @@ namespace ts.projectSystem {
21912199 assert . isTrue ( inferredProject . containsFile ( < server . NormalizedPath > file1 . path ) ) ;
21922200 } ) ;
21932201 } ) ;
2202+
2203+ describe ( "reload" , ( ) => {
2204+ it ( "should work with temp file" , ( ) => {
2205+ const f1 = {
2206+ path : "/a/b/app.ts" ,
2207+ content : "let x = 1"
2208+ } ;
2209+ const tmp = {
2210+ path : "/a/b/app.tmp" ,
2211+ content : "const y = 42"
2212+ } ;
2213+ const host = createServerHost ( [ f1 , tmp ] ) ;
2214+ const session = createSession ( host ) ;
2215+
2216+ // send open request
2217+ session . executeCommand ( < server . protocol . OpenRequest > {
2218+ type : "request" ,
2219+ command : "open" ,
2220+ seq : 1 ,
2221+ arguments : { file : f1 . path }
2222+ } ) ;
2223+
2224+ // reload from tmp file
2225+ session . executeCommand ( < server . protocol . ReloadRequest > {
2226+ type : "request" ,
2227+ command : "reload" ,
2228+ seq : 2 ,
2229+ arguments : { file : f1 . path , tmpfile : tmp . path }
2230+ } ) ;
2231+
2232+ // verify content
2233+ const projectServiice = session . getProjectService ( ) ;
2234+ const snap1 = projectServiice . getScriptInfo ( f1 . path ) . snap ( ) ;
2235+ assert . equal ( snap1 . getText ( 0 , snap1 . getLength ( ) ) , tmp . content , "content should be equal to the content of temp file" ) ;
2236+
2237+ // reload from original file file
2238+ session . executeCommand ( < server . protocol . ReloadRequest > {
2239+ type : "request" ,
2240+ command : "reload" ,
2241+ seq : 2 ,
2242+ arguments : { file : f1 . path }
2243+ } ) ;
2244+
2245+ // verify content
2246+ const snap2 = projectServiice . getScriptInfo ( f1 . path ) . snap ( ) ;
2247+ assert . equal ( snap2 . getText ( 0 , snap2 . getLength ( ) ) , f1 . content , "content should be equal to the content of original file" ) ;
2248+
2249+ } ) ;
2250+ } ) ;
21942251}
0 commit comments