misc improvements

This commit is contained in:
Anton-4 2024-03-04 17:10:59 +01:00
parent c47fff04d2
commit f620508a37
No known key found for this signature in database
GPG Key ID: 0971D718C0A9B937
6 changed files with 14 additions and 46 deletions

View File

@ -531,7 +531,7 @@ pub fn test(matches: &ArgMatches, triple: Triple) -> io::Result<i32> {
"if there were errors, we would have already exited."
);
if problems.warnings > 0 {
problems.print_to_stdout(start_time.elapsed());
problems.print_error_warning_count(start_time.elapsed());
println!(".\n\nRunning tests…\n\n\x1B[36m{}\x1B[39m", "".repeat(80));
}
}
@ -824,7 +824,7 @@ pub fn build(
// since the process is about to exit anyway.
// std::mem::forget(arena);
problems.print_to_stdout(total_time);
problems.print_error_warning_count(total_time);
println!(" while successfully building:\n\n {generated_filename}");
// Return a nonzero exit code if there were problems
@ -832,7 +832,7 @@ pub fn build(
}
BuildAndRun => {
if problems.fatally_errored {
problems.print_to_stdout(total_time);
problems.print_error_warning_count(total_time);
println!(
".\n\nCannot run program due to fatal error…\n\n\x1B[36m{}\x1B[39m",
"".repeat(80)
@ -842,7 +842,7 @@ pub fn build(
return Ok(problems.exit_code());
}
if problems.errors > 0 || problems.warnings > 0 {
problems.print_to_stdout(total_time);
problems.print_error_warning_count(total_time);
println!(
".\n\nRunning program anyway…\n\n\x1B[36m{}\x1B[39m",
"".repeat(80)
@ -862,7 +862,7 @@ pub fn build(
}
BuildAndRunIfNoErrors => {
if problems.fatally_errored {
problems.print_to_stdout(total_time);
problems.print_error_warning_count(total_time);
println!(
".\n\nCannot run program due to fatal error…\n\n\x1B[36m{}\x1B[39m",
"".repeat(80)
@ -877,7 +877,7 @@ pub fn build(
);
if problems.warnings > 0 {
problems.print_to_stdout(total_time);
problems.print_error_warning_count(total_time);
println!(
".\n\nRunning program…\n\n\x1B[36m{}\x1B[39m",
"".repeat(80)

View File

@ -210,7 +210,7 @@ fn main() -> io::Result<()> {
threading,
) {
Ok((problems, total_time)) => {
problems.print_to_stdout(total_time);
problems.print_error_warning_count(total_time);
Ok(problems.exit_code())
}

View File

@ -649,7 +649,7 @@ pub fn handle_error_module(
let problems = report_problems_typechecked(&mut module);
problems.print_to_stdout(total_time);
problems.print_error_warning_count(total_time);
if print_run_anyway_hint {
// If you're running "main.roc" then you can just do `roc run`

View File

@ -1901,7 +1901,7 @@ fn load_multi_threaded<'a>(
// &mut can_problems_recorded,
// &mut type_problems_recorded,
// )
// .print_to_stdout(Duration::default()); // TODO determine total elapsed time and use it here
// .print_error_warning_count(Duration::default()); // TODO determine total elapsed time and use it here
Err(LoadingProblem::FormattedReport(
concat!(

View File

@ -123,7 +123,7 @@ pub fn generate(
"if there are errors, they should have been returned as an error variant"
);
if problems.warnings > 0 {
problems.print_to_stdout(total_time);
problems.print_error_warning_count(total_time);
println!(
".\n\nRunning glue despite warnings…\n\n\x1B[36m{}\x1B[39m",
"".repeat(80)

View File

@ -27,12 +27,13 @@ impl Problems {
}
}
pub fn print_to_stdout(&self, total_time: std::time::Duration) {
// prints e.g. `1 error and 0 warnings found in 63 ms.`
pub fn print_error_warning_count(&self, total_time: std::time::Duration) {
const GREEN: &str = ANSI_STYLE_CODES.green;
const YELLOW: &str = ANSI_STYLE_CODES.yellow;
print!(
"{}{}\x1B[39m {} and {}{}\x1B[39m {} found in {} ms\n",
println!(
"{}{}\x1B[39m {} and {}{}\x1B[39m {} found in {} ms",
match self.errors {
0 => GREEN,
_ => YELLOW,
@ -56,39 +57,6 @@ impl Problems {
}
}
// prints e.g. `1 error and 0 warnings found in 63 ms.`
pub fn print_error_warning_count(
error_count: usize,
warning_count: usize,
total_time: std::time::Duration,
) {
const GREEN: &str = ANSI_STYLE_CODES.green;
const YELLOW: &str = ANSI_STYLE_CODES.yellow;
print!(
"{}{}\x1B[39m {} and {}{}\x1B[39m {} found in {} ms",
match error_count {
0 => GREEN,
_ => YELLOW,
},
error_count,
match error_count {
1 => "error",
_ => "errors",
},
match warning_count {
0 => GREEN,
_ => YELLOW,
},
warning_count,
match warning_count {
1 => "warning",
_ => "warnings",
},
total_time.as_millis()
);
}
pub fn report_problems(
sources: &MutMap<ModuleId, (PathBuf, Box<str>)>,
interns: &Interns,