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

Do not print error codes by default #694

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ module ts {
type: "boolean",
description: Diagnostics.Do_not_emit_comments_to_output,
},
{
name: "showDiagnosticCodes",
type: "boolean",
},
{
name: "sourceMap",
type: "boolean",
Expand Down
28 changes: 16 additions & 12 deletions src/compiler/tsc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ module ts {
return diagnostic.messageText;
}

function reportDiagnostic(diagnostic: Diagnostic) {
function reportDiagnostic(diagnostic: Diagnostic, options: CompilerOptions) {
var output = "";

if (diagnostic.file) {
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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;

Expand Down Expand Up @@ -290,7 +294,7 @@ module ts {
}

function recompile(changedFiles: Map<boolean>) {
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);
Expand All @@ -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);
}

Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,7 @@ module ts {
out?: string;
outDir?: string;
removeComments?: boolean;
showDiagnosticCodes?: boolean;
sourceMap?: boolean;
sourceRoot?: string;
target?: ScriptTarget;
Expand Down