mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 04:19:13 +00:00
feat: Make unlinked_file diagnostic quickfixes work for inline modules
This commit is contained in:
parent
bb4e272d8a
commit
1ce3e820dc
3 changed files with 202 additions and 42 deletions
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue