Skip to content

Commit

Permalink
Merge pull request #32490 from microsoft/assertFix
Browse files Browse the repository at this point in the history
Fix the assert of reporting scriptinfos with JSON.stringify when removing projet with script infos still attached to it
  • Loading branch information
sheetalkamat authored Jul 20, 2019
2 parents e543d8b + aab3069 commit 70b7bd5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/server/editorServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1087,7 +1087,24 @@ namespace ts.server {

project.close();
if (Debug.shouldAssert(AssertionLevel.Normal)) {
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))}`));
this.filenameToScriptInfo.forEach(info => Debug.assert(
!info.isAttached(project),
"Found script Info still attached to project",
() => `${project.projectName}: ScriptInfos still attached: ${JSON.stringify(
arrayFrom(
mapDefinedIterator(
this.filenameToScriptInfo.values(),
info => info.isAttached(project) ?
{
fileName: info.fileName,
projects: info.containingProjects.map(p => p.projectName),
hasMixedContent: info.hasMixedContent
} : undefined
)
),
/*replacer*/ undefined,
" "
)}`));
}
// Remove the project from pending project updates
this.pendingProjectUpdates.delete(project.getProjectName());
Expand Down
17 changes: 17 additions & 0 deletions src/testRunner/unittests/tsserver/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1467,5 +1467,22 @@ var x = 10;`
openFilesForSession([{ file, projectRootPath }], session);
}
});

it("assert when removing project", () => {
const host = createServerHost([commonFile1, commonFile2, libFile]);
const service = createProjectService(host);
service.openClientFile(commonFile1.path);
const project = service.inferredProjects[0];
checkProjectActualFiles(project, [commonFile1.path, libFile.path]);
// Intentionally create scriptinfo and attach it to project
const info = service.getOrCreateScriptInfoForNormalizedPath(commonFile2.path as server.NormalizedPath, /*openedByClient*/ false)!;
info.attachToProject(project);
try {
service.applyChangesInOpenFiles(/*openFiles*/ undefined, /*changedFiles*/ undefined, [commonFile1.path]);
}
catch (e) {
assert.isTrue(e.message.indexOf("Debug Failure. False expression: Found script Info still attached to project") === 0);
}
});
});
}

0 comments on commit 70b7bd5

Please sign in to comment.