Skip to content

Commit 8c38cbf

Browse files
authored
Merge pull request #9073 from zhengbli/i8523
Increase project reference count even when the opened file is referenced by it but not its root
2 parents 9a2cf11 + 1e7790d commit 8c38cbf

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/server/editorServices.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,7 @@ namespace ts.server {
807807
else {
808808
this.findReferencingProjects(info);
809809
if (info.defaultProject) {
810+
info.defaultProject.addOpenRef();
810811
this.openFilesReferenced.push(info);
811812
}
812813
else {

tests/cases/unittests/tsserverProjectSystem.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,5 +567,32 @@ namespace ts {
567567
checkConfiguredProjectActualFiles(project, [file1.path, classicModuleFile.path]);
568568
checkNumberOfInferredProjects(projectService, 1);
569569
});
570+
571+
it("should keep the configured project when the opened file is referenced by the project but not its root", () => {
572+
const file1: FileOrFolder = {
573+
path: "/a/b/main.ts",
574+
content: "import { objA } from './obj-a';"
575+
};
576+
const file2: FileOrFolder = {
577+
path: "/a/b/obj-a.ts",
578+
content: `export const objA = Object.assign({foo: "bar"}, {bar: "baz"});`
579+
};
580+
const configFile: FileOrFolder = {
581+
path: "/a/b/tsconfig.json",
582+
content: `{
583+
"compilerOptions": {
584+
"target": "es6"
585+
},
586+
"files": [ "main.ts" ]
587+
}`
588+
};
589+
const host = new TestServerHost(/*useCaseSensitiveFileNames*/ false, getExecutingFilePathFromLibFile(libFile), "/", [file1, file2, configFile]);
590+
const projectService = new server.ProjectService(host, nullLogger);
591+
projectService.openClientFile(file1.path);
592+
projectService.closeClientFile(file1.path);
593+
projectService.openClientFile(file2.path);
594+
checkNumberOfConfiguredProjects(projectService, 1);
595+
checkNumberOfInferredProjects(projectService, 0);
596+
});
570597
});
571598
}

0 commit comments

Comments
 (0)