detach root files on project close if project language service is disabled (#13077)

This commit is contained in:
Vladimir Matveev 2016-12-20 19:25:25 -08:00 committed by GitHub
parent c90af3aa94
commit 1045f3bffb
2 changed files with 38 additions and 2 deletions

View file

@ -1840,6 +1840,41 @@ namespace ts.projectSystem {
assert.isFalse(service.externalProjects[0].languageServiceEnabled, "language service should be disabled - 2");
});
it("files are properly detached when language service is disabled", () => {
const f1 = {
path: "/a/app.js",
content: "var x = 1"
};
const f2 = {
path: "/a/largefile.js",
content: ""
};
const f3 = {
path: "/a/lib.js",
content: "var x = 1"
};
const config = {
path: "/a/tsconfig.json",
content: JSON.stringify({ compilerOptions: { allowJs: true } })
};
const host = createServerHost([f1, f2, f3, config]);
const originalGetFileSize = host.getFileSize;
host.getFileSize = (filePath: string) =>
filePath === f2.path ? server.maxProgramSizeForNonTsFiles + 1 : originalGetFileSize.call(host, filePath);
const projectService = createProjectService(host);
projectService.openClientFile(f1.path);
projectService.checkNumberOfProjects({ configuredProjects: 1 });
projectService.closeClientFile(f1.path);
projectService.checkNumberOfProjects({});
for (const f of [f2, f3]) {
const scriptInfo = projectService.getScriptInfoForNormalizedPath(server.toNormalizedPath(f.path));
assert.equal(scriptInfo.containingProjects.length, 0, `expect 0 containing projects for '${f.path}'`)
}
});
it("language service disabled events are triggered", () => {
const f1 = {
path: "/a/app.js",

View file

@ -257,8 +257,9 @@ namespace ts.server {
info.detachFromProject(this);
}
}
else {
// release all root files
if (!this.program || !this.languageServiceEnabled) {
// release all root files either if there is no program or language service is disabled.
// in the latter case set of root files can be larger than the set of files in program.
for (const root of this.rootFiles) {
root.detachFromProject(this);
}