diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 0e48953eaa7d5..3e4d4580fd818 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -88,6 +88,10 @@ module ts { type: "boolean", description: Diagnostics.Do_not_emit_comments_to_output, }, + { + name: "showDiagnosticCodes", + type: "boolean", + }, { name: "sourceMap", type: "boolean", diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index 8188cb8e4d12e..ba31507c46952 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -85,7 +85,7 @@ module ts { return diagnostic.messageText; } - function reportDiagnostic(diagnostic: Diagnostic) { + function reportDiagnostic(diagnostic: Diagnostic, options: CompilerOptions) { var output = ""; if (diagnostic.file) { @@ -94,15 +94,19 @@ module ts { output += diagnostic.file.filename + "(" + loc.line + "," + loc.character + "): "; } - var category = DiagnosticCategory[diagnostic.category].toLowerCase(); - output += category + " TS" + diagnostic.code + ": " + diagnostic.messageText + sys.newLine; + if (options.showDiagnosticCodes) { + var category = DiagnosticCategory[diagnostic.category].toLowerCase(); + output += category + " TS" + diagnostic.code + ": "; + } + + output += diagnostic.messageText + sys.newLine; sys.write(output); } - function reportDiagnostics(diagnostics: Diagnostic[]) { + function reportDiagnostics(diagnostics: Diagnostic[], options: CompilerOptions) { for (var i = 0; i < diagnostics.length; i++) { - reportDiagnostic(diagnostics[i]); + reportDiagnostic(diagnostics[i], options); } } @@ -207,12 +211,12 @@ module ts { // If there are any errors due to command line parsing and/or // setting up localization, report them and quit. if (commandLine.errors.length > 0) { - reportDiagnostics(commandLine.errors); + reportDiagnostics(commandLine.errors, commandLine.options); return sys.exit(1); } if (commandLine.options.version) { - reportDiagnostic(createCompilerDiagnostic(Diagnostics.Version_0, version)); + reportDiagnostic(createCompilerDiagnostic(Diagnostics.Version_0, version), commandLine.options); return sys.exit(0); } @@ -226,7 +230,7 @@ module ts { if (commandLine.options.watch) { if (!sys.watchFile) { - reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_current_host_does_not_support_the_0_option, "--watch")); + reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_current_host_does_not_support_the_0_option, "--watch"), commandLine.options); return sys.exit(1); } @@ -250,7 +254,7 @@ module ts { // Compile the program the first time and watch all given/referenced files. var program = compile(commandLine, compilerHost).program; - reportDiagnostic(createCompilerDiagnostic(Diagnostics.Compilation_complete_Watching_for_file_changes)); + reportDiagnostic(createCompilerDiagnostic(Diagnostics.Compilation_complete_Watching_for_file_changes), commandLine.options); addWatchers(program); return; @@ -290,7 +294,7 @@ module ts { } function recompile(changedFiles: Map) { - reportDiagnostic(createCompilerDiagnostic(Diagnostics.File_change_detected_Compiling)); + reportDiagnostic(createCompilerDiagnostic(Diagnostics.File_change_detected_Compiling), commandLine.options); // Remove all the watchers, as we may not be watching every file // specified since the last compilation cycle. removeWatchers(program); @@ -317,7 +321,7 @@ module ts { }; program = compile(commandLine, newCompilerHost).program; - reportDiagnostic(createCompilerDiagnostic(Diagnostics.Compilation_complete_Watching_for_file_changes)); + reportDiagnostic(createCompilerDiagnostic(Diagnostics.Compilation_complete_Watching_for_file_changes), commandLine.options); addWatchers(program); } @@ -347,7 +351,7 @@ module ts { errors = concatenate(semanticErrors, emitErrors); } - reportDiagnostics(errors); + reportDiagnostics(errors, commandLine.options); if (commandLine.options.diagnostics) { var memoryUsed = sys.getMemoryUsage ? sys.getMemoryUsage() : -1; reportCountStatistic("Files", program.getSourceFiles().length); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 82fac6b891322..303b7eb7fae9c 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -988,6 +988,7 @@ module ts { out?: string; outDir?: string; removeComments?: boolean; + showDiagnosticCodes?: boolean; sourceMap?: boolean; sourceRoot?: string; target?: ScriptTarget;