mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-11 06:02:53 -05:00
Assert if the script info that is attached to closed project is present
Adds assertion to investigate #19003 and #18928
This commit is contained in:
@@ -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());
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user