@@ -169,11 +169,18 @@ namespace ts.projectSystem {
169
169
return host ;
170
170
}
171
171
172
+ class TestSession extends server . Session {
173
+ getProjectService ( ) {
174
+ return this . projectService ;
175
+ }
176
+ } ;
177
+
172
178
export function createSession ( host : server . ServerHost , typingsInstaller ?: server . ITypingsInstaller , projectServiceEventHandler ?: server . ProjectServiceEventHandler ) {
173
179
if ( typingsInstaller === undefined ) {
174
180
typingsInstaller = new TestTypingsInstaller ( "/a/data/" , /*throttleLimit*/ 5 , host ) ;
175
181
}
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 ) ;
177
184
}
178
185
179
186
export interface CreateProjectServiceParameters {
@@ -533,12 +540,13 @@ namespace ts.projectSystem {
533
540
this . reloadFS ( filesOrFolders ) ;
534
541
}
535
542
543
+ write ( s : string ) {
544
+ }
545
+
536
546
readonly readFile = ( s : string ) => ( < File > this . fs . get ( this . toPath ( s ) ) ) . content ;
537
547
readonly resolvePath = ( s : string ) => s ;
538
548
readonly getExecutingFilePath = ( ) => this . executingFilePath ;
539
549
readonly getCurrentDirectory = ( ) => this . currentDirectory ;
540
- readonly writeCompressedData = ( ) => notImplemented ( ) ;
541
- readonly write = ( s : string ) => notImplemented ( ) ;
542
550
readonly exit = ( ) => notImplemented ( ) ;
543
551
}
544
552
@@ -2191,4 +2199,53 @@ namespace ts.projectSystem {
2191
2199
assert . isTrue ( inferredProject . containsFile ( < server . NormalizedPath > file1 . path ) ) ;
2192
2200
} ) ;
2193
2201
} ) ;
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
+ } ) ;
2194
2251
}
0 commit comments