Handle if reading tsconfig file fails (#37563)

Fixes #36862
This commit is contained in:
Sheetal Nandi 2020-03-25 10:14:31 -07:00 committed by GitHub
parent a1c8608f68
commit b7b2c333a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 1 deletions

View File

@ -1974,7 +1974,7 @@ namespace ts.server {
// Read updated contents from disk
const configFilename = normalizePath(project.getConfigFilePath());
const configFileContent = this.host.readFile(configFilename)!; // TODO: GH#18217
const configFileContent = this.host.readFile(configFilename) || "";
const result = parseJsonText(configFilename, configFileContent);
if (!result.endOfFileToken) {

View File

@ -1233,4 +1233,27 @@ declare var console: {
checkWatchedDirectories(host, watchedRecursiveDirectories, /*recursive*/ true);
});
});
describe("unittests:: tsserver:: ConfiguredProjects:: when reading tsconfig file fails", () => {
it("should be tolerated without crashing the server", () => {
const configFile = {
path: `${tscWatch.projectRoot}/tsconfig.json`,
content: ""
};
const file1 = {
path: `${tscWatch.projectRoot}/file1.ts`,
content: "let t = 10;"
};
const host = createServerHost([file1, configFile]);
const projectService = createProjectService(host);
const originalReadFile = host.readFile;
host.readFile = f => {
return f === configFile.path ?
undefined :
originalReadFile.call(host, f);
};
projectService.openClientFile(file1.path);
});
});
}