@@ -23,46 +23,39 @@ namespace Bridge {
23
23
24
24
private documentRegistry : ts . DocumentRegistry ;
25
25
private exportedFolderNames : { [ projectName : string ] : string [ ] } ;
26
- private fileInfos : { [ fileName : string ] : FileInfo } ;
26
+ private projectFileInfos : { [ projectName : string ] : { [ fileName : string ] : FileInfo } } ;
27
+ private allFileInfos : { [ fileName : string ] : FileInfo } ;
27
28
private languageServices : { [ serviceKey : string ] : ts . LanguageService } ;
28
- private sourceFolderNames : { [ projectName : string ] : string [ ] } ;
29
29
30
30
constructor ( ) {
31
31
this . documentRegistry = ts . createDocumentRegistry ( ) ;
32
32
this . exportedFolderNames = Object . create ( null ) ;
33
- this . fileInfos = Object . create ( null ) ;
33
+ this . allFileInfos = Object . create ( null ) ;
34
34
this . languageServices = Object . create ( null ) ;
35
- this . sourceFolderNames = Object . create ( null ) ;
35
+ this . projectFileInfos = Object . create ( null ) ;
36
36
}
37
37
38
38
public cleanProject ( projectName : string ) {
39
39
if ( this . isProjectInitialized ( projectName ) ) {
40
- // delete the project's files
41
- Object . getOwnPropertyNames ( this . fileInfos ) . forEach ( ( fileName ) => {
42
- if ( this . isSourceFile ( projectName , fileName ) || this . isExportedFile ( projectName , fileName ) ) {
43
- delete this . fileInfos [ fileName ] ;
44
- }
45
- } ) ;
46
40
47
41
delete this . exportedFolderNames [ projectName ] ;
42
+ delete this . projectFileInfos [ projectName ] ;
48
43
delete this . languageServices [ projectName ] ;
49
- delete this . sourceFolderNames [ projectName ] ;
50
44
}
51
45
}
52
46
53
47
public initializeProject (
54
- projectName : string ,
55
- compilationSettings : ts . CompilerOptions ,
56
- referencedProjectNames : string [ ] ,
57
- exportedFolderNames : string [ ] ,
58
- sourceFolderNames : string [ ] ,
59
- files : { [ fileName : string ] : string } ) {
48
+ projectName : string ,
49
+ compilationSettings : ts . CompilerOptions ,
50
+ referencedProjectNames : string [ ] ,
51
+ exportedFolderNames : string [ ] ,
52
+ files : { [ fileName : string ] : string } ) {
60
53
61
54
this . cleanProject ( projectName ) ;
62
55
this . exportedFolderNames [ projectName ] = exportedFolderNames ;
63
- this . sourceFolderNames [ projectName ] = sourceFolderNames ;
56
+
64
57
this . languageServices [ projectName ] = this . createProjectLanguageService ( projectName , compilationSettings , referencedProjectNames ) ;
65
- this . addFiles ( files ) ;
58
+ this . addFiles ( projectName , files ) ;
66
59
}
67
60
68
61
public isProjectInitialized ( projectName : string ) {
@@ -72,18 +65,17 @@ namespace Bridge {
72
65
public initializeIsolatedLanguageService ( serviceKey : string , fileName : string , fileContents : string ) {
73
66
this . languageServices [ serviceKey ] = this . createIsolatedLanguageService ( fileName ) ;
74
67
75
- this . fileInfos [ fileName ] = new FileInfo ( fileContents , null ) ;
68
+ this . allFileInfos [ fileName ] = new FileInfo ( fileContents , null , null ) ;
76
69
}
77
70
78
71
public closeIsolatedLanguageService ( serviceKey : string , fileName : string ) {
79
- delete this . fileInfos [ fileName ] ;
72
+ delete this . allFileInfos [ fileName ] ;
80
73
delete this . languageServices [ serviceKey ] ;
81
74
}
82
75
83
76
public getAllTodoComments ( projectName : string ) {
84
77
var todos : { [ fileName : string ] : TodoCommentEx [ ] } = { } ;
85
- Object . keys ( this . fileInfos )
86
- . filter ( ( fileName ) => this . isSourceFile ( projectName , fileName ) )
78
+ Object . keys ( this . getProjectFileInfos ( projectName ) )
87
79
. forEach ( ( fileName ) => {
88
80
todos [ fileName ] = this . getTodoComments ( projectName , fileName ) ;
89
81
} ) ;
@@ -93,8 +85,7 @@ namespace Bridge {
93
85
public getAllDiagnostics ( projectName : string ) {
94
86
var diagnostics : { [ fileName : string ] : DiagnosticEx [ ] } = Object . create ( null ) ;
95
87
96
- Object . keys ( this . fileInfos )
97
- . filter ( ( fileName ) => this . isSourceFile ( projectName , fileName ) )
88
+ Object . keys ( this . getProjectFileInfos ( projectName ) )
98
89
. forEach ( ( fileName ) => {
99
90
diagnostics [ fileName ] = this . getDiagnostics ( projectName , fileName , true ) ;
100
91
} ) ;
@@ -103,6 +94,7 @@ namespace Bridge {
103
94
}
104
95
105
96
public getDiagnostics ( serviceKey : string , fileName : string , semantic : boolean ) : DiagnosticEx [ ] {
97
+
106
98
var diagnostics = this . languageServices [ serviceKey ] . getSyntacticDiagnostics ( fileName ) ;
107
99
108
100
if ( semantic && diagnostics . length === 0 ) {
@@ -237,11 +229,11 @@ namespace Bridge {
237
229
}
238
230
239
231
public editFile ( fileName : string , offset : number , length : number , text : string ) {
240
- this . fileInfos [ fileName ] . editContents ( offset , length , text ) ;
232
+ this . allFileInfos [ fileName ] . editContents ( offset , length , text ) ;
241
233
}
242
234
243
235
public setFileOpen ( fileName : string , open : boolean ) {
244
- var fileInfo = this . fileInfos [ fileName ] ;
236
+ var fileInfo = this . allFileInfos [ fileName ] ;
245
237
246
238
// the file may have been deleted previously, so only process this call if the file exists
247
239
if ( fileInfo != null ) {
@@ -250,21 +242,21 @@ namespace Bridge {
250
242
}
251
243
252
244
public setLibContents ( libContents : string , libES6Contents : string ) {
253
- var libFileInfo = new FileInfo ( libContents , null ) ;
254
- this . fileInfos [ LIB_FILE_NAME ] = libFileInfo ;
245
+ var libFileInfo = new FileInfo ( libContents , null , null ) ;
246
+ this . allFileInfos [ LIB_FILE_NAME ] = libFileInfo ;
255
247
256
- var libES6FileInfo = new FileInfo ( libES6Contents , null ) ;
257
- this . fileInfos [ LIB_ES6_FILE_NAME ] = libES6FileInfo ;
248
+ var libES6FileInfo = new FileInfo ( libES6Contents , null , null ) ;
249
+ this . allFileInfos [ LIB_ES6_FILE_NAME ] = libES6FileInfo ;
258
250
}
259
251
260
- public updateFiles ( deltas : IFileDelta [ ] ) {
252
+ public updateFiles ( projectName : string , deltas : IFileDelta [ ] ) {
261
253
deltas . forEach ( ( delta ) => {
262
254
var fileName = delta . fileName ;
263
255
264
256
switch ( delta . delta ) {
265
257
case "ADDED" :
266
258
case "CHANGED" :
267
- var fileInfo = this . fileInfos [ fileName ] ;
259
+ var fileInfo = this . allFileInfos [ fileName ] ;
268
260
269
261
if ( fileInfo !== undefined ) {
270
262
// only update files not currently open in an editor
@@ -277,19 +269,23 @@ namespace Bridge {
277
269
var filePath = delta . filePath ;
278
270
var contents = readFileContents ( filePath ) ;
279
271
280
- fileInfo = new FileInfo ( contents , filePath ) ;
281
-
282
- this . fileInfos [ fileName ] = fileInfo ;
272
+ this . pushFile ( projectName , fileName , contents , filePath ) ;
283
273
}
284
274
break ;
285
275
case "REMOVED" :
286
- delete this . fileInfos [ fileName ] ;
276
+ var fileInfo : FileInfo = this . allFileInfos [ fileName ] ;
277
+ if ( fileInfo != null ) {
278
+ delete this . allFileInfos [ fileName ] ;
279
+ if ( fileInfo . getProjectName ( ) != null ) {
280
+ delete this . getProjectFileInfos ( fileInfo . getProjectName ( ) ) [ fileName ] ;
281
+ }
282
+ }
287
283
break ;
288
284
}
289
285
} ) ;
290
286
}
291
287
292
- private addFiles ( files : { [ fileName : string ] : string } ) {
288
+ private addFiles ( projectName : string , files : { [ fileName : string ] : string } ) {
293
289
for ( var fileName in files ) {
294
290
if ( files . hasOwnProperty ( fileName ) ) {
295
291
var filePath = files [ fileName ] ;
@@ -303,14 +299,29 @@ namespace Bridge {
303
299
}
304
300
305
301
// cache the file
306
- var fileInfo = new FileInfo ( contents , filePath ) ;
307
- this . fileInfos [ fileName ] = fileInfo ;
302
+ this . pushFile ( projectName , fileName , contents , filePath ) ;
308
303
}
309
304
}
310
305
}
311
306
312
- private createLanguageService ( compilationSettings : ts . CompilerOptions , fileFilter : ( fileName : string ) => boolean ) {
313
- var host = new LanguageServiceHost ( compilationSettings , fileFilter , this . fileInfos ) ;
307
+ private pushFile ( projectName : string , fileName : string , contents : string , filePath : string ) : void {
308
+ var fileInfo = new FileInfo ( contents , filePath , projectName ) ;
309
+ this . getProjectFileInfos ( projectName ) [ fileName ] = fileInfo ;
310
+ this . allFileInfos [ fileName ] = fileInfo ;
311
+ }
312
+
313
+ private getProjectFileInfos ( projectName : string ) : { [ fileName : string ] : FileInfo } {
314
+ if ( this . projectFileInfos [ projectName ] == null ) {
315
+ this . projectFileInfos [ projectName ] = Object . create ( null ) ;
316
+ }
317
+
318
+ return this . projectFileInfos [ projectName ] ;
319
+ }
320
+
321
+ private createLanguageService (
322
+ compilationSettings : ts . CompilerOptions ,
323
+ fileFilter : ( fileName : string ) => boolean ) {
324
+ var host = new LanguageServiceHost ( compilationSettings , fileFilter , this . allFileInfos ) ;
314
325
315
326
return ts . createLanguageService ( host , this . documentRegistry ) ;
316
327
}
@@ -351,9 +362,8 @@ namespace Bridge {
351
362
}
352
363
353
364
private isSourceFile ( projectName : string , fileName : string ) {
354
- return this . sourceFolderNames [ projectName ] . some ( ( sourceFolderName ) => {
355
- return folderContains ( sourceFolderName , fileName ) ;
356
- } ) ;
365
+ var projectSourceFiles : { [ fileName : string ] : FileInfo } = this . getProjectFileInfos ( projectName ) ;
366
+ return projectSourceFiles [ fileName ] != null ;
357
367
}
358
368
}
359
369
0 commit comments