mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-02 22:55:08 +00:00
[ty] Show related information in diagnostic (#17359)
This commit is contained in:
parent
55a410a885
commit
6985de4c40
4 changed files with 159 additions and 5 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue