From 0a1ec43de0887721022774deb68c6ebfc3e8c158 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Thu, 4 Aug 2016 14:46:00 -0700 Subject: [PATCH] addref in all configured projects that contain the file --- .../unittests/tsserverProjectSystem.ts | 45 +++++++++++++++++++ src/server/editorServices.ts | 23 +++++----- 2 files changed, 56 insertions(+), 12 deletions(-) diff --git a/src/harness/unittests/tsserverProjectSystem.ts b/src/harness/unittests/tsserverProjectSystem.ts index a5e39735eae..31fed86d83d 100644 --- a/src/harness/unittests/tsserverProjectSystem.ts +++ b/src/harness/unittests/tsserverProjectSystem.ts @@ -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: `/// ` + }; + 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 }); + }); }); } \ No newline at end of file diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index af4c5b3b766..f61d7d6b497 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -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) { + ((p)).addOpenRef(); + } + } + } + if (foundConfiguredProject) { if (addToListOfOpenFiles) { - configuredProject.addOpenRef(); this.openFiles.push(info); } return;