pub struct Diagnostic<FileId> {
pub severity: Severity,
pub code: Option<String>,
pub message: String,
pub labels: Vec<Label<FileId>>,
pub notes: Vec<String>,
pub subdiagnostics: Vec<Subdiagnostic<FileId>>,
}
Expand description
Represents a diagnostic message that can provide information like errors and warnings to the user.
The position of a Diagnostic is considered to be the position of the Label
that has the earliest starting position and has the highest style which appears in all the labels of the diagnostic.
Fields§
§severity: Severity
The overall severity of the diagnostic
code: Option<String>
An optional code that identifies this diagnostic.
message: String
The main message associated with this diagnostic.
These should not include line breaks, and in order support the ‘short’ diagnostic display mod, the message should be specific enough to make sense on its own, without additional context provided by labels and notes.
labels: Vec<Label<FileId>>
Source labels that describe the cause of the diagnostic. The order of the labels inside the vector does not have any meaning. The labels are always arranged in the order they appear in the source code.
notes: Vec<String>
Notes that are associated with the primary cause of the diagnostic. These can include line breaks for improved formatting.
subdiagnostics: Vec<Subdiagnostic<FileId>>
A list of diagnostics that are “attached” to the main diagnostic. They are rendered below the main diagnostic but still as one “unit”. For example, a note with one or more labels can be attached to a warning to give additional information that doesn’t make sense to group with the labels.
Implementations§
Source§impl<FileId> Diagnostic<FileId>
impl<FileId> Diagnostic<FileId>
Sourcepub fn bug() -> Self
pub fn bug() -> Self
Create a new diagnostic with a severity of Severity::Bug
.
Sourcepub fn error() -> Self
pub fn error() -> Self
Create a new diagnostic with a severity of Severity::Error
.
Sourcepub fn warning() -> Self
pub fn warning() -> Self
Create a new diagnostic with a severity of Severity::Warning
.
Sourcepub fn note() -> Self
pub fn note() -> Self
Create a new diagnostic with a severity of Severity::Note
.
Sourcepub fn help() -> Self
pub fn help() -> Self
Create a new diagnostic with a severity of Severity::Help
.
Sourcepub fn with_message(self, message: impl ToString) -> Self
pub fn with_message(self, message: impl ToString) -> Self
Set the message of the diagnostic.
Sourcepub fn with_label(self, label: Label<FileId>) -> Self
pub fn with_label(self, label: Label<FileId>) -> Self
Add a label to the diagnostic.
Sourcepub fn with_labels(self, labels: Vec<Label<FileId>>) -> Self
pub fn with_labels(self, labels: Vec<Label<FileId>>) -> Self
Add some labels to the diagnostic.
Sourcepub fn with_labels_iter<I>(self, labels: I) -> Selfwhere
I: IntoIterator<Item = Label<FileId>>,
pub fn with_labels_iter<I>(self, labels: I) -> Selfwhere
I: IntoIterator<Item = Label<FileId>>,
Add some labels from an iterator to the diagnostic.
Sourcepub fn with_notes(self, notes: Vec<String>) -> Self
pub fn with_notes(self, notes: Vec<String>) -> Self
Add some notes to the diagnostic.
Sourcepub fn with_notes_iter<I, T>(self, notes: I) -> Self
pub fn with_notes_iter<I, T>(self, notes: I) -> Self
Add notes from an iterator to the diagnostic.
Sourcepub fn with_suggestions(self, suggestions: Vec<Suggestion<FileId>>) -> Self
pub fn with_suggestions(self, suggestions: Vec<Suggestion<FileId>>) -> Self
Add some suggestions to the diagnostic.
Convenience method for Self::with_subdiagnostics. Use that if you want to interleave suggestions with other Subdiagnostics.
Sourcepub fn with_spanned_notes(self, spanned_notes: Vec<SpannedNote<FileId>>) -> Self
pub fn with_spanned_notes(self, spanned_notes: Vec<SpannedNote<FileId>>) -> Self
Add some spanned notes to the diagnostic.
Convenience method for Self::with_subdiagnostics. Use that if you want to interleave spanned notes with other Subdiagnostics.
Sourcepub fn with_subdiagnostics(
self,
subdiagnostics: Vec<Subdiagnostic<FileId>>,
) -> Diagnostic<FileId>
pub fn with_subdiagnostics( self, subdiagnostics: Vec<Subdiagnostic<FileId>>, ) -> Diagnostic<FileId>
Add some subdiagnostics to the diagnostic.
Trait Implementations§
Source§impl<FileId: Clone> Clone for Diagnostic<FileId>
impl<FileId: Clone> Clone for Diagnostic<FileId>
Source§fn clone(&self) -> Diagnostic<FileId>
fn clone(&self) -> Diagnostic<FileId>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more