Skip to content

Commit 2df421b

Browse files
authored
Always generate configFileDiag if file is going to be added to configured project (#37443)
Fixes #30623
1 parent 0aa2e27 commit 2df421b

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

src/server/editorServices.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3017,6 +3017,13 @@ namespace ts.server {
30173017
// At this point if file is part of any any configured or external project, then it would be present in the containing projects
30183018
// So if it still doesnt have any containing projects, it needs to be part of inferred project
30193019
if (info.isOrphan()) {
3020+
// Even though this info did not belong to any of the configured projects, send the config file diag
3021+
if (isArray(retainProjects)) {
3022+
retainProjects.forEach(project => this.sendConfigFileDiagEvent(project, info.fileName));
3023+
}
3024+
else if (retainProjects) {
3025+
this.sendConfigFileDiagEvent(retainProjects, info.fileName);
3026+
}
30203027
Debug.assert(this.openFiles.has(info.path));
30213028
this.assignOrphanScriptInfoToInferredProject(info, this.openFiles.get(info.path));
30223029
}

src/testRunner/unittests/tsserver/projectErrors.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,10 @@ declare module '@custom/plugin' {
608608
path: "/a/b/test.ts",
609609
content: "let x = 10"
610610
};
611+
const file3: File = {
612+
path: "/a/b/test2.ts",
613+
content: "let xy = 10"
614+
};
611615
const configFile: File = {
612616
path: "/a/b/tsconfig.json",
613617
content: `{
@@ -618,9 +622,20 @@ declare module '@custom/plugin' {
618622
"files": ["app.ts"]
619623
}`
620624
};
621-
const serverEventManager = new TestServerEventManager([file, file2, libFile, configFile]);
625+
const serverEventManager = new TestServerEventManager([file, file2, file3, libFile, configFile]);
622626
openFilesForSession([file2], serverEventManager.session);
627+
serverEventManager.checkSingleConfigFileDiagEvent(configFile.path, file2.path, [
628+
getUnknownCompilerOptionDiagnostic(configFile, "foo"),
629+
getUnknownCompilerOptionDiagnostic(configFile, "allowJS", "allowJs")
630+
]);
631+
openFilesForSession([file], serverEventManager.session);
632+
// We generate only if project is created when opening file from the project
623633
serverEventManager.hasZeroEvent("configFileDiag");
634+
openFilesForSession([file3], serverEventManager.session);
635+
serverEventManager.checkSingleConfigFileDiagEvent(configFile.path, file3.path, [
636+
getUnknownCompilerOptionDiagnostic(configFile, "foo"),
637+
getUnknownCompilerOptionDiagnostic(configFile, "allowJS", "allowJs")
638+
]);
624639
});
625640

626641
it("are not generated when the config file has errors but suppressDiagnosticEvents is true", () => {
@@ -651,16 +666,25 @@ declare module '@custom/plugin' {
651666
path: "/a/b/test.ts",
652667
content: "let x = 10"
653668
};
669+
const file3: File = {
670+
path: "/a/b/test2.ts",
671+
content: "let xy = 10"
672+
};
654673
const configFile: File = {
655674
path: "/a/b/tsconfig.json",
656675
content: `{
657676
"files": ["app.ts"]
658677
}`
659678
};
660679

661-
const serverEventManager = new TestServerEventManager([file, file2, libFile, configFile]);
680+
const serverEventManager = new TestServerEventManager([file, file2, file3, libFile, configFile]);
662681
openFilesForSession([file2], serverEventManager.session);
682+
serverEventManager.checkSingleConfigFileDiagEvent(configFile.path, file2.path, emptyArray);
683+
openFilesForSession([file], serverEventManager.session);
684+
// We generate only if project is created when opening file from the project
663685
serverEventManager.hasZeroEvent("configFileDiag");
686+
openFilesForSession([file3], serverEventManager.session);
687+
serverEventManager.checkSingleConfigFileDiagEvent(configFile.path, file3.path, emptyArray);
664688
});
665689

666690
it("contains the project reference errors", () => {

0 commit comments

Comments
 (0)