From 57be814acb4de646fc5be83c553f5a208e000474 Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Fri, 21 Mar 2025 13:48:57 -0400 Subject: [PATCH] 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. --- crates/ruff_db/src/diagnostic/old.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/crates/ruff_db/src/diagnostic/old.rs b/crates/ruff_db/src/diagnostic/old.rs index 735915ff2d..015270f7b9 100644 --- a/crates/ruff_db/src/diagnostic/old.rs +++ b/crates/ruff_db/src/diagnostic/old.rs @@ -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`