mirror of https://github.com/astral-sh/ruff
ruff_db: add method to create sub-diagnostics from old secondary messages
This is temporary to scaffold the refactor. The main idea is that we want to take the `InferContext` API, *as it is*, and migrate that to the new diagnostic data model *internally*. Then we can rip out the old stuff and iterate on the API.
This commit is contained in:
parent
a8a18e7171
commit
57be814acb
|
|
@ -61,6 +61,12 @@ impl OldSecondaryDiagnosticMessage {
|
|||
message: message.into(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_sub_diagnostic(&self) -> SubDiagnostic {
|
||||
let mut sub = SubDiagnostic::new(Severity::Info, "");
|
||||
sub.annotate(Annotation::secondary(self.span.clone()).message(&self.message));
|
||||
sub
|
||||
}
|
||||
}
|
||||
|
||||
pub struct OldDisplayDiagnostic<'db, 'diag, 'config> {
|
||||
|
|
@ -126,11 +132,7 @@ impl std::fmt::Display for OldDisplayDiagnostic<'_, '_, '_> {
|
|||
// empty. This leads to somewhat awkward rendering, but
|
||||
// the way to fix that is to migrate Red Knot to the more
|
||||
// expressive `Diagnostic` API.
|
||||
let mut sub = SubDiagnostic::new(Severity::Info, "");
|
||||
sub.annotate(
|
||||
Annotation::secondary(secondary_msg.span.clone()).message(&secondary_msg.message),
|
||||
);
|
||||
diag.sub(sub);
|
||||
diag.sub(secondary_msg.to_sub_diagnostic());
|
||||
}
|
||||
|
||||
// The main way to print a `Diagnostic` is via its `print`
|
||||
|
|
|
|||
Loading…
Reference in New Issue