From 1a97cce01f8e49b33bf28cbcdfeb3c8aefd809a5 Mon Sep 17 00:00:00 2001 From: Akshay Date: Fri, 29 Oct 2021 18:20:54 +0530 Subject: report syntax errors as statix errors - statix now reports errors also, not just warnings - all diagnostics are available on stderr stream - non-utf8 files are skipped, does not eject early --- bin/src/traits.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'bin/src/traits.rs') diff --git a/bin/src/traits.rs b/bin/src/traits.rs index 465abe4..a8ec70f 100644 --- a/bin/src/traits.rs +++ b/bin/src/traits.rs @@ -9,6 +9,7 @@ use ariadne::{ CharSet, Color, Config as CliConfig, Fmt, Label, LabelAttach, Report as CliReport, ReportKind as CliReportKind, Source, }; +use lib::Severity; use rnix::{TextRange, TextSize}; use vfs::ReadOnlyVfs; @@ -57,11 +58,16 @@ fn write_stderr( .map(|d| d.at.start().into()) .min() .unwrap_or(0usize); + let report_kind = match report.severity { + Severity::Warn => CliReportKind::Warning, + Severity::Error => CliReportKind::Error, + Severity::Hint => CliReportKind::Advice, + }; report .diagnostics .iter() .fold( - CliReport::build(CliReportKind::Warning, src_id, offset) + CliReport::build(report_kind, src_id, offset) .with_config( CliConfig::default() .with_cross_gap(true) @@ -103,7 +109,11 @@ fn write_errfmt( filename = path.to_str().unwrap_or(""), linenumber = line, columnnumber = col, - errortype = "W", + errortype = match report.severity { + Severity::Warn => "W", + Severity::Error => "E", + Severity::Hint => "I", /* "info" message */ + }, errornumber = report.code, errormessage = diagnostic.message )?; @@ -118,6 +128,7 @@ mod json { use std::io::{self, Write}; + use lib::Severity; use rnix::TextRange; use serde::Serialize; use serde_json; @@ -134,6 +145,7 @@ mod json { struct JsonReport<'μ> { note: &'static str, code: u32, + severity: &'μ Severity, diagnostics: Vec>, } @@ -192,6 +204,7 @@ mod json { .map(|r| { let note = r.note; let code = r.code; + let severity = &r.severity; let diagnostics = r .diagnostics .iter() @@ -207,6 +220,7 @@ mod json { JsonReport { note, code, + severity, diagnostics, } }) -- cgit v1.2.3