#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd)] #[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] pubenum LabelStyle { /// Labels that describe the primary cause of a diagnostic.
Primary, /// Labels that provide additional context for a diagnostic.
Secondary,
}
/// A label describing an underlined region of code associated with a diagnostic. #[derive(Clone, Debug, PartialEq, Eq)] #[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] pubstruct Label<FileId> { /// The style of the label. pub style: LabelStyle, /// The file that we are labelling. pub file_id: FileId, /// The range in bytes we are going to include in the final snippet. pub range: Range<usize>, /// An optional message to provide some additional information for the /// underlined code. These should not include line breaks. pub message: String,
}
/// Create a new label with a style of [`LabelStyle::Primary`]. /// /// [`LabelStyle::Primary`]: LabelStyle::Primary pubfn primary(file_id: FileId, range: impl Into<Range<usize>>) -> Label<FileId> {
Label::new(LabelStyle::Primary, file_id, range)
}
/// Create a new label with a style of [`LabelStyle::Secondary`]. /// /// [`LabelStyle::Secondary`]: LabelStyle::Secondary pubfn secondary(file_id: FileId, range: impl Into<Range<usize>>) -> Label<FileId> {
Label::new(LabelStyle::Secondary, file_id, range)
}
/// Add a message to the diagnostic. pubfn with_message(mutself, message: impl Into<String>) -> Label<FileId> { self.message = message.into(); self
}
}
/// 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. #[derive(Clone, Debug, PartialEq, Eq)] #[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] pubstruct Diagnostic<FileId> { /// The overall severity of the diagnostic pub severity: Severity, /// An optional code that identifies this diagnostic. pub code: Option<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. pub message: String, /// 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. pub labels: Vec<Label<FileId>>, /// Notes that are associated with the primary cause of the diagnostic. /// These can include line breaks for improved formatting. pub notes: Vec<String>,
}
/// Create a new diagnostic with a severity of [`Severity::Bug`]. /// /// [`Severity::Bug`]: Severity::Bug pubfn bug() -> Diagnostic<FileId> {
Diagnostic::new(Severity::Bug)
}
/// Create a new diagnostic with a severity of [`Severity::Error`]. /// /// [`Severity::Error`]: Severity::Error pubfn error() -> Diagnostic<FileId> {
Diagnostic::new(Severity::Error)
}
/// Create a new diagnostic with a severity of [`Severity::Warning`]. /// /// [`Severity::Warning`]: Severity::Warning pubfn warning() -> Diagnostic<FileId> {
Diagnostic::new(Severity::Warning)
}
/// Create a new diagnostic with a severity of [`Severity::Note`]. /// /// [`Severity::Note`]: Severity::Note pubfn note() -> Diagnostic<FileId> {
Diagnostic::new(Severity::Note)
}
/// Create a new diagnostic with a severity of [`Severity::Help`]. /// /// [`Severity::Help`]: Severity::Help pubfn help() -> Diagnostic<FileId> {
Diagnostic::new(Severity::Help)
}
/// Set the error code of the diagnostic. pubfn with_code(mutself, code: impl Into<String>) -> Diagnostic<FileId> { self.code = Some(code.into()); self
}
/// Set the message of the diagnostic. pubfn with_message(mutself, message: impl Into<String>) -> Diagnostic<FileId> { self.message = message.into(); self
}
/// Add some labels to the diagnostic. pubfn with_labels(mutself, mut labels: Vec<Label<FileId>>) -> Diagnostic<FileId> { self.labels.append(&mut labels); self
}
/// Add some notes to the diagnostic. pubfn with_notes(mutself, mut notes: Vec<String>) -> Diagnostic<FileId> { self.notes.append(&mut notes); self
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.9 Sekunden
(vorverarbeitet am 2026-06-27)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.