From 43bd0437559a5c267b1ac8b44dfc436d7fcff3bb Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Wed, 23 Apr 2025 11:23:51 -0400 Subject: [PATCH] ruff_db: add a `From` impl for `FileRange` to `Span` These types are almost equivalent. The only difference is that a `Span`'s range is optional. --- crates/ruff_db/src/diagnostic/mod.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/ruff_db/src/diagnostic/mod.rs b/crates/ruff_db/src/diagnostic/mod.rs index 3478d105b5..02b298afbb 100644 --- a/crates/ruff_db/src/diagnostic/mod.rs +++ b/crates/ruff_db/src/diagnostic/mod.rs @@ -3,7 +3,7 @@ use std::{fmt::Formatter, sync::Arc}; use thiserror::Error; use ruff_annotate_snippets::Level as AnnotateLevel; -use ruff_text_size::TextRange; +use ruff_text_size::{Ranged, TextRange}; pub use self::render::DisplayDiagnostic; use crate::files::File; @@ -601,6 +601,12 @@ impl From for Span { } } +impl From for Span { + fn from(file_range: crate::files::FileRange) -> Span { + Span::from(file_range.file()).with_range(file_range.range()) + } +} + #[derive(Debug, Clone, Copy, PartialEq, Eq, Ord, PartialOrd)] pub enum Severity { Info,