@@ -93,6 +93,10 @@ namespace ts.server {
93
93
return this . fileInfos_doNotAccessDirectly || ( this . fileInfos_doNotAccessDirectly = createFileMap < T > ( ) ) ;
94
94
}
95
95
96
+ protected hasFileInfos ( ) {
97
+ return ! ! this . fileInfos_doNotAccessDirectly ;
98
+ }
99
+
96
100
public clear ( ) {
97
101
// drop the existing list - it will be re-created as necessary
98
102
this . fileInfos_doNotAccessDirectly = undefined ;
@@ -130,11 +134,13 @@ namespace ts.server {
130
134
131
135
abstract getFilesAffectedBy ( scriptInfo : ScriptInfo ) : string [ ] ;
132
136
abstract onProjectUpdateGraph ( ) : void ;
137
+ protected abstract ensureFileInfoIfInProject ( scriptInfo : ScriptInfo ) : void ;
133
138
134
139
/**
135
140
* @returns {boolean } whether the emit was conducted or not
136
141
*/
137
142
emitFile ( scriptInfo : ScriptInfo , writeFile : ( path : string , data : string , writeByteOrderMark ?: boolean ) => void ) : boolean {
143
+ this . ensureFileInfoIfInProject ( scriptInfo ) ;
138
144
const fileInfo = this . getFileInfo ( scriptInfo . path ) ;
139
145
if ( ! fileInfo ) {
140
146
return false ;
@@ -158,7 +164,21 @@ namespace ts.server {
158
164
super ( project , BuilderFileInfo ) ;
159
165
}
160
166
167
+ protected ensureFileInfoIfInProject ( scriptInfo : ScriptInfo ) {
168
+ if ( this . project . containsScriptInfo ( scriptInfo ) ) {
169
+ this . getOrCreateFileInfo ( scriptInfo . path ) ;
170
+ }
171
+ }
172
+
161
173
onProjectUpdateGraph ( ) {
174
+ if ( this . hasFileInfos ( ) ) {
175
+ this . forEachFileInfo ( fileInfo => {
176
+ if ( ! this . project . containsScriptInfo ( fileInfo . scriptInfo ) ) {
177
+ // This file was deleted from this project
178
+ this . removeFileInfo ( fileInfo . scriptInfo . path ) ;
179
+ }
180
+ } ) ;
181
+ }
162
182
}
163
183
164
184
/**
@@ -262,10 +282,17 @@ namespace ts.server {
262
282
return [ ] ;
263
283
}
264
284
265
- onProjectUpdateGraph ( ) {
285
+ protected ensureFileInfoIfInProject ( _scriptInfo : ScriptInfo ) {
266
286
this . ensureProjectDependencyGraphUpToDate ( ) ;
267
287
}
268
288
289
+ onProjectUpdateGraph ( ) {
290
+ // Update the graph only if we have computed graph earlier
291
+ if ( this . hasFileInfos ( ) ) {
292
+ this . ensureProjectDependencyGraphUpToDate ( ) ;
293
+ }
294
+ }
295
+
269
296
private ensureProjectDependencyGraphUpToDate ( ) {
270
297
if ( ! this . projectVersionForDependencyGraph || this . project . getProjectVersion ( ) !== this . projectVersionForDependencyGraph ) {
271
298
const currentScriptInfos = this . project . getScriptInfos ( ) ;
@@ -386,4 +413,4 @@ namespace ts.server {
386
413
return new ModuleBuilder ( project ) ;
387
414
}
388
415
}
389
- }
416
+ }
0 commit comments