merge: pull request #563 from HigherOrderCO/562-add-flag-to-remove-dependency-errors

Feat added flag to remove error dependenies
This commit is contained in:
Sofia Rodrigues 2023-05-08 17:05:35 -03:00 committed by GitHub
commit fb550066a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 56 additions and 17 deletions

View File

@ -57,6 +57,10 @@ pub struct Cli {
#[arg(long)] #[arg(long)]
pub hide_vals: bool, 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 /// Entrypoint of the file that makes the erasure checker
/// not remove the entry. /// not remove the entry.
#[arg(short, long)] #[arg(short, long)]
@ -174,11 +178,24 @@ pub fn compile_in_session<T>(
let mut contains_error = false; let mut contains_error = false;
let mut hidden = 0;
let total = diagnostics.len() as u64;
for diagnostic in diagnostics { for diagnostic in diagnostics {
if diagnostic.get_severity() == Severity::Error { if diagnostic.get_severity() == Severity::Error {
contains_error = true; 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) render_to_stderr(render_config, &session, &diagnostic)
} }
@ -197,7 +214,7 @@ pub fn compile_in_session<T>(
res res
} else { } else {
render_to_stderr(render_config, &session, &Log::Failed(start.elapsed())); render_to_stderr(render_config, &session, &Log::Failed(start.elapsed(), total, hidden));
eprintln!(); eprintln!();
match res { match res {
@ -216,7 +233,14 @@ pub fn run_cli(config: Cli) -> anyhow::Result<()> {
Mode::Classic 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 root = config.root.unwrap_or_else(|| PathBuf::from("."));
let mut entrypoints = vec!["Main".to_string()]; let mut entrypoints = vec!["Main".to_string()];

View File

@ -72,7 +72,7 @@ pub enum Log {
Checked(Duration), Checked(Duration),
Compiled(Duration), Compiled(Duration),
Rewrites(u64), Rewrites(u64),
Failed(Duration), Failed(Duration, u64, u64),
} }
pub trait Diagnostic { pub trait Diagnostic {

View File

@ -54,36 +54,40 @@ pub struct RenderConfig<'a> {
pub hide_vals: bool, pub hide_vals: bool,
pub mode: Mode, pub mode: Mode,
pub not_align: bool, pub not_align: bool,
pub only_main: bool,
} }
impl<'a> RenderConfig<'a> { 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 { RenderConfig {
chars: Chars::unicode(), chars: Chars::unicode(),
indent, indent,
hide_vals, hide_vals,
mode: Mode::Classic, mode: Mode::Classic,
not_align: false, 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 { RenderConfig {
chars: Chars::ascii(), chars: Chars::ascii(),
indent, indent,
hide_vals, hide_vals,
mode: Mode::Classic, mode: Mode::Classic,
not_align: false, not_align: false,
only_main
} }
} }
pub fn compact(indent: usize) -> RenderConfig<'a> { pub fn compact(indent: usize, only_main: bool) -> RenderConfig<'a> {
RenderConfig { RenderConfig {
chars: Chars::ascii(), chars: Chars::ascii(),
indent, indent,
hide_vals: true, hide_vals: true,
mode: Mode::Compact, mode: Mode::Compact,
not_align: true, 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 { match mode {
Mode::Classic => { Mode::Classic => {
if disable || (cfg!(windows) && !Paint::enable_windows_ascii()) { if disable || (cfg!(windows) && !Paint::enable_windows_ascii()) {
RenderConfig::ascii(indent, hide_vals) RenderConfig::ascii(indent, hide_vals, only_main)
} else { } 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),
} }
} }

View File

@ -1,10 +1,10 @@
use super::CodeBlock; use super::CodeBlock;
use super::{Classic, Renderable, Res}; use super::{Classic, Renderable, Res};
use crate::data::*; use crate::data::*;
use crate::report::code::{count_width, group_markers, LineGuide, Spaces};
use crate::report::code::Point; 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::report::group_marker_lines;
use crate::RenderConfig;
use pathdiff::diff_paths; use pathdiff::diff_paths;
use std::fmt::Write; use std::fmt::Write;
@ -368,12 +368,18 @@ impl Renderable<Classic> for Log {
duration.as_secs_f32() duration.as_secs_f32()
) )
} }
Log::Failed(duration) => { Log::Failed(duration, total, hidden) => {
writeln!( writeln!(
fmt, fmt,
" {} Took {}s", " {} Took {:.1}s, {} errors{}",
Paint::new(" FAILED ").bg(yansi::Color::Red).bold(), Paint::new(" FAILED ").bg(yansi::Color::Red).bold(),
duration.as_secs() duration.as_secs_f32(),
total,
if *hidden == 0 {
"".to_string()
} else {
format!(", {} hidden", hidden)
},
) )
} }
Log::Rewrites(u64) => { Log::Rewrites(u64) => {
@ -444,4 +450,4 @@ impl Renderable<Classic> for DiagnosticFrame {
Ok(()) Ok(())
} }
} }

View File

@ -12,6 +12,11 @@ impl SyntaxCtxIndex {
pub fn new(size: usize) -> SyntaxCtxIndex { pub fn new(size: usize) -> SyntaxCtxIndex {
SyntaxCtxIndex(size) 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 /// A span in the encoded format that is required by

View File

@ -40,7 +40,7 @@ fn test_kind2(path: &Path, run: fn(&PathBuf, &mut Session) -> Option<String>) ->
let res = run(&PathBuf::from(path), &mut session); let res = run(&PathBuf::from(path), &mut session);
let diagnostics = tx.try_iter().collect::<Vec<Box<dyn Diagnostic>>>(); let diagnostics = tx.try_iter().collect::<Vec<Box<dyn Diagnostic>>>();
let render = RenderConfig::ascii(2, false); let render = RenderConfig::ascii(2, false, false);
kind_report::check_if_colors_are_supported(true); kind_report::check_if_colors_are_supported(true);