From ee95afeaf828659104681f1c14f0934dd022ee0f Mon Sep 17 00:00:00 2001 From: Zhengbo Li Date: Thu, 13 Oct 2016 15:39:09 -0700 Subject: [PATCH] Port #11601 to release-2.0.5 * Avoid watching non-existing directories and fix null-exception * Add test * Move the fix to sys to cover tsc -w also --- src/compiler/sys.ts | 4 +++ .../unittests/tsserverProjectSystem.ts | 29 +++++++++++++++++++ src/server/editorServices.ts | 2 +- 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index ea858e21fbf..318573cd5f3 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -470,6 +470,10 @@ namespace ts { // Node 4.0 `fs.watch` function supports the "recursive" option on both OSX and Windows // (ref: https://github.com/nodejs/node/pull/2649 and https://github.com/Microsoft/TypeScript/issues/4643) let options: any; + if (!directoryExists(directoryName)) { + return; + } + if (isNode4OrLater() && (process.platform === "win32" || process.platform === "darwin")) { options = { persistent: true, recursive: !!recursive }; } diff --git a/src/harness/unittests/tsserverProjectSystem.ts b/src/harness/unittests/tsserverProjectSystem.ts index b12a8675613..4251430ce4d 100644 --- a/src/harness/unittests/tsserverProjectSystem.ts +++ b/src/harness/unittests/tsserverProjectSystem.ts @@ -2162,4 +2162,33 @@ namespace ts.projectSystem { serverEventManager.checkEventCountOfType("configFileDiag", 1); }); }); + + describe("non-existing directories listed in config file input array", () => { + it("should be tolerated without crashing the server", () => { + const configFile = { + path: "/a/b/tsconfig.json", + content: `{ + "compilerOptions": {}, + "include": ["app/*", "test/**/*", "something"] + }` + }; + const file1 = { + path: "/a/b/file1.ts", + content: "let t = 10;" + }; + + const host = createServerHost([file1, configFile]); + const projectService = createProjectService(host); + projectService.openClientFile(file1.path); + host.runQueuedTimeoutCallbacks(); + checkNumberOfConfiguredProjects(projectService, 1); + checkNumberOfInferredProjects(projectService, 1); + + const configuredProject = projectService.configuredProjects[0]; + assert.isTrue(configuredProject.getFileNames().length == 0); + + const inferredProject = projectService.inferredProjects[0]; + assert.isTrue(inferredProject.containsFile(file1.path)); + }); + }); } \ No newline at end of file diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index e10b7e8b2cf..c0a8b496077 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -706,7 +706,7 @@ namespace ts.server { Debug.assert(!!parsedCommandLine.fileNames); if (parsedCommandLine.fileNames.length === 0) { - errors.push(createCompilerDiagnostic(Diagnostics.The_config_file_0_found_doesn_t_contain_any_source_files, configFilename)); + (errors || (errors = [])).push(createCompilerDiagnostic(Diagnostics.The_config_file_0_found_doesn_t_contain_any_source_files, configFilename)); return { success: false, configFileErrors: errors }; }