[ty] Show related information in diagnostic (#17359)

This commit is contained in:
Micha Reiser 2025-05-19 18:52:12 +02:00 committed by GitHub
parent 55a410a885
commit 6985de4c40
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 159 additions and 5 deletions

View file

@ -11,6 +11,7 @@ use ruff_text_size::{Ranged, TextRange};
use salsa::plumbing::AsId;
use salsa::{Durability, Setter};
use crate::diagnostic::{Span, UnifiedFile};
use crate::file_revision::FileRevision;
use crate::files::file_root::FileRoots;
use crate::files::private::FileStatus;
@ -549,6 +550,29 @@ impl Ranged for FileRange {
}
}
impl TryFrom<&Span> for FileRange {
type Error = ();
fn try_from(value: &Span) -> Result<Self, Self::Error> {
let UnifiedFile::Ty(file) = value.file() else {
return Err(());
};
Ok(Self {
file: *file,
range: value.range().ok_or(())?,
})
}
}
impl TryFrom<Span> for FileRange {
type Error = ();
fn try_from(value: Span) -> Result<Self, Self::Error> {
Self::try_from(&value)
}
}
#[cfg(test)]
mod tests {
use crate::file_revision::FileRevision;