Skip to content

Commit 761895d

Browse files
committed
Port (#12372)
1 parent 77613eb commit 761895d

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

src/harness/unittests/tsserverProjectSystem.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2452,6 +2452,43 @@ namespace ts.projectSystem {
24522452
openFilesForSession([file], session);
24532453
serverEventManager.checkEventCountOfType("configFileDiag", 1);
24542454
});
2455+
2456+
it("are generated when the config file changes", () => {
2457+
const serverEventManager = new TestServerEventManager();
2458+
const file = {
2459+
path: "/a/b/app.ts",
2460+
content: "let x = 10"
2461+
};
2462+
const configFile = {
2463+
path: "/a/b/tsconfig.json",
2464+
content: `{
2465+
"compilerOptions": {}
2466+
}`
2467+
};
2468+
2469+
const host = createServerHost([file, configFile]);
2470+
const session = createSession(host, /*typingsInstaller*/ undefined, serverEventManager.handler);
2471+
openFilesForSession([file], session);
2472+
serverEventManager.checkEventCountOfType("configFileDiag", 1);
2473+
2474+
configFile.content = `{
2475+
"compilerOptions": {
2476+
"haha": 123
2477+
}
2478+
}`;
2479+
host.reloadFS([file, configFile]);
2480+
host.triggerFileWatcherCallback(configFile.path);
2481+
host.runQueuedTimeoutCallbacks();
2482+
serverEventManager.checkEventCountOfType("configFileDiag", 2);
2483+
2484+
configFile.content = `{
2485+
"compilerOptions": {}
2486+
}`;
2487+
host.reloadFS([file, configFile]);
2488+
host.triggerFileWatcherCallback(configFile.path);
2489+
host.runQueuedTimeoutCallbacks();
2490+
serverEventManager.checkEventCountOfType("configFileDiag", 3);
2491+
});
24552492
});
24562493

24572494
describe("skipLibCheck", () => {

src/server/editorServices.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -520,8 +520,10 @@ namespace ts.server {
520520
}
521521

522522
private onConfigChangedForConfiguredProject(project: ConfiguredProject) {
523-
this.logger.info(`Config file changed: ${project.getConfigFilePath()}`);
524-
this.updateConfiguredProject(project);
523+
const configFileName = project.getConfigFilePath();
524+
this.logger.info(`Config file changed: ${configFileName}`);
525+
const configFileErrors = this.updateConfiguredProject(project);
526+
this.reportConfigFileDiagnostics(configFileName, configFileErrors, /*triggerFile*/ configFileName);
525527
this.refreshInferredProjects();
526528
}
527529

@@ -1015,6 +1017,9 @@ namespace ts.server {
10151017
return;
10161018
}
10171019

1020+
// note: the returned "success" is true does not mean the "configFileErrors" is empty.
1021+
// because we might have tolerated the errors and kept going. So always return the configFileErrors
1022+
// regardless the "success" here is true or not.
10181023
const { success, projectOptions, configFileErrors } = this.convertConfigFileContentToProjectOptions(project.getConfigFilePath());
10191024
if (!success) {
10201025
// reset project settings to default
@@ -1026,7 +1031,7 @@ namespace ts.server {
10261031
project.setCompilerOptions(projectOptions.compilerOptions);
10271032
if (!project.languageServiceEnabled) {
10281033
// language service is already disabled
1029-
return;
1034+
return configFileErrors;
10301035
}
10311036
project.disableLanguageService();
10321037
project.stopWatchingDirectory();
@@ -1038,6 +1043,7 @@ namespace ts.server {
10381043
this.watchConfigDirectoryForProject(project, projectOptions);
10391044
this.updateNonInferredProject(project, projectOptions.files, fileNamePropertyReader, projectOptions.compilerOptions, projectOptions.typingOptions, projectOptions.compileOnSave, configFileErrors);
10401045
}
1046+
return configFileErrors;
10411047
}
10421048

10431049
createInferredProjectWithRootFileIfNecessary(root: ScriptInfo) {

0 commit comments

Comments
 (0)