addref in all configured projects that contain the file

This commit is contained in:
Vladimir Matveev
2016-08-04 14:46:00 -07:00
parent c0bcf8f10c
commit 0a1ec43de0
2 changed files with 56 additions and 12 deletions

View File

@@ -1362,5 +1362,50 @@ namespace ts {
projectService.inferredProjects[0].getLanguageService(/*ensureSynchronized*/ false).getOutliningSpans(file1.path);
projectService.closeClientFile(file1.path);
});
it("File in multiple projects at opened and closed correctly", () => {
const file1 = {
path: "/a/b/app.ts",
content: "let x = 1;"
};
const file2 = {
path: "/a/c/f.ts",
content: `/// <reference path="../b/app.ts"/>`
};
const tsconfig1 = {
path: "/a/c/tsconfig.json",
content: "{}"
};
const tsconfig2 = {
path: "/a/b/tsconfig.json",
content: "{}"
};
const host = createServerHost([file1, file2, tsconfig1, tsconfig2]);
const projectService = new server.ProjectService(host, nullLogger, nullCancellationToken, /*useSingleInferredProject*/ false);
projectService.openClientFile(file2.path);
checkNumberOfProjects(projectService, { configuredProjects: 1 });
const project1 = projectService.configuredProjects[0];
assert.equal(project1.openRefCount, 1, "Open ref count in project1 - 1");
assert.equal(project1.getScriptInfo(file2.path).containingProjects.length, 1, "containing projects count");
projectService.openClientFile(file1.path);
checkNumberOfProjects(projectService, { configuredProjects: 2 });
assert.equal(project1.openRefCount, 2, "Open ref count in project1 - 2");
const project2 = projectService.configuredProjects[1];
assert.equal(project2.openRefCount, 1, "Open ref count in project2 - 2");
assert.equal(project1.getScriptInfo(file1.path).containingProjects.length, 2, `${file1.path} containing projects count`);
assert.equal(project1.getScriptInfo(file2.path).containingProjects.length, 1, `${file2.path} containing projects count`);
projectService.closeClientFile(file2.path);
checkNumberOfProjects(projectService, { configuredProjects: 2 });
assert.equal(project1.openRefCount, 1, "Open ref count in project1 - 3");
assert.equal(project2.openRefCount, 1, "Open ref count in project2 - 3");
projectService.closeClientFile(file1.path);
checkNumberOfProjects(projectService, { configuredProjects: 0 });
});
});
}

View File

@@ -244,15 +244,6 @@ namespace ts.server {
}
}
private findContainingConfiguredProject(info: ScriptInfo): ConfiguredProject {
for (const proj of this.configuredProjects) {
if (proj.containsScriptInfo(info)) {
return proj;
}
}
return undefined;
}
private findContainingExternalProject(fileName: NormalizedPath): ExternalProject {
for (const proj of this.externalProjects) {
if (proj.containsFile(fileName)) {
@@ -424,11 +415,19 @@ namespace ts.server {
}
return;
}
const configuredProject = this.findContainingConfiguredProject(info);
if (configuredProject) {
let foundConfiguredProject = false;
for (const p of info.containingProjects) {
// file is the part of configured project
if (p.projectKind === ProjectKind.Configured) {
foundConfiguredProject = true;
if (addToListOfOpenFiles) {
((<ConfiguredProject>p)).addOpenRef();
}
}
}
if (foundConfiguredProject) {
if (addToListOfOpenFiles) {
configuredProject.addOpenRef();
this.openFiles.push(info);
}
return;