pub struct Diagnostic {
pub code: DiagnosticCode,
pub severity: Severity,
pub message: String,
pub file: Option<PathBuf>,
pub span: Option<SourceSpan>,
pub secondary_spans: Vec<SourceSpan>,
pub notes: Vec<String>,
pub hints: Vec<String>,
}Expand description
A diagnostic message emitted during analysis or scheduling
Diagnostics are structured data representing errors, warnings, hints, or informational messages. The message text is fully rendered at emission time according to the specification in DIAGNOSTICS.md.
§Example
use utf8proj_core::{Diagnostic, DiagnosticCode, Severity};
let diagnostic = Diagnostic::new(
DiagnosticCode::W001AbstractAssignment,
"task 'api_dev' is assigned to abstract profile 'developer'"
);
assert_eq!(diagnostic.severity, Severity::Warning);
assert_eq!(diagnostic.code.as_str(), "W001");Fields§
§code: DiagnosticCodeThe diagnostic code
severity: SeveritySeverity level (derived from code by default)
message: StringThe primary message (fully rendered)
file: Option<PathBuf>Source file path (if applicable)
span: Option<SourceSpan>Primary source span (if applicable)
secondary_spans: Vec<SourceSpan>Additional spans for related locations
notes: Vec<String>Additional notes (displayed after the main message)
hints: Vec<String>Hints for fixing the issue
Implementations§
Source§impl Diagnostic
impl Diagnostic
Sourcepub fn new(code: DiagnosticCode, message: impl Into<String>) -> Self
pub fn new(code: DiagnosticCode, message: impl Into<String>) -> Self
Create a new diagnostic with the given code and message
Severity is derived from the diagnostic code’s default.
Sourcepub fn error(code: DiagnosticCode, message: impl Into<String>) -> Self
pub fn error(code: DiagnosticCode, message: impl Into<String>) -> Self
Create an error diagnostic
Sourcepub fn warning(code: DiagnosticCode, message: impl Into<String>) -> Self
pub fn warning(code: DiagnosticCode, message: impl Into<String>) -> Self
Create a warning diagnostic
Sourcepub fn with_span(self, span: SourceSpan) -> Self
pub fn with_span(self, span: SourceSpan) -> Self
Set the primary source span
Sourcepub fn with_secondary_span(self, span: SourceSpan) -> Self
pub fn with_secondary_span(self, span: SourceSpan) -> Self
Add a secondary span
Sourcepub fn is_warning(&self) -> bool
pub fn is_warning(&self) -> bool
Returns true if this is a warning-level diagnostic
Trait Implementations§
Source§impl Clone for Diagnostic
impl Clone for Diagnostic
Source§fn clone(&self) -> Diagnostic
fn clone(&self) -> Diagnostic
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more