use super::location::{FileSpan, ROOT_ORIGIN, Span};
#[derive(Debug)]
pub enum Severity {
Error = 1,
Warning = 2,
Information = 3,
Hint = 4,
}
impl Severity {
pub fn to_lsp(&self) -> lsp_types::DiagnosticSeverity {
match self {
Severity::Error => lsp_types::DiagnosticSeverity::ERROR,
Severity::Warning => lsp_types::DiagnosticSeverity::WARNING,
Severity::Information => lsp_types::DiagnosticSeverity::INFORMATION,
Severity::Hint => lsp_types::DiagnosticSeverity::HINT,
}
}
}
#[derive(Debug)]
pub struct Diagnostic {
pub span: FileSpan,
pub severity: Severity,
pub source: &'static str,
pub message: String,
}
impl Diagnostic {
pub fn new(span: FileSpan, severity: Severity, source: &'static str, message: String) -> Self {
Self {
span,
severity,
source,
message,
}
}
}
#[derive(Debug, Default)]
pub struct FileDiagnostics {
list: Vec<Diagnostic>,
}
impl FileDiagnostics {
pub fn push(&mut self, span: Span, severity: Severity, source: &'static str, message: String) {
if span.origin != ROOT_ORIGIN {
return;
}
self.list
.push(Diagnostic::new(span.text_span, severity, source, message));
}
pub fn get(&self) -> &[Diagnostic] {
&self.list
}
}