From 9e5e20c80fdb4e8bbccfec437f4ab498db59d381 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Thu, 31 Aug 2017 17:58:09 -0700 Subject: [PATCH] Remove the configured project if on next open file if it has no open files instead of immediately when closing last open file --- src/server/editorServices.ts | 17 +++++++++++++---- src/server/project.ts | 4 ++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index e6784942c66..0679ccd8393 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -878,10 +878,10 @@ namespace ts.server { if (info.hasMixedContent) { info.registerFileUpdate(); } - // last open file in configured project - close it - if ((p).deleteOpenRef() === 0) { - (projectsToRemove || (projectsToRemove = [])).push(p); - } + // Delete the reference to the open configured projects but + // do not remove the project so that we can reuse this project + // if it would need to be re-created with next file open + (p).deleteOpenRef(); } else if (p.projectKind === ProjectKind.Inferred && p.isRoot(info)) { // If this was the open root file of inferred project @@ -1881,6 +1881,15 @@ namespace ts.server { } this.addToListOfOpenFiles(info); + // Remove the configured projects that have zero references from open files. + // This was postponed from closeOpenFile to after opening next file, + // so that we can reuse the project if we need to right away + this.configuredProjects.forEach(project => { + if (!project.hasOpenRef()) { + this.removeProject(project); + } + }); + // Delete the orphan files here because there might be orphan script infos (which are not part of project) // when some file/s were closed which resulted in project removal. // It was then postponed to cleanup these script infos so that they can be reused if diff --git a/src/server/project.ts b/src/server/project.ts index 24b3cd03de4..37b0bb3cd7f 100644 --- a/src/server/project.ts +++ b/src/server/project.ts @@ -1311,6 +1311,10 @@ namespace ts.server { return this.openRefCount; } + hasOpenRef() { + return !!this.openRefCount; + } + getEffectiveTypeRoots() { return getEffectiveTypeRoots(this.getCompilationSettings(), this.partialSystem) || []; }