From a8d0004fdd71edbaa143a1b052d093e712b7867e Mon Sep 17 00:00:00 2001 From: Sofia R Date: Mon, 8 May 2023 17:02:02 -0300 Subject: [PATCH 1/2] feat: added flag to remove error dependenies --- crates/kind-cli/src/main.rs | 28 +++++++++++++++++-- crates/kind-report/src/data.rs | 2 +- crates/kind-report/src/lib.rs | 18 +++++++----- crates/kind-report/src/report/mode/classic.rs | 18 ++++++++---- crates/kind-span/src/lib.rs | 5 ++++ crates/kind-tests/tests/mod.rs | 2 +- 6 files changed, 56 insertions(+), 17 deletions(-) diff --git a/crates/kind-cli/src/main.rs b/crates/kind-cli/src/main.rs index 45f3e7c3..04e5e96b 100644 --- a/crates/kind-cli/src/main.rs +++ b/crates/kind-cli/src/main.rs @@ -57,6 +57,10 @@ pub struct Cli { #[arg(long)] pub hide_vals: bool, + /// Show only the first error message + #[arg(long)] + pub hide_deps: bool, + /// Entrypoint of the file that makes the erasure checker /// not remove the entry. #[arg(short, long)] @@ -174,11 +178,24 @@ pub fn compile_in_session( let mut contains_error = false; + let mut hidden = 0; + let total = diagnostics.len() as u64; + for diagnostic in diagnostics { if diagnostic.get_severity() == Severity::Error { contains_error = true; } + let is_root = diagnostic + .get_syntax_ctx() + .map(|x| x.is_root()) + .unwrap_or_default(); + + if render_config.only_main && !is_root { + hidden += 1; + continue; + } + render_to_stderr(render_config, &session, &diagnostic) } @@ -197,7 +214,7 @@ pub fn compile_in_session( res } else { - render_to_stderr(render_config, &session, &Log::Failed(start.elapsed())); + render_to_stderr(render_config, &session, &Log::Failed(start.elapsed(), total, hidden)); eprintln!(); match res { @@ -216,7 +233,14 @@ pub fn run_cli(config: Cli) -> anyhow::Result<()> { Mode::Classic }; - let render_config = kind_report::check_if_utf8_is_supported(config.ascii, 2, config.hide_vals, mode); + let render_config = kind_report::check_if_utf8_is_supported( + config.ascii, + 2, + config.hide_vals, + mode, + config.hide_deps, + ); + let root = config.root.unwrap_or_else(|| PathBuf::from(".")); let mut entrypoints = vec!["Main".to_string()]; diff --git a/crates/kind-report/src/data.rs b/crates/kind-report/src/data.rs index f856c7d8..2c1fb38b 100644 --- a/crates/kind-report/src/data.rs +++ b/crates/kind-report/src/data.rs @@ -72,7 +72,7 @@ pub enum Log { Checked(Duration), Compiled(Duration), Rewrites(u64), - Failed(Duration), + Failed(Duration, u64, u64), } pub trait Diagnostic { diff --git a/crates/kind-report/src/lib.rs b/crates/kind-report/src/lib.rs index 0a11ac69..6cc9b4f8 100644 --- a/crates/kind-report/src/lib.rs +++ b/crates/kind-report/src/lib.rs @@ -54,36 +54,40 @@ pub struct RenderConfig<'a> { pub hide_vals: bool, pub mode: Mode, pub not_align: bool, + pub only_main: bool, } impl<'a> RenderConfig<'a> { - pub fn unicode(indent: usize, hide_vals: bool) -> RenderConfig<'a> { + pub fn unicode(indent: usize, hide_vals: bool, only_main: bool) -> RenderConfig<'a> { RenderConfig { chars: Chars::unicode(), indent, hide_vals, mode: Mode::Classic, not_align: false, + only_main } } - pub fn ascii(indent: usize, hide_vals: bool) -> RenderConfig<'a> { + pub fn ascii(indent: usize, hide_vals: bool, only_main: bool) -> RenderConfig<'a> { RenderConfig { chars: Chars::ascii(), indent, hide_vals, mode: Mode::Classic, not_align: false, + only_main } } - pub fn compact(indent: usize) -> RenderConfig<'a> { + pub fn compact(indent: usize, only_main: bool) -> RenderConfig<'a> { RenderConfig { chars: Chars::ascii(), indent, hide_vals: true, mode: Mode::Compact, not_align: true, + only_main } } } @@ -94,15 +98,15 @@ pub fn check_if_colors_are_supported(disable: bool) { } } -pub fn check_if_utf8_is_supported<'a>(disable: bool, indent: usize, hide_vals: bool, mode: Mode) -> RenderConfig<'a> { +pub fn check_if_utf8_is_supported<'a>(disable: bool, indent: usize, hide_vals: bool, mode: Mode, only_main: bool) -> RenderConfig<'a> { match mode { Mode::Classic => { if disable || (cfg!(windows) && !Paint::enable_windows_ascii()) { - RenderConfig::ascii(indent, hide_vals) + RenderConfig::ascii(indent, hide_vals, only_main) } else { - RenderConfig::unicode(indent, hide_vals) + RenderConfig::unicode(indent, hide_vals, only_main) } }, - Mode::Compact => RenderConfig::compact(0), + Mode::Compact => RenderConfig::compact(0, only_main), } } diff --git a/crates/kind-report/src/report/mode/classic.rs b/crates/kind-report/src/report/mode/classic.rs index a7e347e1..73929cd1 100644 --- a/crates/kind-report/src/report/mode/classic.rs +++ b/crates/kind-report/src/report/mode/classic.rs @@ -1,10 +1,10 @@ use super::CodeBlock; use super::{Classic, Renderable, Res}; use crate::data::*; -use crate::report::code::{count_width, group_markers, LineGuide, Spaces}; use crate::report::code::Point; -use crate::RenderConfig; +use crate::report::code::{count_width, group_markers, LineGuide, Spaces}; use crate::report::group_marker_lines; +use crate::RenderConfig; use pathdiff::diff_paths; use std::fmt::Write; @@ -368,12 +368,18 @@ impl Renderable for Log { duration.as_secs_f32() ) } - Log::Failed(duration) => { + Log::Failed(duration, total, hidden) => { writeln!( fmt, - " {} Took {}s", + " {} Took {:.1}s, {}{} total", Paint::new(" FAILED ").bg(yansi::Color::Red).bold(), - duration.as_secs() + duration.as_secs_f32(), + if *hidden == 0 { + "".to_string() + } else { + format!("{} hidden errors, ", hidden) + }, + total ) } Log::Rewrites(u64) => { @@ -444,4 +450,4 @@ impl Renderable for DiagnosticFrame { Ok(()) } -} \ No newline at end of file +} diff --git a/crates/kind-span/src/lib.rs b/crates/kind-span/src/lib.rs index 97f9a061..9c585134 100644 --- a/crates/kind-span/src/lib.rs +++ b/crates/kind-span/src/lib.rs @@ -12,6 +12,11 @@ impl SyntaxCtxIndex { pub fn new(size: usize) -> SyntaxCtxIndex { SyntaxCtxIndex(size) } + + /// WARNING: Probably ghost ranges cause problems with it + pub fn is_root(&self) -> bool { + self.0 == 0 + } } /// A span in the encoded format that is required by diff --git a/crates/kind-tests/tests/mod.rs b/crates/kind-tests/tests/mod.rs index e33a7fa6..5d604b71 100644 --- a/crates/kind-tests/tests/mod.rs +++ b/crates/kind-tests/tests/mod.rs @@ -40,7 +40,7 @@ fn test_kind2(path: &Path, run: fn(&PathBuf, &mut Session) -> Option) -> let res = run(&PathBuf::from(path), &mut session); let diagnostics = tx.try_iter().collect::>>(); - let render = RenderConfig::ascii(2, false); + let render = RenderConfig::ascii(2, false, false); kind_report::check_if_colors_are_supported(true); From ccbca71f599a079263ace1ce02ec62cdd7f9bf47 Mon Sep 17 00:00:00 2001 From: Sofia R Date: Mon, 8 May 2023 17:04:40 -0300 Subject: [PATCH 2/2] feat: improved error message for fails --- crates/kind-report/src/report/mode/classic.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/kind-report/src/report/mode/classic.rs b/crates/kind-report/src/report/mode/classic.rs index 73929cd1..4f1f6d3c 100644 --- a/crates/kind-report/src/report/mode/classic.rs +++ b/crates/kind-report/src/report/mode/classic.rs @@ -371,15 +371,15 @@ impl Renderable for Log { Log::Failed(duration, total, hidden) => { writeln!( fmt, - " {} Took {:.1}s, {}{} total", + " {} Took {:.1}s, {} errors{}", Paint::new(" FAILED ").bg(yansi::Color::Red).bold(), duration.as_secs_f32(), + total, if *hidden == 0 { "".to_string() } else { - format!("{} hidden errors, ", hidden) + format!(", {} hidden", hidden) }, - total ) } Log::Rewrites(u64) => {