1
Fork 0

Make diagnostics clearer for ? operators

This commit is contained in:
Yuki Okushi 2021-06-17 06:35:42 +09:00
parent 78a46efff0
commit 378300a63d
No known key found for this signature in database
GPG key ID: DABA5B072961C18A
6 changed files with 53 additions and 5 deletions

View file

@ -74,6 +74,10 @@ impl DiagnosticStyledString {
pub fn highlighted<S: Into<String>>(t: S) -> DiagnosticStyledString {
DiagnosticStyledString(vec![StringPart::Highlighted(t.into())])
}
pub fn content(&self) -> String {
self.0.iter().map(|x| x.content()).collect::<String>()
}
}
#[derive(Debug, PartialEq, Eq)]
@ -82,6 +86,14 @@ pub enum StringPart {
Highlighted(String),
}
impl StringPart {
pub fn content(&self) -> &str {
match self {
&StringPart::Normal(ref s) | &StringPart::Highlighted(ref s) => s,
}
}
}
impl Diagnostic {
pub fn new(level: Level, message: &str) -> Self {
Diagnostic::new_with_code(level, None, message)