feat: Make unlinked_file diagnostic quickfixes work for inline modules

This commit is contained in:
Lukas Wirth 2023-01-11 22:39:05 +01:00
parent bb4e272d8a
commit 1ce3e820dc
3 changed files with 202 additions and 42 deletions

View file

@ -1,7 +1,7 @@
//! Abstract-ish representation of paths for VFS.
use std::fmt;
use paths::{AbsPath, AbsPathBuf};
use paths::{AbsPath, AbsPathBuf, RelPath};
/// Path in [`Vfs`].
///
@ -84,6 +84,14 @@ impl VfsPath {
}
}
pub fn strip_prefix(&self, other: &VfsPath) -> Option<&RelPath> {
match (&self.0, &other.0) {
(VfsPathRepr::PathBuf(lhs), VfsPathRepr::PathBuf(rhs)) => lhs.strip_prefix(rhs),
(VfsPathRepr::VirtualPath(lhs), VfsPathRepr::VirtualPath(rhs)) => lhs.strip_prefix(rhs),
(VfsPathRepr::PathBuf(_) | VfsPathRepr::VirtualPath(_), _) => None,
}
}
/// Returns the `VfsPath` without its final component, if there is one.
///
/// Returns [`None`] if the path is a root or prefix.
@ -320,6 +328,13 @@ impl VirtualPath {
self.0.starts_with(&other.0)
}
fn strip_prefix(&self, base: &VirtualPath) -> Option<&RelPath> {
<_ as AsRef<std::path::Path>>::as_ref(&self.0)
.strip_prefix(&base.0)
.ok()
.map(RelPath::new_unchecked)
}
/// Remove the last component of `self`.
///
/// This will find the last `'/'` in `self`, and remove everything after it,