use serde::Serialize;
use strum_macros::{Display, EnumCount, EnumIter, EnumString, IntoStaticStr};
use crate::report::ErrorKey;
use crate::token::Loc;
pub type LogReport = (LogReportMetadata, LogReportPointers);
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub enum LogReportStyle {
Full,
Abbreviated,
}
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
pub struct LogReportMetadata {
pub severity: Severity,
pub confidence: Confidence,
pub key: ErrorKey,
pub msg: String,
pub info: Option<String>,
pub wiki: Option<String>,
pub style: LogReportStyle,
}
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
pub struct PointedMessage {
pub loc: Loc,
pub length: usize,
pub msg: Option<String>,
}
impl PointedMessage {
pub fn new(loc: Loc) -> Self {
Self { loc, msg: None, length: 0 }
}
}
pub type LogReportPointers = Vec<PointedMessage>;
pub fn pointer_indentation(pointers: &LogReportPointers) -> usize {
pointers.iter().map(|pointer| pointer.loc.line.to_string().len()).max().unwrap_or(0)
}
#[derive(
Default,
Debug,
Display,
Clone,
Copy,
Ord,
PartialOrd,
Eq,
PartialEq,
Hash,
IntoStaticStr,
EnumString,
EnumCount,
EnumIter,
Serialize,
)]
#[serde(rename_all = "kebab-case")]
#[strum(serialize_all = "kebab-case")]
pub enum Severity {
Tips,
Untidy,
#[default]
Warning,
Error,
Fatal,
}
impl Severity {
#[must_use]
pub fn at_most(self, max_sev: Severity) -> Severity {
if self == Severity::Fatal { Severity::Fatal } else { self.min(max_sev) }
}
}
#[derive(
Default,
Debug,
Clone,
Copy,
Ord,
PartialOrd,
Eq,
PartialEq,
Hash,
IntoStaticStr,
EnumIter,
EnumString,
Serialize,
)]
#[serde(rename_all = "kebab-case")]
#[strum(serialize_all = "kebab-case")]
pub enum Confidence {
Weak,
#[default]
Reasonable,
Strong,
}