diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 2916fb60c57..40c196009e3 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -832,6 +832,9 @@ namespace ts.server { this.logger.info(`remove project: ${project.getRootFiles().toString()}`); project.close(); + if (Debug.shouldAssert(AssertionLevel.Normal)) { + this.filenameToScriptInfo.forEach(info => Debug.assert(!info.isAttached(project))); + } // Remove the project from pending project updates this.pendingProjectUpdates.delete(project.getProjectName()); diff --git a/src/server/project.ts b/src/server/project.ts index 5132b82a804..e8bfd7c1b75 100644 --- a/src/server/project.ts +++ b/src/server/project.ts @@ -497,12 +497,7 @@ namespace ts.server { if (this.program) { // if we have a program - release all files that are enlisted in program for (const f of this.program.getSourceFiles()) { - const info = this.projectService.getScriptInfo(f.fileName); - // We might not find the script info in case its not associated with the project any more - // and project graph was not updated (eg delayed update graph in case of files changed/deleted on the disk) - if (info) { - info.detachFromProject(this); - } + this.detachScriptInfo(f.fileName); } } if (!this.program || !this.languageServiceEnabled) { @@ -512,10 +507,13 @@ namespace ts.server { root.detachFromProject(this); } } + this.rootFiles = undefined; this.rootFilesMap = undefined; this.program = undefined; this.builder = undefined; + forEach(this.externalFiles, externalFile => this.detachScriptInfo(externalFile)); + this.externalFiles = undefined; this.resolutionCache.clear(); this.resolutionCache = undefined; this.cachedUnresolvedImportsPerFile = undefined; @@ -532,6 +530,15 @@ namespace ts.server { this.languageService = undefined; } + private detachScriptInfo(uncheckedFilename: string) { + const info = this.projectService.getScriptInfo(uncheckedFilename); + // We might not find the script info in case its not associated with the project any more + // and project graph was not updated (eg delayed update graph in case of files changed/deleted on the disk) + if (info) { + info.detachFromProject(this); + } + } + isClosed() { return this.rootFiles === undefined; } @@ -791,7 +798,7 @@ namespace ts.server { private updateGraphWorker() { const oldProgram = this.program; - + Debug.assert(!this.isClosed(), "Called update graph worker of closed project"); this.writeLog(`Starting updateGraphWorker: Project: ${this.getProjectName()}`); const start = timestamp(); this.hasInvalidatedResolution = this.resolutionCache.createHasInvalidatedResolution();