mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-16 05:58:32 -06:00
more tests
This commit is contained in:
parent
07817fedb0
commit
83afa3fb94
@ -373,10 +373,16 @@ namespace ts.server {
|
||||
const inferredProject = this.createInferredProjectWithRootFileIfNecessary(info);
|
||||
if (!this.useSingleInferredProject) {
|
||||
// if useOneInferredProject is not set then try to fixup ownership of open files
|
||||
// check 'defaultProject !== inferredProject' is necessary to handle cases
|
||||
// when creation inferred project for some file has added other open files into this project (i.e. as referenced files)
|
||||
// we definitely don't want to delete the project that was just created
|
||||
for (const f of this.openFiles) {
|
||||
if (f.containingProjects.length === 0) {
|
||||
// this is orphaned file that we have not processed yet - skip it
|
||||
continue;
|
||||
}
|
||||
const defaultProject = f.getDefaultProject();
|
||||
if (isRootFileInInferredProject(info) && defaultProject !== inferredProject && inferredProject.containsScriptInfo(f)) {
|
||||
|
||||
// open file used to be root in inferred project,
|
||||
// this inferred project is different from the one we've just created for current file
|
||||
// and new inferred project references this open file.
|
||||
|
||||
@ -1039,5 +1039,41 @@ namespace ts {
|
||||
checkNumberOfProjects(projectService, { configuredProjects: 1 });
|
||||
checkProjectActualFiles(projectService.configuredProjects[0], [ file1.path, file2.path, file3.path ]);
|
||||
});
|
||||
|
||||
it("correctly migrate files between projects", () => {
|
||||
const file1 = {
|
||||
path: "/a/b/f1.ts",
|
||||
content: `
|
||||
export * from "../c/f2.ts";
|
||||
export * from "../d/f3.ts";`
|
||||
};
|
||||
const file2 = {
|
||||
path: "/a/c/f2.ts",
|
||||
content: "export let x = 1;"
|
||||
};
|
||||
const file3 = {
|
||||
path: "/a/d/f3.ts",
|
||||
content: "export let y = 1;"
|
||||
};
|
||||
const host = createServerHost([file1, file2, file3]);
|
||||
const projectService = new server.ProjectService(host, nullLogger, nullCancellationToken, /*useSingleInferredProject*/ false);
|
||||
|
||||
projectService.openClientFile(file2.path);
|
||||
checkNumberOfProjects(projectService, { inferredProjects: 1 });
|
||||
checkProjectActualFiles(projectService.inferredProjects[0], [file2.path]);
|
||||
|
||||
projectService.openClientFile(file3.path);
|
||||
checkNumberOfProjects(projectService, { inferredProjects: 2 });
|
||||
checkProjectActualFiles(projectService.inferredProjects[0], [file2.path]);
|
||||
checkProjectActualFiles(projectService.inferredProjects[1], [file3.path]);
|
||||
|
||||
projectService.openClientFile(file1.path);
|
||||
checkNumberOfProjects(projectService, { inferredProjects: 1 });
|
||||
checkProjectRootFiles(projectService.inferredProjects[0], [file1.path]);
|
||||
checkProjectActualFiles(projectService.inferredProjects[0], [file1.path, file2.path, file3.path]);
|
||||
|
||||
projectService.closeClientFile(file1.path);
|
||||
checkNumberOfProjects(projectService, { inferredProjects: 2 });
|
||||
});
|
||||
});
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user