From 8fee60cc21c86c31e2d85464140b4556e4f12ad5 Mon Sep 17 00:00:00 2001 From: zhengbli Date: Fri, 18 Nov 2016 17:21:29 -0800 Subject: [PATCH] report config errors when config file changed --- .../unittests/tsserverProjectSystem.ts | 37 +++++++++++++++++++ src/server/editorServices.ts | 12 ++++-- 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/src/harness/unittests/tsserverProjectSystem.ts b/src/harness/unittests/tsserverProjectSystem.ts index e9b6ccb788401..bf7be965b503f 100644 --- a/src/harness/unittests/tsserverProjectSystem.ts +++ b/src/harness/unittests/tsserverProjectSystem.ts @@ -2452,6 +2452,43 @@ namespace ts.projectSystem { openFilesForSession([file], session); serverEventManager.checkEventCountOfType("configFileDiag", 1); }); + + it("are generated when the config file changes", () => { + const serverEventManager = new TestServerEventManager(); + const file = { + path: "/a/b/app.ts", + content: "let x = 10" + }; + const configFile = { + path: "/a/b/tsconfig.json", + content: `{ + "compilerOptions": {} + }` + }; + + const host = createServerHost([file, configFile]); + const session = createSession(host, /*typingsInstaller*/ undefined, serverEventManager.handler); + openFilesForSession([file], session); + serverEventManager.checkEventCountOfType("configFileDiag", 1); + + configFile.content = `{ + "compilerOptions": { + "haha": 123 + } + }`; + host.reloadFS([file, configFile]); + host.triggerFileWatcherCallback(configFile.path); + host.runQueuedTimeoutCallbacks(); + serverEventManager.checkEventCountOfType("configFileDiag", 2); + + configFile.content = `{ + "compilerOptions": {} + }`; + host.reloadFS([file, configFile]); + host.triggerFileWatcherCallback(configFile.path); + host.runQueuedTimeoutCallbacks(); + serverEventManager.checkEventCountOfType("configFileDiag", 3); + }); }); describe("skipLibCheck", () => { diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 6a7cb049296c7..2a0e78eaccce7 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -520,8 +520,10 @@ namespace ts.server { } private onConfigChangedForConfiguredProject(project: ConfiguredProject) { - this.logger.info(`Config file changed: ${project.getConfigFilePath()}`); - this.updateConfiguredProject(project); + const configFileName = project.getConfigFilePath(); + this.logger.info(`Config file changed: ${configFileName}`); + const configFileErrors = this.updateConfiguredProject(project); + this.reportConfigFileDiagnostics(configFileName, configFileErrors, /*triggerFile*/ configFileName); this.refreshInferredProjects(); } @@ -1015,6 +1017,9 @@ namespace ts.server { return; } + // note: the returned "success" is true does not mean the "configFileErrors" is empty. + // because we might have tolerated the errors and kept going. So always return the configFileErrors + // regardless the "success" here is true or not. const { success, projectOptions, configFileErrors } = this.convertConfigFileContentToProjectOptions(project.getConfigFilePath()); if (!success) { // reset project settings to default @@ -1026,7 +1031,7 @@ namespace ts.server { project.setCompilerOptions(projectOptions.compilerOptions); if (!project.languageServiceEnabled) { // language service is already disabled - return; + return configFileErrors; } project.disableLanguageService(); project.stopWatchingDirectory(); @@ -1038,6 +1043,7 @@ namespace ts.server { this.watchConfigDirectoryForProject(project, projectOptions); this.updateNonInferredProject(project, projectOptions.files, fileNamePropertyReader, projectOptions.compilerOptions, projectOptions.typingOptions, projectOptions.compileOnSave, configFileErrors); } + return configFileErrors; } createInferredProjectWithRootFileIfNecessary(root: ScriptInfo) {