Skip to content

Commit 70b7bd5

Browse files
authored
Merge pull request microsoft#32490 from microsoft/assertFix
Fix the assert of reporting scriptinfos with JSON.stringify when removing projet with script infos still attached to it
2 parents e543d8b + aab3069 commit 70b7bd5

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

src/server/editorServices.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1087,7 +1087,24 @@ namespace ts.server {
10871087

10881088
project.close();
10891089
if (Debug.shouldAssert(AssertionLevel.Normal)) {
1090-
this.filenameToScriptInfo.forEach(info => Debug.assert(!info.isAttached(project), "Found script Info still attached to project", () => `${project.projectName}: ScriptInfos still attached: ${JSON.stringify(mapDefined(arrayFrom(this.filenameToScriptInfo.values()), info => info.isAttached(project) ? info : undefined))}`));
1090+
this.filenameToScriptInfo.forEach(info => Debug.assert(
1091+
!info.isAttached(project),
1092+
"Found script Info still attached to project",
1093+
() => `${project.projectName}: ScriptInfos still attached: ${JSON.stringify(
1094+
arrayFrom(
1095+
mapDefinedIterator(
1096+
this.filenameToScriptInfo.values(),
1097+
info => info.isAttached(project) ?
1098+
{
1099+
fileName: info.fileName,
1100+
projects: info.containingProjects.map(p => p.projectName),
1101+
hasMixedContent: info.hasMixedContent
1102+
} : undefined
1103+
)
1104+
),
1105+
/*replacer*/ undefined,
1106+
" "
1107+
)}`));
10911108
}
10921109
// Remove the project from pending project updates
10931110
this.pendingProjectUpdates.delete(project.getProjectName());

src/testRunner/unittests/tsserver/projects.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,5 +1467,22 @@ var x = 10;`
14671467
openFilesForSession([{ file, projectRootPath }], session);
14681468
}
14691469
});
1470+
1471+
it("assert when removing project", () => {
1472+
const host = createServerHost([commonFile1, commonFile2, libFile]);
1473+
const service = createProjectService(host);
1474+
service.openClientFile(commonFile1.path);
1475+
const project = service.inferredProjects[0];
1476+
checkProjectActualFiles(project, [commonFile1.path, libFile.path]);
1477+
// Intentionally create scriptinfo and attach it to project
1478+
const info = service.getOrCreateScriptInfoForNormalizedPath(commonFile2.path as server.NormalizedPath, /*openedByClient*/ false)!;
1479+
info.attachToProject(project);
1480+
try {
1481+
service.applyChangesInOpenFiles(/*openFiles*/ undefined, /*changedFiles*/ undefined, [commonFile1.path]);
1482+
}
1483+
catch (e) {
1484+
assert.isTrue(e.message.indexOf("Debug Failure. False expression: Found script Info still attached to project") === 0);
1485+
}
1486+
});
14701487
});
14711488
}

0 commit comments

Comments
 (0)