mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 04:53:34 +00:00
Simplify
This commit is contained in:
parent
733ef3163c
commit
d8571e076c
2 changed files with 5 additions and 9 deletions
|
@ -337,15 +337,11 @@ impl Env {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ExternSource {
|
impl ExternSource {
|
||||||
pub fn extern_path(&self, path: impl AsRef<Path>) -> Option<(ExternSourceId, RelativePathBuf)> {
|
pub fn extern_path(&self, path: &Path) -> Option<(ExternSourceId, RelativePathBuf)> {
|
||||||
let path = path.as_ref();
|
|
||||||
self.extern_paths.iter().find_map(|(root_path, id)| {
|
self.extern_paths.iter().find_map(|(root_path, id)| {
|
||||||
if let Ok(rel_path) = path.strip_prefix(root_path) {
|
let rel_path = path.strip_prefix(root_path).ok()?;
|
||||||
let rel_path = RelativePathBuf::from_path(rel_path).ok()?;
|
let rel_path = RelativePathBuf::from_path(rel_path).ok()?;
|
||||||
Some((*id, rel_path))
|
Some((*id, rel_path))
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -158,7 +158,7 @@ impl<T: SourceDatabaseExt> FileLoader for FileLoaderDelegate<&'_ T> {
|
||||||
if std::path::Path::new(path).is_absolute() {
|
if std::path::Path::new(path).is_absolute() {
|
||||||
let krate = *self.relevant_crates(anchor).get(0)?;
|
let krate = *self.relevant_crates(anchor).get(0)?;
|
||||||
let (extern_source_id, relative_file) =
|
let (extern_source_id, relative_file) =
|
||||||
self.0.crate_graph()[krate].extern_source.extern_path(path)?;
|
self.0.crate_graph()[krate].extern_source.extern_path(path.as_ref())?;
|
||||||
|
|
||||||
let source_root = self.0.source_root(SourceRootId(extern_source_id.0));
|
let source_root = self.0.source_root(SourceRootId(extern_source_id.0));
|
||||||
source_root.file_by_relative_path(&relative_file)
|
source_root.file_by_relative_path(&relative_file)
|
||||||
|
|
Loading…
Reference in a new issue