diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 18e88ad9d3..e80c1c639b 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -119,6 +119,18 @@ namespace ts { category: Diagnostics.Advanced_Options, description: Diagnostics.Enable_tracing_of_the_name_resolution_process }, + { + name: "diagnostics", + type: "boolean", + category: Diagnostics.Advanced_Options, + description: Diagnostics.Show_diagnostic_information + }, + { + name: "extendedDiagnostics", + type: "boolean", + category: Diagnostics.Advanced_Options, + description: Diagnostics.Show_verbose_diagnostic_information + }, ]; /* @internal */ @@ -592,18 +604,6 @@ namespace ts { category: Diagnostics.Advanced_Options, description: Diagnostics.Specify_the_JSX_factory_function_to_use_when_targeting_react_JSX_emit_e_g_React_createElement_or_h }, - { - name: "diagnostics", - type: "boolean", - category: Diagnostics.Advanced_Options, - description: Diagnostics.Show_diagnostic_information - }, - { - name: "extendedDiagnostics", - type: "boolean", - category: Diagnostics.Advanced_Options, - description: Diagnostics.Show_verbose_diagnostic_information - }, { name: "resolveJsonModule", type: "boolean", diff --git a/src/compiler/tsbuild.ts b/src/compiler/tsbuild.ts index 4b9e75102b..e17057b914 100644 --- a/src/compiler/tsbuild.ts +++ b/src/compiler/tsbuild.ts @@ -32,6 +32,8 @@ namespace ts { pretty?: boolean; traceResolution?: boolean; + /* @internal */ diagnostics?: boolean; + /* @internal */ extendedDiagnostics?: boolean; } enum BuildResultFlags { @@ -326,6 +328,11 @@ namespace ts { reportDiagnostic: DiagnosticReporter; // Technically we want to move it out and allow steps of actions on Solution, but for now just merge stuff in build host here reportSolutionBuilderStatus: DiagnosticReporter; + + // TODO: To do better with watch mode and normal build mode api that creates program and emits files + // This currently helps enable --diagnostics and --extendedDiagnostics + beforeCreateProgram?(options: CompilerOptions): void; + afterProgramEmitAndDiagnostics?(program: Program): void; } export interface SolutionBuilderHost extends SolutionBuilderHostBase { @@ -997,7 +1004,6 @@ namespace ts { } } - function buildSingleProject(proj: ResolvedConfigFileName): BuildResultFlags { if (options.dry) { reportStatus(Diagnostics.A_non_dry_build_would_build_project_0, proj); @@ -1030,6 +1036,9 @@ namespace ts { options: configFile.options, configFileParsingDiagnostics: configFile.errors }; + if (host.beforeCreateProgram) { + host.beforeCreateProgram(options); + } const program = createProgram(programOptions); // Don't emit anything in the presence of syntactic errors or options diagnostics @@ -1089,12 +1098,18 @@ namespace ts { }; diagnostics.removeKey(proj); projectStatus.setValue(proj, status); + if (host.afterProgramEmitAndDiagnostics) { + host.afterProgramEmitAndDiagnostics(program); + } return resultFlags; function buildErrors(diagnostics: ReadonlyArray, errorFlags: BuildResultFlags, errorType: string) { resultFlags |= errorFlags; reportAndStoreErrors(proj, diagnostics); projectStatus.setValue(proj, { type: UpToDateStatusType.Unbuildable, reason: `${errorType} errors` }); + if (host.afterProgramEmitAndDiagnostics) { + host.afterProgramEmitAndDiagnostics(program); + } return resultFlags; } } diff --git a/src/tsc/tsc.ts b/src/tsc/tsc.ts index d3a60f58d0..8d9b2f1afa 100644 --- a/src/tsc/tsc.ts +++ b/src/tsc/tsc.ts @@ -199,11 +199,14 @@ namespace ts { reportWatchModeWithoutSysSupport(); } - // TODO: change this to host if watch => watchHost otherwiue without wathc - const builder = createSolutionBuilder(buildOptions.watch ? + // TODO: change this to host if watch => watchHost otherwiue without watch + const buildHost = buildOptions.watch ? createSolutionBuilderWithWatchHost(sys, reportDiagnostic, createBuilderStatusReporter(sys, shouldBePretty()), createWatchStatusReporter()) : - createSolutionBuilderHost(sys, reportDiagnostic, createBuilderStatusReporter(sys, shouldBePretty()), createReportErrorSummary(buildOptions)), - projects, buildOptions); + createSolutionBuilderHost(sys, reportDiagnostic, createBuilderStatusReporter(sys, shouldBePretty()), createReportErrorSummary(buildOptions)); + buildHost.beforeCreateProgram = enableStatistics; + buildHost.afterProgramEmitAndDiagnostics = reportStatistics; + + const builder = createSolutionBuilder(buildHost, projects, buildOptions); if (buildOptions.clean) { return sys.exit(builder.cleanAllProjects()); }