Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send configFileDiag event when presence of errors change on project.update #58120

Merged
merged 3 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions src/server/editorServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -840,10 +840,19 @@ export function projectContainsInfoDirectly(project: Project, info: ScriptInfo)
!project.isSourceOfProjectReferenceRedirect(info.path);
}

/** @internal */
/**
* returns true if project updated with new program
* @internal
*/
export function updateProjectIfDirty(project: Project) {
project.invalidateResolutionsOfFailedLookupLocations();
return project.dirty && project.updateGraph();
return project.dirty && !project.updateGraph();
}

function updateConfiguredProjectWithoutConfigDiagIfDirty(project: ConfiguredProject) {
project.skipConfigDiagEvent = true;
updateProjectIfDirty(project);
project.skipConfigDiagEvent = undefined;
}

function setProjectOptionsUsed(project: ConfiguredProject | ExternalProject) {
Expand Down Expand Up @@ -2508,6 +2517,7 @@ export class ProjectService {
/** @internal */
private createLoadAndUpdateConfiguredProject(configFileName: NormalizedPath, reason: string) {
const project = this.createAndLoadConfiguredProject(configFileName, reason);
project.skipConfigDiagEvent = true;
project.updateGraph();
return project;
}
Expand Down Expand Up @@ -2836,6 +2846,7 @@ export class ProjectService {

// Load project from the disk
this.loadConfiguredProject(project, reason);
project.skipConfigDiagEvent = true;
project.updateGraph();

this.sendConfigFileDiagEvent(project, configFileName);
Expand All @@ -2849,17 +2860,22 @@ export class ProjectService {
project.markAsDirty();
}

private sendConfigFileDiagEvent(project: ConfiguredProject, triggerFile: NormalizedPath) {
/** @internal */
sendConfigFileDiagEvent(project: ConfiguredProject, triggerFile: NormalizedPath | undefined) {
if (!this.eventHandler || this.suppressDiagnosticEvents) {
return;
}
const diagnostics = project.getLanguageService().getCompilerOptionsDiagnostics();
diagnostics.push(...project.getAllProjectErrors());

if (!triggerFile && !!diagnostics.length === !!project.hasConfigFileDiagnostics) return;

project.hasConfigFileDiagnostics = !!diagnostics.length;

this.eventHandler(
{
eventName: ConfigFileDiagEvent,
data: { configFileName: project.getConfigFilePath(), diagnostics, triggerFile },
data: { configFileName: project.getConfigFilePath(), diagnostics, triggerFile: triggerFile ?? project.getConfigFilePath() },
} satisfies ConfigFileDiagEvent,
);
}
Expand Down Expand Up @@ -3782,7 +3798,7 @@ export class ProjectService {
}
else {
// Ensure project is ready to check if it contains opened script info
updateProjectIfDirty(project);
updateConfiguredProjectWithoutConfigDiagIfDirty(project);
}

projectForConfigFileDiag = project.containsScriptInfo(info) ? project : undefined;
Expand All @@ -3795,7 +3811,7 @@ export class ProjectService {
project,
info.path,
child => {
updateProjectIfDirty(child);
updateConfiguredProjectWithoutConfigDiagIfDirty(child);
// Retain these projects
if (!isArray(retainProjects)) {
retainProjects = [project as ConfiguredProject, child];
Expand Down
9 changes: 9 additions & 0 deletions src/server/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2707,6 +2707,12 @@ export class ConfiguredProject extends Project {
/** @internal */
private compilerHost?: CompilerHost;

/** @internal */
hasConfigFileDiagnostics?: boolean;

/** @internal */
skipConfigDiagEvent?: true;

/** @internal */
constructor(
configFileName: NormalizedPath,
Expand Down Expand Up @@ -2790,6 +2796,9 @@ export class ConfiguredProject extends Project {
this.compilerHost = undefined;
this.projectService.sendProjectLoadingFinishEvent(this);
this.projectService.sendProjectTelemetry(this);
if (!this.skipConfigDiagEvent && !result) { // If new program, send event if diagnostics presence has changed
this.projectService.sendConfigFileDiagEvent(this, /*triggerFile*/ undefined);
}
return result;
}

Expand Down
25 changes: 25 additions & 0 deletions src/testRunner/unittests/tsserver/projectErrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
File,
Folder,
libFile,
TestServerHostOsFlavor,
} from "../helpers/virtualFileSystemWithWatch";

describe("unittests:: tsserver:: projectErrors::", () => {
Expand Down Expand Up @@ -808,3 +809,27 @@ describe("unittests:: tsserver:: projectErrors:: with npm install when", () => {
verifyNpmInstall(/*timeoutDuringPartialInstallation*/ false);
});
});

describe("unittests:: tsserver:: projectErrors:: with file rename on wsl2::", () => {
it("rename a file", () => {
const host = createServerHost({
"/home/username/project/src/a.ts": `export const a = 10;`,
"/home/username/project/src/b.ts": `export const b = 10;`,
"/home/username/project/tsconfig.json": jsonToReadableText({
compilerOptions: {
strictNullChecks: true,
},
include: ["src/**/*.ts"],
}),
[libFile.path]: libFile.content,
}, { osFlavor: TestServerHostOsFlavor.Linux });
const session = new TestSession(host);
openFilesForSession([{ file: "/home/username/project/src/a.ts", projectRootPath: "/home/username/project" }], session);
host.renameFile("/home/username/project/src/b.ts", "/home/username/project/src/c.ts");
openFilesForSession([{ file: "/home/username/project/src/c.ts", content: `export const b = 10;`, projectRootPath: "/home/username/project" }], session);
host.runQueuedTimeoutCallbacks(); // Updates the project that c.ts now exists on the disk and schedules one more update
host.runQueuedTimeoutCallbacks();
closeFilesForSession(["/home/username/project/src/c.ts"], session);
baselineTsserverLogs("projectErrors", "file rename on wsl2", session);
});
});
1 change: 0 additions & 1 deletion tests/baselines/reference/api/typescript.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3233,7 +3233,6 @@ declare namespace ts {
private addFilesToNonInferredProject;
private updateNonInferredProjectFiles;
private updateRootAndOptionsOfNonInferredProject;
private sendConfigFileDiagEvent;
private getOrCreateInferredProjectForProjectRootPathIfEnabled;
private getOrCreateSingleInferredProjectIfEnabled;
private getOrCreateSingleInferredWithoutProjectRoot;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,63 @@ Info seq [hh:mm:ss:mss] event:
}
}
}
Info seq [hh:mm:ss:mss] event:
{
"seq": 0,
"type": "event",
"event": "configFileDiag",
"body": {
"triggerFile": "/packages/a/tsconfig.json",
"configFile": "/packages/a/tsconfig.json",
"diagnostics": [
{
"text": "File '/a/lib/lib.d.ts' not found.\n The file is in the program because:\n Default library for target 'es5'",
"code": 6053,
"category": "error"
},
{
"text": "Cannot find global type 'Array'.",
"code": 2318,
"category": "error"
},
{
"text": "Cannot find global type 'Boolean'.",
"code": 2318,
"category": "error"
},
{
"text": "Cannot find global type 'Function'.",
"code": 2318,
"category": "error"
},
{
"text": "Cannot find global type 'IArguments'.",
"code": 2318,
"category": "error"
},
{
"text": "Cannot find global type 'Number'.",
"code": 2318,
"category": "error"
},
{
"text": "Cannot find global type 'Object'.",
"code": 2318,
"category": "error"
},
{
"text": "Cannot find global type 'RegExp'.",
"code": 2318,
"category": "error"
},
{
"text": "Cannot find global type 'String'.",
"code": 2318,
"category": "error"
}
]
}
}
Info seq [hh:mm:ss:mss] Finding references to /packages/b/index.ts position 13 in project /tsconfig.json
Info seq [hh:mm:ss:mss] Search path: /packages/a
Info seq [hh:mm:ss:mss] For info: /packages/a/index.ts :: Config file name: /packages/a/tsconfig.json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,26 +525,6 @@ Info seq [hh:mm:ss:mss] Files (4)
/user/username/projects/myproject/file3.ts Text-1 "const xy = 3;"

Info seq [hh:mm:ss:mss] -----------------------------------------------
Info seq [hh:mm:ss:mss] Before ensureProjectForOpenFiles:
Info seq [hh:mm:ss:mss] Project '/user/username/projects/myproject/tsconfig.json' (Configured)
Info seq [hh:mm:ss:mss] Files (4)

Info seq [hh:mm:ss:mss] -----------------------------------------------
Info seq [hh:mm:ss:mss] Open files:
Info seq [hh:mm:ss:mss] FileName: /user/username/projects/myproject/file1.ts ProjectRootPath: undefined
Info seq [hh:mm:ss:mss] Projects: /user/username/projects/myproject/tsconfig.json
Info seq [hh:mm:ss:mss] FileName: /user/username/projects/myproject/file2.ts ProjectRootPath: undefined
Info seq [hh:mm:ss:mss] Projects: /user/username/projects/myproject/tsconfig.json
Info seq [hh:mm:ss:mss] After ensureProjectForOpenFiles:
Info seq [hh:mm:ss:mss] Project '/user/username/projects/myproject/tsconfig.json' (Configured)
Info seq [hh:mm:ss:mss] Files (4)

Info seq [hh:mm:ss:mss] -----------------------------------------------
Info seq [hh:mm:ss:mss] Open files:
Info seq [hh:mm:ss:mss] FileName: /user/username/projects/myproject/file1.ts ProjectRootPath: undefined
Info seq [hh:mm:ss:mss] Projects: /user/username/projects/myproject/tsconfig.json
Info seq [hh:mm:ss:mss] FileName: /user/username/projects/myproject/file2.ts ProjectRootPath: undefined
Info seq [hh:mm:ss:mss] Projects: /user/username/projects/myproject/tsconfig.json
Info seq [hh:mm:ss:mss] response:
{
"response": [
Expand Down Expand Up @@ -672,26 +652,6 @@ Info seq [hh:mm:ss:mss] Files (4)
/user/username/projects/myproject/file3.ts Text-1 "const xy = 3;"

Info seq [hh:mm:ss:mss] -----------------------------------------------
Info seq [hh:mm:ss:mss] Before ensureProjectForOpenFiles:
Info seq [hh:mm:ss:mss] Project '/user/username/projects/myproject/tsconfig.json' (Configured)
Info seq [hh:mm:ss:mss] Files (4)

Info seq [hh:mm:ss:mss] -----------------------------------------------
Info seq [hh:mm:ss:mss] Open files:
Info seq [hh:mm:ss:mss] FileName: /user/username/projects/myproject/file1.ts ProjectRootPath: undefined
Info seq [hh:mm:ss:mss] Projects: /user/username/projects/myproject/tsconfig.json
Info seq [hh:mm:ss:mss] FileName: /user/username/projects/myproject/file2.ts ProjectRootPath: undefined
Info seq [hh:mm:ss:mss] Projects: /user/username/projects/myproject/tsconfig.json
Info seq [hh:mm:ss:mss] After ensureProjectForOpenFiles:
Info seq [hh:mm:ss:mss] Project '/user/username/projects/myproject/tsconfig.json' (Configured)
Info seq [hh:mm:ss:mss] Files (4)

Info seq [hh:mm:ss:mss] -----------------------------------------------
Info seq [hh:mm:ss:mss] Open files:
Info seq [hh:mm:ss:mss] FileName: /user/username/projects/myproject/file1.ts ProjectRootPath: undefined
Info seq [hh:mm:ss:mss] Projects: /user/username/projects/myproject/tsconfig.json
Info seq [hh:mm:ss:mss] FileName: /user/username/projects/myproject/file2.ts ProjectRootPath: undefined
Info seq [hh:mm:ss:mss] Projects: /user/username/projects/myproject/tsconfig.json
Info seq [hh:mm:ss:mss] response:
{
"response": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -583,26 +583,6 @@ Info seq [hh:mm:ss:mss] Files (5)
/user/username/projects/myproject/module.ts Text-1 "export const xyz = 4;"

Info seq [hh:mm:ss:mss] -----------------------------------------------
Info seq [hh:mm:ss:mss] Before ensureProjectForOpenFiles:
Info seq [hh:mm:ss:mss] Project '/user/username/projects/myproject/tsconfig.json' (Configured)
Info seq [hh:mm:ss:mss] Files (5)

Info seq [hh:mm:ss:mss] -----------------------------------------------
Info seq [hh:mm:ss:mss] Open files:
Info seq [hh:mm:ss:mss] FileName: /user/username/projects/myproject/file1.ts ProjectRootPath: undefined
Info seq [hh:mm:ss:mss] Projects: /user/username/projects/myproject/tsconfig.json
Info seq [hh:mm:ss:mss] FileName: /user/username/projects/myproject/file2.ts ProjectRootPath: undefined
Info seq [hh:mm:ss:mss] Projects: /user/username/projects/myproject/tsconfig.json
Info seq [hh:mm:ss:mss] After ensureProjectForOpenFiles:
Info seq [hh:mm:ss:mss] Project '/user/username/projects/myproject/tsconfig.json' (Configured)
Info seq [hh:mm:ss:mss] Files (5)

Info seq [hh:mm:ss:mss] -----------------------------------------------
Info seq [hh:mm:ss:mss] Open files:
Info seq [hh:mm:ss:mss] FileName: /user/username/projects/myproject/file1.ts ProjectRootPath: undefined
Info seq [hh:mm:ss:mss] Projects: /user/username/projects/myproject/tsconfig.json
Info seq [hh:mm:ss:mss] FileName: /user/username/projects/myproject/file2.ts ProjectRootPath: undefined
Info seq [hh:mm:ss:mss] Projects: /user/username/projects/myproject/tsconfig.json
Info seq [hh:mm:ss:mss] response:
{
"response": [
Expand Down Expand Up @@ -735,26 +715,6 @@ Info seq [hh:mm:ss:mss] Files (5)
/user/username/projects/myproject/module.ts Text-1 "export const xyz = 4;"

Info seq [hh:mm:ss:mss] -----------------------------------------------
Info seq [hh:mm:ss:mss] Before ensureProjectForOpenFiles:
Info seq [hh:mm:ss:mss] Project '/user/username/projects/myproject/tsconfig.json' (Configured)
Info seq [hh:mm:ss:mss] Files (5)

Info seq [hh:mm:ss:mss] -----------------------------------------------
Info seq [hh:mm:ss:mss] Open files:
Info seq [hh:mm:ss:mss] FileName: /user/username/projects/myproject/file1.ts ProjectRootPath: undefined
Info seq [hh:mm:ss:mss] Projects: /user/username/projects/myproject/tsconfig.json
Info seq [hh:mm:ss:mss] FileName: /user/username/projects/myproject/file2.ts ProjectRootPath: undefined
Info seq [hh:mm:ss:mss] Projects: /user/username/projects/myproject/tsconfig.json
Info seq [hh:mm:ss:mss] After ensureProjectForOpenFiles:
Info seq [hh:mm:ss:mss] Project '/user/username/projects/myproject/tsconfig.json' (Configured)
Info seq [hh:mm:ss:mss] Files (5)

Info seq [hh:mm:ss:mss] -----------------------------------------------
Info seq [hh:mm:ss:mss] Open files:
Info seq [hh:mm:ss:mss] FileName: /user/username/projects/myproject/file1.ts ProjectRootPath: undefined
Info seq [hh:mm:ss:mss] Projects: /user/username/projects/myproject/tsconfig.json
Info seq [hh:mm:ss:mss] FileName: /user/username/projects/myproject/file2.ts ProjectRootPath: undefined
Info seq [hh:mm:ss:mss] Projects: /user/username/projects/myproject/tsconfig.json
Info seq [hh:mm:ss:mss] response:
{
"response": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -553,26 +553,6 @@ Info seq [hh:mm:ss:mss] Files (5)
/user/username/projects/myproject/module.ts Text-1 "export const xyz = 4;"

Info seq [hh:mm:ss:mss] -----------------------------------------------
Info seq [hh:mm:ss:mss] Before ensureProjectForOpenFiles:
Info seq [hh:mm:ss:mss] Project '/user/username/projects/myproject/tsconfig.json' (Configured)
Info seq [hh:mm:ss:mss] Files (5)

Info seq [hh:mm:ss:mss] -----------------------------------------------
Info seq [hh:mm:ss:mss] Open files:
Info seq [hh:mm:ss:mss] FileName: /user/username/projects/myproject/file1.ts ProjectRootPath: undefined
Info seq [hh:mm:ss:mss] Projects: /user/username/projects/myproject/tsconfig.json
Info seq [hh:mm:ss:mss] FileName: /user/username/projects/myproject/file2.ts ProjectRootPath: undefined
Info seq [hh:mm:ss:mss] Projects: /user/username/projects/myproject/tsconfig.json
Info seq [hh:mm:ss:mss] After ensureProjectForOpenFiles:
Info seq [hh:mm:ss:mss] Project '/user/username/projects/myproject/tsconfig.json' (Configured)
Info seq [hh:mm:ss:mss] Files (5)

Info seq [hh:mm:ss:mss] -----------------------------------------------
Info seq [hh:mm:ss:mss] Open files:
Info seq [hh:mm:ss:mss] FileName: /user/username/projects/myproject/file1.ts ProjectRootPath: undefined
Info seq [hh:mm:ss:mss] Projects: /user/username/projects/myproject/tsconfig.json
Info seq [hh:mm:ss:mss] FileName: /user/username/projects/myproject/file2.ts ProjectRootPath: undefined
Info seq [hh:mm:ss:mss] Projects: /user/username/projects/myproject/tsconfig.json
Info seq [hh:mm:ss:mss] response:
{
"response": [
Expand Down Expand Up @@ -704,26 +684,6 @@ Info seq [hh:mm:ss:mss] Files (5)
/user/username/projects/myproject/module.ts Text-1 "export const xyz = 4;"

Info seq [hh:mm:ss:mss] -----------------------------------------------
Info seq [hh:mm:ss:mss] Before ensureProjectForOpenFiles:
Info seq [hh:mm:ss:mss] Project '/user/username/projects/myproject/tsconfig.json' (Configured)
Info seq [hh:mm:ss:mss] Files (5)

Info seq [hh:mm:ss:mss] -----------------------------------------------
Info seq [hh:mm:ss:mss] Open files:
Info seq [hh:mm:ss:mss] FileName: /user/username/projects/myproject/file1.ts ProjectRootPath: undefined
Info seq [hh:mm:ss:mss] Projects: /user/username/projects/myproject/tsconfig.json
Info seq [hh:mm:ss:mss] FileName: /user/username/projects/myproject/file2.ts ProjectRootPath: undefined
Info seq [hh:mm:ss:mss] Projects: /user/username/projects/myproject/tsconfig.json
Info seq [hh:mm:ss:mss] After ensureProjectForOpenFiles:
Info seq [hh:mm:ss:mss] Project '/user/username/projects/myproject/tsconfig.json' (Configured)
Info seq [hh:mm:ss:mss] Files (5)

Info seq [hh:mm:ss:mss] -----------------------------------------------
Info seq [hh:mm:ss:mss] Open files:
Info seq [hh:mm:ss:mss] FileName: /user/username/projects/myproject/file1.ts ProjectRootPath: undefined
Info seq [hh:mm:ss:mss] Projects: /user/username/projects/myproject/tsconfig.json
Info seq [hh:mm:ss:mss] FileName: /user/username/projects/myproject/file2.ts ProjectRootPath: undefined
Info seq [hh:mm:ss:mss] Projects: /user/username/projects/myproject/tsconfig.json
Info seq [hh:mm:ss:mss] response:
{
"response": [
Expand Down
Loading