use std::path::PathBuf;
use crate::parser::SyntaxError;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Severity {
Error,
Warning,
Info,
Hint,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Applicability {
Safe,
Unsafe,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Fix {
pub content: String,
pub start: usize,
pub end: usize,
pub applicability: Applicability,
pub description: String,
}
impl Fix {
pub fn safe(
start: usize,
end: usize,
content: impl Into<String>,
description: impl Into<String>,
) -> Self {
Self {
content: content.into(),
start,
end,
applicability: Applicability::Safe,
description: description.into(),
}
}
pub fn unsafe_(
start: usize,
end: usize,
content: impl Into<String>,
description: impl Into<String>,
) -> Self {
Self {
content: content.into(),
start,
end,
applicability: Applicability::Unsafe,
description: description.into(),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Diagnostic {
pub rule: &'static str,
pub severity: Severity,
pub path: PathBuf,
pub start: usize,
pub end: usize,
pub message: String,
pub fix: Option<Fix>,
}
impl Diagnostic {
pub fn from_parse(path: PathBuf, error: &SyntaxError) -> Self {
Self {
rule: "parse",
severity: Severity::Error,
path,
start: error.start,
end: error.end,
message: error.message.clone(),
fix: None,
}
}
}