blues-lsp 0.1.3

LSP language server for the Bluespec SystemVerilog language
Documentation
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) {
        // TODO: would be helpfull to emit additional diagnostics in header files?
        if span.origin != ROOT_ORIGIN {
            return;
        }
        // TODO: a limit to emited diagnostics is probably also a good idea...
        self.list
            .push(Diagnostic::new(span.text_span, severity, source, message));
    }

    pub fn get(&self) -> &[Diagnostic] {
        &self.list
    }
}