Skip to content

Commit 9e5e20c

Browse files
committed
Remove the configured project if on next open file if it has no open files instead of immediately when closing last open file
1 parent 8d5d4c2 commit 9e5e20c

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/server/editorServices.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -878,10 +878,10 @@ namespace ts.server {
878878
if (info.hasMixedContent) {
879879
info.registerFileUpdate();
880880
}
881-
// last open file in configured project - close it
882-
if ((<ConfiguredProject>p).deleteOpenRef() === 0) {
883-
(projectsToRemove || (projectsToRemove = [])).push(p);
884-
}
881+
// Delete the reference to the open configured projects but
882+
// do not remove the project so that we can reuse this project
883+
// if it would need to be re-created with next file open
884+
(<ConfiguredProject>p).deleteOpenRef();
885885
}
886886
else if (p.projectKind === ProjectKind.Inferred && p.isRoot(info)) {
887887
// If this was the open root file of inferred project
@@ -1881,6 +1881,15 @@ namespace ts.server {
18811881
}
18821882
this.addToListOfOpenFiles(info);
18831883

1884+
// Remove the configured projects that have zero references from open files.
1885+
// This was postponed from closeOpenFile to after opening next file,
1886+
// so that we can reuse the project if we need to right away
1887+
this.configuredProjects.forEach(project => {
1888+
if (!project.hasOpenRef()) {
1889+
this.removeProject(project);
1890+
}
1891+
});
1892+
18841893
// Delete the orphan files here because there might be orphan script infos (which are not part of project)
18851894
// when some file/s were closed which resulted in project removal.
18861895
// It was then postponed to cleanup these script infos so that they can be reused if

src/server/project.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,6 +1311,10 @@ namespace ts.server {
13111311
return this.openRefCount;
13121312
}
13131313

1314+
hasOpenRef() {
1315+
return !!this.openRefCount;
1316+
}
1317+
13141318
getEffectiveTypeRoots() {
13151319
return getEffectiveTypeRoots(this.getCompilationSettings(), this.partialSystem) || [];
13161320
}

0 commit comments

Comments
 (0)