Skip to content

Commit 25de1b0

Browse files
authored
Send configFileDiag event when presence of errors change on project.update (#58120)
1 parent f608fc0 commit 25de1b0

File tree

31 files changed

+1257
-455
lines changed

31 files changed

+1257
-455
lines changed

src/server/editorServices.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -840,10 +840,19 @@ export function projectContainsInfoDirectly(project: Project, info: ScriptInfo)
840840
!project.isSourceOfProjectReferenceRedirect(info.path);
841841
}
842842

843-
/** @internal */
843+
/**
844+
* returns true if project updated with new program
845+
* @internal
846+
*/
844847
export function updateProjectIfDirty(project: Project) {
845848
project.invalidateResolutionsOfFailedLookupLocations();
846-
return project.dirty && project.updateGraph();
849+
return project.dirty && !project.updateGraph();
850+
}
851+
852+
function updateConfiguredProjectWithoutConfigDiagIfDirty(project: ConfiguredProject) {
853+
project.skipConfigDiagEvent = true;
854+
updateProjectIfDirty(project);
855+
project.skipConfigDiagEvent = undefined;
847856
}
848857

849858
function setProjectOptionsUsed(project: ConfiguredProject | ExternalProject) {
@@ -2508,6 +2517,7 @@ export class ProjectService {
25082517
/** @internal */
25092518
private createLoadAndUpdateConfiguredProject(configFileName: NormalizedPath, reason: string) {
25102519
const project = this.createAndLoadConfiguredProject(configFileName, reason);
2520+
project.skipConfigDiagEvent = true;
25112521
project.updateGraph();
25122522
return project;
25132523
}
@@ -2836,6 +2846,7 @@ export class ProjectService {
28362846

28372847
// Load project from the disk
28382848
this.loadConfiguredProject(project, reason);
2849+
project.skipConfigDiagEvent = true;
28392850
project.updateGraph();
28402851

28412852
this.sendConfigFileDiagEvent(project, configFileName);
@@ -2849,17 +2860,22 @@ export class ProjectService {
28492860
project.markAsDirty();
28502861
}
28512862

2852-
private sendConfigFileDiagEvent(project: ConfiguredProject, triggerFile: NormalizedPath) {
2863+
/** @internal */
2864+
sendConfigFileDiagEvent(project: ConfiguredProject, triggerFile: NormalizedPath | undefined) {
28532865
if (!this.eventHandler || this.suppressDiagnosticEvents) {
28542866
return;
28552867
}
28562868
const diagnostics = project.getLanguageService().getCompilerOptionsDiagnostics();
28572869
diagnostics.push(...project.getAllProjectErrors());
28582870

2871+
if (!triggerFile && !!diagnostics.length === !!project.hasConfigFileDiagnostics) return;
2872+
2873+
project.hasConfigFileDiagnostics = !!diagnostics.length;
2874+
28592875
this.eventHandler(
28602876
{
28612877
eventName: ConfigFileDiagEvent,
2862-
data: { configFileName: project.getConfigFilePath(), diagnostics, triggerFile },
2878+
data: { configFileName: project.getConfigFilePath(), diagnostics, triggerFile: triggerFile ?? project.getConfigFilePath() },
28632879
} satisfies ConfigFileDiagEvent,
28642880
);
28652881
}
@@ -3782,7 +3798,7 @@ export class ProjectService {
37823798
}
37833799
else {
37843800
// Ensure project is ready to check if it contains opened script info
3785-
updateProjectIfDirty(project);
3801+
updateConfiguredProjectWithoutConfigDiagIfDirty(project);
37863802
}
37873803

37883804
projectForConfigFileDiag = project.containsScriptInfo(info) ? project : undefined;
@@ -3795,7 +3811,7 @@ export class ProjectService {
37953811
project,
37963812
info.path,
37973813
child => {
3798-
updateProjectIfDirty(child);
3814+
updateConfiguredProjectWithoutConfigDiagIfDirty(child);
37993815
// Retain these projects
38003816
if (!isArray(retainProjects)) {
38013817
retainProjects = [project as ConfiguredProject, child];

src/server/project.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2707,6 +2707,12 @@ export class ConfiguredProject extends Project {
27072707
/** @internal */
27082708
private compilerHost?: CompilerHost;
27092709

2710+
/** @internal */
2711+
hasConfigFileDiagnostics?: boolean;
2712+
2713+
/** @internal */
2714+
skipConfigDiagEvent?: true;
2715+
27102716
/** @internal */
27112717
constructor(
27122718
configFileName: NormalizedPath,
@@ -2790,6 +2796,9 @@ export class ConfiguredProject extends Project {
27902796
this.compilerHost = undefined;
27912797
this.projectService.sendProjectLoadingFinishEvent(this);
27922798
this.projectService.sendProjectTelemetry(this);
2799+
if (!this.skipConfigDiagEvent && !result) { // If new program, send event if diagnostics presence has changed
2800+
this.projectService.sendConfigFileDiagEvent(this, /*triggerFile*/ undefined);
2801+
}
27932802
return result;
27942803
}
27952804

src/testRunner/unittests/tsserver/projectErrors.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
File,
1818
Folder,
1919
libFile,
20+
TestServerHostOsFlavor,
2021
} from "../helpers/virtualFileSystemWithWatch";
2122

2223
describe("unittests:: tsserver:: projectErrors::", () => {
@@ -808,3 +809,27 @@ describe("unittests:: tsserver:: projectErrors:: with npm install when", () => {
808809
verifyNpmInstall(/*timeoutDuringPartialInstallation*/ false);
809810
});
810811
});
812+
813+
describe("unittests:: tsserver:: projectErrors:: with file rename on wsl2::", () => {
814+
it("rename a file", () => {
815+
const host = createServerHost({
816+
"/home/username/project/src/a.ts": `export const a = 10;`,
817+
"/home/username/project/src/b.ts": `export const b = 10;`,
818+
"/home/username/project/tsconfig.json": jsonToReadableText({
819+
compilerOptions: {
820+
strictNullChecks: true,
821+
},
822+
include: ["src/**/*.ts"],
823+
}),
824+
[libFile.path]: libFile.content,
825+
}, { osFlavor: TestServerHostOsFlavor.Linux });
826+
const session = new TestSession(host);
827+
openFilesForSession([{ file: "/home/username/project/src/a.ts", projectRootPath: "/home/username/project" }], session);
828+
host.renameFile("/home/username/project/src/b.ts", "/home/username/project/src/c.ts");
829+
openFilesForSession([{ file: "/home/username/project/src/c.ts", content: `export const b = 10;`, projectRootPath: "/home/username/project" }], session);
830+
host.runQueuedTimeoutCallbacks(); // Updates the project that c.ts now exists on the disk and schedules one more update
831+
host.runQueuedTimeoutCallbacks();
832+
closeFilesForSession(["/home/username/project/src/c.ts"], session);
833+
baselineTsserverLogs("projectErrors", "file rename on wsl2", session);
834+
});
835+
});

tests/baselines/reference/api/typescript.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3233,7 +3233,6 @@ declare namespace ts {
32333233
private addFilesToNonInferredProject;
32343234
private updateNonInferredProjectFiles;
32353235
private updateRootAndOptionsOfNonInferredProject;
3236-
private sendConfigFileDiagEvent;
32373236
private getOrCreateInferredProjectForProjectRootPathIfEnabled;
32383237
private getOrCreateSingleInferredProjectIfEnabled;
32393238
private getOrCreateSingleInferredWithoutProjectRoot;

tests/baselines/reference/tsserver/autoImportProvider/Does-not-create-auto-import-providers-upon-opening-projects-for-find-all-references.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,63 @@ Info seq [hh:mm:ss:mss] event:
540540
}
541541
}
542542
}
543+
Info seq [hh:mm:ss:mss] event:
544+
{
545+
"seq": 0,
546+
"type": "event",
547+
"event": "configFileDiag",
548+
"body": {
549+
"triggerFile": "/packages/a/tsconfig.json",
550+
"configFile": "/packages/a/tsconfig.json",
551+
"diagnostics": [
552+
{
553+
"text": "File '/a/lib/lib.d.ts' not found.\n The file is in the program because:\n Default library for target 'es5'",
554+
"code": 6053,
555+
"category": "error"
556+
},
557+
{
558+
"text": "Cannot find global type 'Array'.",
559+
"code": 2318,
560+
"category": "error"
561+
},
562+
{
563+
"text": "Cannot find global type 'Boolean'.",
564+
"code": 2318,
565+
"category": "error"
566+
},
567+
{
568+
"text": "Cannot find global type 'Function'.",
569+
"code": 2318,
570+
"category": "error"
571+
},
572+
{
573+
"text": "Cannot find global type 'IArguments'.",
574+
"code": 2318,
575+
"category": "error"
576+
},
577+
{
578+
"text": "Cannot find global type 'Number'.",
579+
"code": 2318,
580+
"category": "error"
581+
},
582+
{
583+
"text": "Cannot find global type 'Object'.",
584+
"code": 2318,
585+
"category": "error"
586+
},
587+
{
588+
"text": "Cannot find global type 'RegExp'.",
589+
"code": 2318,
590+
"category": "error"
591+
},
592+
{
593+
"text": "Cannot find global type 'String'.",
594+
"code": 2318,
595+
"category": "error"
596+
}
597+
]
598+
}
599+
}
543600
Info seq [hh:mm:ss:mss] Finding references to /packages/b/index.ts position 13 in project /tsconfig.json
544601
Info seq [hh:mm:ss:mss] Search path: /packages/a
545602
Info seq [hh:mm:ss:mss] For info: /packages/a/index.ts :: Config file name: /packages/a/tsconfig.json

tests/baselines/reference/tsserver/compileOnSave/emit-in-project-with-dts-emit.js

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -525,26 +525,6 @@ Info seq [hh:mm:ss:mss] Files (4)
525525
/user/username/projects/myproject/file3.ts Text-1 "const xy = 3;"
526526

527527
Info seq [hh:mm:ss:mss] -----------------------------------------------
528-
Info seq [hh:mm:ss:mss] Before ensureProjectForOpenFiles:
529-
Info seq [hh:mm:ss:mss] Project '/user/username/projects/myproject/tsconfig.json' (Configured)
530-
Info seq [hh:mm:ss:mss] Files (4)
531-
532-
Info seq [hh:mm:ss:mss] -----------------------------------------------
533-
Info seq [hh:mm:ss:mss] Open files:
534-
Info seq [hh:mm:ss:mss] FileName: /user/username/projects/myproject/file1.ts ProjectRootPath: undefined
535-
Info seq [hh:mm:ss:mss] Projects: /user/username/projects/myproject/tsconfig.json
536-
Info seq [hh:mm:ss:mss] FileName: /user/username/projects/myproject/file2.ts ProjectRootPath: undefined
537-
Info seq [hh:mm:ss:mss] Projects: /user/username/projects/myproject/tsconfig.json
538-
Info seq [hh:mm:ss:mss] After ensureProjectForOpenFiles:
539-
Info seq [hh:mm:ss:mss] Project '/user/username/projects/myproject/tsconfig.json' (Configured)
540-
Info seq [hh:mm:ss:mss] Files (4)
541-
542-
Info seq [hh:mm:ss:mss] -----------------------------------------------
543-
Info seq [hh:mm:ss:mss] Open files:
544-
Info seq [hh:mm:ss:mss] FileName: /user/username/projects/myproject/file1.ts ProjectRootPath: undefined
545-
Info seq [hh:mm:ss:mss] Projects: /user/username/projects/myproject/tsconfig.json
546-
Info seq [hh:mm:ss:mss] FileName: /user/username/projects/myproject/file2.ts ProjectRootPath: undefined
547-
Info seq [hh:mm:ss:mss] Projects: /user/username/projects/myproject/tsconfig.json
548528
Info seq [hh:mm:ss:mss] response:
549529
{
550530
"response": [
@@ -672,26 +652,6 @@ Info seq [hh:mm:ss:mss] Files (4)
672652
/user/username/projects/myproject/file3.ts Text-1 "const xy = 3;"
673653

674654
Info seq [hh:mm:ss:mss] -----------------------------------------------
675-
Info seq [hh:mm:ss:mss] Before ensureProjectForOpenFiles:
676-
Info seq [hh:mm:ss:mss] Project '/user/username/projects/myproject/tsconfig.json' (Configured)
677-
Info seq [hh:mm:ss:mss] Files (4)
678-
679-
Info seq [hh:mm:ss:mss] -----------------------------------------------
680-
Info seq [hh:mm:ss:mss] Open files:
681-
Info seq [hh:mm:ss:mss] FileName: /user/username/projects/myproject/file1.ts ProjectRootPath: undefined
682-
Info seq [hh:mm:ss:mss] Projects: /user/username/projects/myproject/tsconfig.json
683-
Info seq [hh:mm:ss:mss] FileName: /user/username/projects/myproject/file2.ts ProjectRootPath: undefined
684-
Info seq [hh:mm:ss:mss] Projects: /user/username/projects/myproject/tsconfig.json
685-
Info seq [hh:mm:ss:mss] After ensureProjectForOpenFiles:
686-
Info seq [hh:mm:ss:mss] Project '/user/username/projects/myproject/tsconfig.json' (Configured)
687-
Info seq [hh:mm:ss:mss] Files (4)
688-
689-
Info seq [hh:mm:ss:mss] -----------------------------------------------
690-
Info seq [hh:mm:ss:mss] Open files:
691-
Info seq [hh:mm:ss:mss] FileName: /user/username/projects/myproject/file1.ts ProjectRootPath: undefined
692-
Info seq [hh:mm:ss:mss] Projects: /user/username/projects/myproject/tsconfig.json
693-
Info seq [hh:mm:ss:mss] FileName: /user/username/projects/myproject/file2.ts ProjectRootPath: undefined
694-
Info seq [hh:mm:ss:mss] Projects: /user/username/projects/myproject/tsconfig.json
695655
Info seq [hh:mm:ss:mss] response:
696656
{
697657
"response": [

tests/baselines/reference/tsserver/compileOnSave/emit-in-project-with-module-with-dts-emit.js

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -583,26 +583,6 @@ Info seq [hh:mm:ss:mss] Files (5)
583583
/user/username/projects/myproject/module.ts Text-1 "export const xyz = 4;"
584584

585585
Info seq [hh:mm:ss:mss] -----------------------------------------------
586-
Info seq [hh:mm:ss:mss] Before ensureProjectForOpenFiles:
587-
Info seq [hh:mm:ss:mss] Project '/user/username/projects/myproject/tsconfig.json' (Configured)
588-
Info seq [hh:mm:ss:mss] Files (5)
589-
590-
Info seq [hh:mm:ss:mss] -----------------------------------------------
591-
Info seq [hh:mm:ss:mss] Open files:
592-
Info seq [hh:mm:ss:mss] FileName: /user/username/projects/myproject/file1.ts ProjectRootPath: undefined
593-
Info seq [hh:mm:ss:mss] Projects: /user/username/projects/myproject/tsconfig.json
594-
Info seq [hh:mm:ss:mss] FileName: /user/username/projects/myproject/file2.ts ProjectRootPath: undefined
595-
Info seq [hh:mm:ss:mss] Projects: /user/username/projects/myproject/tsconfig.json
596-
Info seq [hh:mm:ss:mss] After ensureProjectForOpenFiles:
597-
Info seq [hh:mm:ss:mss] Project '/user/username/projects/myproject/tsconfig.json' (Configured)
598-
Info seq [hh:mm:ss:mss] Files (5)
599-
600-
Info seq [hh:mm:ss:mss] -----------------------------------------------
601-
Info seq [hh:mm:ss:mss] Open files:
602-
Info seq [hh:mm:ss:mss] FileName: /user/username/projects/myproject/file1.ts ProjectRootPath: undefined
603-
Info seq [hh:mm:ss:mss] Projects: /user/username/projects/myproject/tsconfig.json
604-
Info seq [hh:mm:ss:mss] FileName: /user/username/projects/myproject/file2.ts ProjectRootPath: undefined
605-
Info seq [hh:mm:ss:mss] Projects: /user/username/projects/myproject/tsconfig.json
606586
Info seq [hh:mm:ss:mss] response:
607587
{
608588
"response": [
@@ -735,26 +715,6 @@ Info seq [hh:mm:ss:mss] Files (5)
735715
/user/username/projects/myproject/module.ts Text-1 "export const xyz = 4;"
736716

737717
Info seq [hh:mm:ss:mss] -----------------------------------------------
738-
Info seq [hh:mm:ss:mss] Before ensureProjectForOpenFiles:
739-
Info seq [hh:mm:ss:mss] Project '/user/username/projects/myproject/tsconfig.json' (Configured)
740-
Info seq [hh:mm:ss:mss] Files (5)
741-
742-
Info seq [hh:mm:ss:mss] -----------------------------------------------
743-
Info seq [hh:mm:ss:mss] Open files:
744-
Info seq [hh:mm:ss:mss] FileName: /user/username/projects/myproject/file1.ts ProjectRootPath: undefined
745-
Info seq [hh:mm:ss:mss] Projects: /user/username/projects/myproject/tsconfig.json
746-
Info seq [hh:mm:ss:mss] FileName: /user/username/projects/myproject/file2.ts ProjectRootPath: undefined
747-
Info seq [hh:mm:ss:mss] Projects: /user/username/projects/myproject/tsconfig.json
748-
Info seq [hh:mm:ss:mss] After ensureProjectForOpenFiles:
749-
Info seq [hh:mm:ss:mss] Project '/user/username/projects/myproject/tsconfig.json' (Configured)
750-
Info seq [hh:mm:ss:mss] Files (5)
751-
752-
Info seq [hh:mm:ss:mss] -----------------------------------------------
753-
Info seq [hh:mm:ss:mss] Open files:
754-
Info seq [hh:mm:ss:mss] FileName: /user/username/projects/myproject/file1.ts ProjectRootPath: undefined
755-
Info seq [hh:mm:ss:mss] Projects: /user/username/projects/myproject/tsconfig.json
756-
Info seq [hh:mm:ss:mss] FileName: /user/username/projects/myproject/file2.ts ProjectRootPath: undefined
757-
Info seq [hh:mm:ss:mss] Projects: /user/username/projects/myproject/tsconfig.json
758718
Info seq [hh:mm:ss:mss] response:
759719
{
760720
"response": [

tests/baselines/reference/tsserver/compileOnSave/emit-in-project-with-module.js

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -553,26 +553,6 @@ Info seq [hh:mm:ss:mss] Files (5)
553553
/user/username/projects/myproject/module.ts Text-1 "export const xyz = 4;"
554554

555555
Info seq [hh:mm:ss:mss] -----------------------------------------------
556-
Info seq [hh:mm:ss:mss] Before ensureProjectForOpenFiles:
557-
Info seq [hh:mm:ss:mss] Project '/user/username/projects/myproject/tsconfig.json' (Configured)
558-
Info seq [hh:mm:ss:mss] Files (5)
559-
560-
Info seq [hh:mm:ss:mss] -----------------------------------------------
561-
Info seq [hh:mm:ss:mss] Open files:
562-
Info seq [hh:mm:ss:mss] FileName: /user/username/projects/myproject/file1.ts ProjectRootPath: undefined
563-
Info seq [hh:mm:ss:mss] Projects: /user/username/projects/myproject/tsconfig.json
564-
Info seq [hh:mm:ss:mss] FileName: /user/username/projects/myproject/file2.ts ProjectRootPath: undefined
565-
Info seq [hh:mm:ss:mss] Projects: /user/username/projects/myproject/tsconfig.json
566-
Info seq [hh:mm:ss:mss] After ensureProjectForOpenFiles:
567-
Info seq [hh:mm:ss:mss] Project '/user/username/projects/myproject/tsconfig.json' (Configured)
568-
Info seq [hh:mm:ss:mss] Files (5)
569-
570-
Info seq [hh:mm:ss:mss] -----------------------------------------------
571-
Info seq [hh:mm:ss:mss] Open files:
572-
Info seq [hh:mm:ss:mss] FileName: /user/username/projects/myproject/file1.ts ProjectRootPath: undefined
573-
Info seq [hh:mm:ss:mss] Projects: /user/username/projects/myproject/tsconfig.json
574-
Info seq [hh:mm:ss:mss] FileName: /user/username/projects/myproject/file2.ts ProjectRootPath: undefined
575-
Info seq [hh:mm:ss:mss] Projects: /user/username/projects/myproject/tsconfig.json
576556
Info seq [hh:mm:ss:mss] response:
577557
{
578558
"response": [
@@ -704,26 +684,6 @@ Info seq [hh:mm:ss:mss] Files (5)
704684
/user/username/projects/myproject/module.ts Text-1 "export const xyz = 4;"
705685

706686
Info seq [hh:mm:ss:mss] -----------------------------------------------
707-
Info seq [hh:mm:ss:mss] Before ensureProjectForOpenFiles:
708-
Info seq [hh:mm:ss:mss] Project '/user/username/projects/myproject/tsconfig.json' (Configured)
709-
Info seq [hh:mm:ss:mss] Files (5)
710-
711-
Info seq [hh:mm:ss:mss] -----------------------------------------------
712-
Info seq [hh:mm:ss:mss] Open files:
713-
Info seq [hh:mm:ss:mss] FileName: /user/username/projects/myproject/file1.ts ProjectRootPath: undefined
714-
Info seq [hh:mm:ss:mss] Projects: /user/username/projects/myproject/tsconfig.json
715-
Info seq [hh:mm:ss:mss] FileName: /user/username/projects/myproject/file2.ts ProjectRootPath: undefined
716-
Info seq [hh:mm:ss:mss] Projects: /user/username/projects/myproject/tsconfig.json
717-
Info seq [hh:mm:ss:mss] After ensureProjectForOpenFiles:
718-
Info seq [hh:mm:ss:mss] Project '/user/username/projects/myproject/tsconfig.json' (Configured)
719-
Info seq [hh:mm:ss:mss] Files (5)
720-
721-
Info seq [hh:mm:ss:mss] -----------------------------------------------
722-
Info seq [hh:mm:ss:mss] Open files:
723-
Info seq [hh:mm:ss:mss] FileName: /user/username/projects/myproject/file1.ts ProjectRootPath: undefined
724-
Info seq [hh:mm:ss:mss] Projects: /user/username/projects/myproject/tsconfig.json
725-
Info seq [hh:mm:ss:mss] FileName: /user/username/projects/myproject/file2.ts ProjectRootPath: undefined
726-
Info seq [hh:mm:ss:mss] Projects: /user/username/projects/myproject/tsconfig.json
727687
Info seq [hh:mm:ss:mss] response:
728688
{
729689
"response": [

0 commit comments

Comments
 (0)