fix: Respect textual length of paths in find-path

This commit is contained in:
Lukas Wirth 2024-02-16 10:54:54 +01:00
parent b9b0d29b8e
commit c00c9ee959
3 changed files with 68 additions and 11 deletions

View file

@ -94,6 +94,21 @@ impl ModPath {
}
}
pub fn textual_len(&self) -> usize {
let base = match self.kind {
PathKind::Plain => 0,
PathKind::Super(0) => "self".len(),
PathKind::Super(i) => "super".len() * i as usize,
PathKind::Crate => "crate".len(),
PathKind::Abs => 0,
PathKind::DollarCrate(_) => "$crate".len(),
};
self.segments()
.iter()
.map(|segment| segment.as_str().map_or(0, str::len))
.fold(base, core::ops::Add::add)
}
pub fn is_ident(&self) -> bool {
self.as_ident().is_some()
}