Skip to content

Commit 1e7790d

Browse files
committed
Fix #8523
1 parent 6687f2c commit 1e7790d

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
@@ -803,6 +803,7 @@ namespace ts.server {
803803
else {
804804
this.findReferencingProjects(info);
805805
if (info.defaultProject) {
806+
info.defaultProject.addOpenRef();
806807
this.openFilesReferenced.push(info);
807808
}
808809
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)