From 6bde4b5c02e1ab44517f3ff2ca1387654c72be05 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Thu, 29 Oct 2020 12:18:43 -0700 Subject: [PATCH] Fix missing file name of extended source file in synchronizeProjectList when it is missing on disk (#41222) Fixes #40136 --- src/compiler/commandLineParser.ts | 2 +- src/testRunner/unittests/tsserver/projects.ts | 42 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 117410246d9..56cc83516e5 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -1578,7 +1578,7 @@ namespace ts { */ export function readJsonConfigFile(fileName: string, readFile: (path: string) => string | undefined): TsConfigSourceFile { const textOrDiagnostic = tryReadFile(fileName, readFile); - return isString(textOrDiagnostic) ? parseJsonText(fileName, textOrDiagnostic) : { parseDiagnostics: [textOrDiagnostic] }; + return isString(textOrDiagnostic) ? parseJsonText(fileName, textOrDiagnostic) : { fileName, parseDiagnostics: [textOrDiagnostic] }; } /*@internal*/ diff --git a/src/testRunner/unittests/tsserver/projects.ts b/src/testRunner/unittests/tsserver/projects.ts index 2de2da67af3..0afe37c4639 100644 --- a/src/testRunner/unittests/tsserver/projects.ts +++ b/src/testRunner/unittests/tsserver/projects.ts @@ -1481,6 +1481,48 @@ namespace ts.projectSystem { ]); }); + it("synchronizeProjectList returns correct information when base configuration file cannot be resolved", () => { + const file: File = { + path: `${tscWatch.projectRoot}/index.ts`, + content: "export const foo = 5;" + }; + const config: File = { + path: `${tscWatch.projectRoot}/tsconfig.json`, + content: JSON.stringify({ extends: "./tsconfig_base.json" }) + }; + const host = createServerHost([file, config, libFile]); + const projectService = createProjectService(host); + projectService.openClientFile(file.path); + const knownProjects = projectService.synchronizeProjectList([], /*includeProjectReferenceRedirectInfo*/ false); + assert.deepEqual(knownProjects[0].files, [ + libFile.path, + file.path, + config.path, + `${tscWatch.projectRoot}/tsconfig_base.json`, + ]); + }); + + it("synchronizeProjectList returns correct information when base configuration file cannot be resolved and redirect info is requested", () => { + const file: File = { + path: `${tscWatch.projectRoot}/index.ts`, + content: "export const foo = 5;" + }; + const config: File = { + path: `${tscWatch.projectRoot}/tsconfig.json`, + content: JSON.stringify({ extends: "./tsconfig_base.json" }) + }; + const host = createServerHost([file, config, libFile]); + const projectService = createProjectService(host); + projectService.openClientFile(file.path); + const knownProjects = projectService.synchronizeProjectList([], /*includeProjectReferenceRedirectInfo*/ true); + assert.deepEqual(knownProjects[0].files, [ + { fileName: libFile.path, isSourceOfProjectReferenceRedirect: false }, + { fileName: file.path, isSourceOfProjectReferenceRedirect: false }, + { fileName: config.path, isSourceOfProjectReferenceRedirect: false }, + { fileName: `${tscWatch.projectRoot}/tsconfig_base.json`, isSourceOfProjectReferenceRedirect: false }, + ]); + }); + it("handles delayed directory watch invoke on file creation", () => { const projectRootPath = "/users/username/projects/project"; const fileB: File = {