@@ -46,6 +46,7 @@ module ts {
4646 getCurrentDirectory : ( ) : string => {
4747 return "" ;
4848 } ,
49+ getEnvironmentVariable : ( name : string ) => "" ,
4950 readDirectory : ( path : string , extension ?: string , exclude ?: string [ ] ) : string [ ] => {
5051 throw new Error ( "NYI" ) ;
5152 } ,
@@ -79,8 +80,8 @@ module ts {
7980 let projectService = new server . ProjectService ( serverHost , logger ) ;
8081 let rootScriptInfo = projectService . openFile ( rootFile , /* openedByClient */ true ) ;
8182 let project = projectService . createInferredProject ( rootScriptInfo ) ;
82- project . setProjectOptions ( { files : [ rootScriptInfo . fileName ] , compilerOptions : { module : ts . ModuleKind . AMD } } ) ;
83- return {
83+ project . setProjectOptions ( { files : [ rootScriptInfo . fileName ] , compilerOptions : { module : ts . ModuleKind . AMD } } ) ;
84+ return {
8485 project,
8586 rootScriptInfo
8687 } ;
@@ -97,22 +98,22 @@ module ts {
9798 name : "c:/f1.ts" ,
9899 content : `foo()`
99100 } ;
100-
101+
101102 let serverHost = createDefaultServerHost ( { [ root . name ] : root , [ imported . name ] : imported } ) ;
102103 let { project, rootScriptInfo } = createProject ( root . name , serverHost ) ;
103104
104105 // ensure that imported file was found
105106 let diags = project . compilerService . languageService . getSemanticDiagnostics ( imported . name ) ;
106107 assert . equal ( diags . length , 1 ) ;
107-
108+
108109 let originalFileExists = serverHost . fileExists ;
109110 {
110111 // patch fileExists to make sure that disk is not touched
111112 serverHost . fileExists = ( fileName ) : boolean => {
112- assert . isTrue ( false , "fileExists should not be called" ) ;
113+ assert . isTrue ( false , "fileExists should not be called" ) ;
113114 return false ;
114115 } ;
115-
116+
116117 let newContent = `import {x} from "f1"
117118 var x: string = 1;` ;
118119 rootScriptInfo . editContent ( 0 , rootScriptInfo . content . length , newContent ) ;
@@ -133,7 +134,7 @@ module ts {
133134 } ;
134135 let newContent = `import {x} from "f2"` ;
135136 rootScriptInfo . editContent ( 0 , rootScriptInfo . content . length , newContent ) ;
136-
137+
137138 try {
138139 // trigger synchronization to make sure that LSHost will try to find 'f2' module on disk
139140 project . compilerService . languageService . getSemanticDiagnostics ( imported . name ) ;
@@ -142,53 +143,53 @@ module ts {
142143 catch ( e ) {
143144 assert . isTrue ( e . message . indexOf ( `Could not find file: '${ imported . name } '.` ) === 0 ) ;
144145 }
145-
146+
146147 assert . isTrue ( fileExistsIsCalled ) ;
147148 }
148149 {
149150 let fileExistsCalled = false ;
150151 serverHost . fileExists = ( fileName ) : boolean => {
151152 if ( fileName === "lib.d.ts" ) {
152153 return false ;
153- }
154+ }
154155 fileExistsCalled = true ;
155156 assert . isTrue ( fileName . indexOf ( '/f1.' ) !== - 1 ) ;
156157 return originalFileExists ( fileName ) ;
157158 } ;
158-
159+
159160 let newContent = `import {x} from "f1"` ;
160161 rootScriptInfo . editContent ( 0 , rootScriptInfo . content . length , newContent ) ;
161162 project . compilerService . languageService . getSemanticDiagnostics ( imported . name ) ;
162163 assert . isTrue ( fileExistsCalled ) ;
163-
164+
164165 // setting compiler options discards module resolution cache
165166 fileExistsCalled = false ;
166-
167+
167168 let opts = ts . clone ( project . projectOptions ) ;
168169 opts . compilerOptions = ts . clone ( opts . compilerOptions ) ;
169170 opts . compilerOptions . target = ts . ScriptTarget . ES5 ;
170171 project . setProjectOptions ( opts ) ;
171-
172+
172173 project . compilerService . languageService . getSemanticDiagnostics ( imported . name ) ;
173174 assert . isTrue ( fileExistsCalled ) ;
174175 }
175176 } ) ;
176-
177+
177178 it ( "loads missing files from disk" , ( ) => {
178179 let root : File = {
179180 name : 'c:/foo.ts' ,
180181 content : `import {x} from "bar"`
181182 } ;
182-
183+
183184 let imported : File = {
184185 name : 'c:/bar.d.ts' ,
185186 content : `export var y = 1`
186- } ;
187-
187+ } ;
188+
188189 let fileMap : Map < File > = { [ root . name ] : root } ;
189190 let serverHost = createDefaultServerHost ( fileMap ) ;
190191 let originalFileExists = serverHost . fileExists ;
191-
192+
192193 let fileExistsCalledForBar = false ;
193194 serverHost . fileExists = fileName => {
194195 if ( fileName === "lib.d.ts" ) {
@@ -197,22 +198,22 @@ module ts {
197198 if ( ! fileExistsCalledForBar ) {
198199 fileExistsCalledForBar = fileName . indexOf ( "/bar." ) !== - 1 ;
199200 }
200-
201+
201202 return originalFileExists ( fileName ) ;
202203 } ;
203-
204+
204205 let { project, rootScriptInfo } = createProject ( root . name , serverHost ) ;
205206
206207 let diags = project . compilerService . languageService . getSemanticDiagnostics ( root . name ) ;
207208 assert . isTrue ( fileExistsCalledForBar , "'fileExists' should be called" ) ;
208209 assert . isTrue ( diags . length === 1 , "one diagnostic expected" ) ;
209210 assert . isTrue ( typeof diags [ 0 ] . messageText === "string" && ( ( < string > diags [ 0 ] . messageText ) . indexOf ( "Cannot find module" ) === 0 ) , "should be 'cannot find module' message" ) ;
210-
211+
211212 // assert that import will success once file appear on disk
212213 fileMap [ imported . name ] = imported ;
213214 fileExistsCalledForBar = false ;
214215 rootScriptInfo . editContent ( 0 , rootScriptInfo . content . length , `import {y} from "bar"` )
215-
216+
216217 diags = project . compilerService . languageService . getSemanticDiagnostics ( root . name ) ;
217218 assert . isTrue ( fileExistsCalledForBar , "'fileExists' should be called" ) ;
218219 assert . isTrue ( diags . length === 0 ) ;
0 commit comments