Skip to content

Commit a34cf58

Browse files
sheetalkamatrbuckton
authored andcommitted
Update the builder dependency graph only if it was created.
This makes sure that we dont create this graph just because project was updated
1 parent 50abee3 commit a34cf58

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

src/server/builder.ts

+29-2
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ namespace ts.server {
9393
return this.fileInfos_doNotAccessDirectly || (this.fileInfos_doNotAccessDirectly = createFileMap<T>());
9494
}
9595

96+
protected hasFileInfos() {
97+
return !!this.fileInfos_doNotAccessDirectly;
98+
}
99+
96100
public clear() {
97101
// drop the existing list - it will be re-created as necessary
98102
this.fileInfos_doNotAccessDirectly = undefined;
@@ -130,11 +134,13 @@ namespace ts.server {
130134

131135
abstract getFilesAffectedBy(scriptInfo: ScriptInfo): string[];
132136
abstract onProjectUpdateGraph(): void;
137+
protected abstract ensureFileInfoIfInProject(scriptInfo: ScriptInfo): void;
133138

134139
/**
135140
* @returns {boolean} whether the emit was conducted or not
136141
*/
137142
emitFile(scriptInfo: ScriptInfo, writeFile: (path: string, data: string, writeByteOrderMark?: boolean) => void): boolean {
143+
this.ensureFileInfoIfInProject(scriptInfo);
138144
const fileInfo = this.getFileInfo(scriptInfo.path);
139145
if (!fileInfo) {
140146
return false;
@@ -158,7 +164,21 @@ namespace ts.server {
158164
super(project, BuilderFileInfo);
159165
}
160166

167+
protected ensureFileInfoIfInProject(scriptInfo: ScriptInfo) {
168+
if (this.project.containsScriptInfo(scriptInfo)) {
169+
this.getOrCreateFileInfo(scriptInfo.path);
170+
}
171+
}
172+
161173
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+
}
162182
}
163183

164184
/**
@@ -262,10 +282,17 @@ namespace ts.server {
262282
return [];
263283
}
264284

265-
onProjectUpdateGraph() {
285+
protected ensureFileInfoIfInProject(_scriptInfo: ScriptInfo) {
266286
this.ensureProjectDependencyGraphUpToDate();
267287
}
268288

289+
onProjectUpdateGraph() {
290+
// Update the graph only if we have computed graph earlier
291+
if (this.hasFileInfos()) {
292+
this.ensureProjectDependencyGraphUpToDate();
293+
}
294+
}
295+
269296
private ensureProjectDependencyGraphUpToDate() {
270297
if (!this.projectVersionForDependencyGraph || this.project.getProjectVersion() !== this.projectVersionForDependencyGraph) {
271298
const currentScriptInfos = this.project.getScriptInfos();
@@ -386,4 +413,4 @@ namespace ts.server {
386413
return new ModuleBuilder(project);
387414
}
388415
}
389-
}
416+
}

0 commit comments

Comments
 (0)