Skip to main content

only_diagnostic/
diagnostic.rs

1use text_size::TextRange;
2
3use crate::{DiagnosticCode, DiagnosticLabel, DiagnosticPhase, DiagnosticSeverity};
4
5#[derive(Debug, Clone, PartialEq, Eq)]
6pub struct Diagnostic {
7    pub severity: DiagnosticSeverity,
8    pub message: String,
9    pub code: DiagnosticCode,
10    pub primary_range: TextRange,
11    pub secondary_ranges: Vec<TextRange>,
12    pub labels: Vec<DiagnosticLabel>,
13    pub phase: DiagnosticPhase,
14}
15
16impl Diagnostic {
17    /// Creates a diagnostic with a single primary range.
18    ///
19    /// Args:
20    /// severity: Host-facing severity level.
21    /// code: Stable machine-readable code.
22    /// message: Human-readable summary.
23    /// phase: Pipeline stage that produced the issue.
24    /// primary_range: Main highlighted source range.
25    ///
26    /// Returns:
27    /// New diagnostic value.
28    pub fn new(
29        severity: DiagnosticSeverity,
30        code: DiagnosticCode,
31        message: impl Into<String>,
32        phase: DiagnosticPhase,
33        primary_range: TextRange,
34    ) -> Self {
35        Self {
36            severity,
37            message: message.into(),
38            code,
39            primary_range,
40            secondary_ranges: Vec::new(),
41            labels: Vec::new(),
42            phase,
43        }
44    }
45}