Skip to main content

editor_core/
diagnostics.rs

1//! First-class diagnostics data model.
2//!
3//! This module stores structured diagnostics (errors/warnings/hints) as derived editor state.
4//! Renderers can use this for:
5//! - problems panels / gutter markers
6//! - hover tooltips / inline messages
7//! - mapping diagnostics back to style layers (underlines)
8
9/// A half-open character-offset range (`start..end`) in the document.
10#[derive(Debug, Clone, Copy, PartialEq, Eq)]
11pub struct DiagnosticRange {
12    /// Range start offset (inclusive), in Unicode scalar values (`char`) from the start of the document.
13    pub start: usize,
14    /// Range end offset (exclusive), in Unicode scalar values (`char`) from the start of the document.
15    pub end: usize,
16}
17
18impl DiagnosticRange {
19    /// Create a new diagnostic range.
20    pub fn new(start: usize, end: usize) -> Self {
21        Self { start, end }
22    }
23}
24
25/// Diagnostic severity levels.
26#[derive(Debug, Clone, Copy, PartialEq, Eq)]
27pub enum DiagnosticSeverity {
28    /// Error diagnostics.
29    Error,
30    /// Warning diagnostics.
31    Warning,
32    /// Informational diagnostics.
33    Information,
34    /// Hint diagnostics.
35    Hint,
36}
37
38/// A single diagnostic item for the current document.
39#[derive(Debug, Clone, PartialEq, Eq)]
40pub struct Diagnostic {
41    /// Diagnostic range in character offsets.
42    pub range: DiagnosticRange,
43    /// Optional diagnostic severity.
44    pub severity: Option<DiagnosticSeverity>,
45    /// Optional diagnostic code (stringified).
46    pub code: Option<String>,
47    /// Optional diagnostic source (e.g. `"rust-analyzer"`).
48    pub source: Option<String>,
49    /// Diagnostic message.
50    pub message: String,
51    /// Optional related information payload, encoded as JSON text (if provided by an integration).
52    pub related_information_json: Option<String>,
53    /// Optional extra data payload, encoded as JSON text (if provided by an integration).
54    pub data_json: Option<String>,
55}