mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-29 16:29:19 -05:00
addref in all configured projects that contain the file
This commit is contained in:
@@ -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 });
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user