57: less hacky paths r=matklad a=matklad



Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2018-09-05 15:28:21 +00:00
commit 8f30179f82

View File

@ -7,7 +7,7 @@ use std::{
path::{Path},
};
use relative_path::RelativePath;
use relative_path::{RelativePath, RelativePathBuf};
use libanalysis::{AnalysisHost, FileId, FileResolver, JobHandle, CrateGraph, CrateId};
use test_utils::assert_eq_dbg;
@ -28,18 +28,15 @@ impl FileResolver for FileMap {
self.path(id).file_stem().unwrap().to_str().unwrap().to_string()
}
fn resolve(&self, id: FileId, rel: &RelativePath) -> Option<FileId> {
let path = {
if rel.starts_with("..") {
rel.strip_prefix("..").unwrap()
.to_path(&self.path(id).parent().unwrap())
} else {
rel.to_path(self.path(id))
}
};
let path = &path.to_str().unwrap()[1..];
let path = RelativePath::new(&path[0..]).normalize();
let path = rel.to_path(self.path(id));
let path = path.strip_prefix("/").unwrap();
let path = RelativePathBuf::from_path(&path).unwrap().normalize();
let &(id, _) = self.0.iter()
.find(|it| path == RelativePath::new(&it.1[0..]).normalize())?;
.find(|it| {
let p = Path::new(it.1).strip_prefix("/").unwrap();
let p = RelativePathBuf::from_path(p).unwrap();
path == p
})?;
Some(FileId(id))
}
}