Skip to content

Commit be2e8e8

Browse files
authored
property handle missing config files in external projects (#12094)
1 parent 0173a3f commit be2e8e8

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/harness/unittests/tsserverProjectSystem.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2249,6 +2249,27 @@ namespace ts.projectSystem {
22492249
assert.equal(diags.length, 0);
22502250
});
22512251

2252+
it("should property handle missing config files", () => {
2253+
const f1 = {
2254+
path: "/a/b/app.ts",
2255+
content: "let x = 1"
2256+
};
2257+
const config = {
2258+
path: "/a/b/tsconfig.json",
2259+
content: "{}"
2260+
};
2261+
const projectName = "project1";
2262+
const host = createServerHost([f1]);
2263+
const projectService = createProjectService(host);
2264+
projectService.openExternalProject({ rootFiles: toExternalFiles([f1.path, config.path]), options: {}, projectFileName: projectName });
2265+
2266+
// should have one external project since config file is missing
2267+
projectService.checkNumberOfProjects({ externalProjects: 1 });
2268+
2269+
host.reloadFS([f1, config]);
2270+
projectService.openExternalProject({ rootFiles: toExternalFiles([f1.path, config.path]), options: {}, projectFileName: projectName });
2271+
projectService.checkNumberOfProjects({ configuredProjects: 1 });
2272+
});
22522273
});
22532274

22542275
describe("add the missing module file for inferred project", () => {

src/server/editorServices.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1288,7 +1288,9 @@ namespace ts.server {
12881288
for (const file of proj.rootFiles) {
12891289
const normalized = toNormalizedPath(file.fileName);
12901290
if (getBaseFileName(normalized) === "tsconfig.json") {
1291-
(tsConfigFiles || (tsConfigFiles = [])).push(normalized);
1291+
if (this.host.fileExists(normalized)) {
1292+
(tsConfigFiles || (tsConfigFiles = [])).push(normalized);
1293+
}
12921294
}
12931295
else {
12941296
rootFiles.push(file);

0 commit comments

Comments
 (0)