diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-12-20 09:16:07 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-12-20 09:16:07 +0000 |
commit | 9a16cf2bf646a4a881f3f5acbf5582dacc4337bf (patch) | |
tree | ff90eb390a8f5af47b6d0c6ec4c49b4431b82d1c /crates/ra_db/src/mock.rs | |
parent | dbb62b5baa36783bbca06f09c77794fce3ceff0c (diff) | |
parent | a084412f0698d5f54d586f707930e141c88b0673 (diff) |
Merge #292
292: Vfs r=matklad a=matklad
closes #243
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_db/src/mock.rs')
-rw-r--r-- | crates/ra_db/src/mock.rs | 28 |
1 files changed, 1 insertions, 27 deletions
diff --git a/crates/ra_db/src/mock.rs b/crates/ra_db/src/mock.rs index 2f7551597..5e185062b 100644 --- a/crates/ra_db/src/mock.rs +++ b/crates/ra_db/src/mock.rs | |||
@@ -1,9 +1,7 @@ | |||
1 | use std::sync::Arc; | ||
2 | |||
3 | use rustc_hash::FxHashSet; | 1 | use rustc_hash::FxHashSet; |
4 | use relative_path::{RelativePath, RelativePathBuf}; | 2 | use relative_path::{RelativePath, RelativePathBuf}; |
5 | 3 | ||
6 | use crate::{FileId, FileResolver, SourceRoot, FileResolverImp}; | 4 | use crate::{FileId}; |
7 | 5 | ||
8 | #[derive(Default, Debug, Clone)] | 6 | #[derive(Default, Debug, Clone)] |
9 | pub struct FileMap(Vec<(FileId, RelativePathBuf)>); | 7 | pub struct FileMap(Vec<(FileId, RelativePathBuf)>); |
@@ -15,15 +13,6 @@ impl FileMap { | |||
15 | file_id | 13 | file_id |
16 | } | 14 | } |
17 | 15 | ||
18 | pub fn into_source_root(self) -> SourceRoot { | ||
19 | let files = self.files(); | ||
20 | let file_resolver = FileResolverImp::new(Arc::new(self)); | ||
21 | SourceRoot { | ||
22 | file_resolver, | ||
23 | files, | ||
24 | } | ||
25 | } | ||
26 | |||
27 | pub fn files(&self) -> FxHashSet<FileId> { | 16 | pub fn files(&self) -> FxHashSet<FileId> { |
28 | self.iter().map(|(id, _)| id).collect() | 17 | self.iter().map(|(id, _)| id).collect() |
29 | } | 18 | } |
@@ -38,19 +27,4 @@ impl FileMap { | |||
38 | .iter() | 27 | .iter() |
39 | .map(|(id, path)| (*id, path.as_relative_path())) | 28 | .map(|(id, path)| (*id, path.as_relative_path())) |
40 | } | 29 | } |
41 | |||
42 | fn path(&self, id: FileId) -> &RelativePath { | ||
43 | self.iter().find(|&(it, _)| it == id).unwrap().1 | ||
44 | } | ||
45 | } | ||
46 | |||
47 | impl FileResolver for FileMap { | ||
48 | fn file_stem(&self, id: FileId) -> String { | ||
49 | self.path(id).file_stem().unwrap().to_string() | ||
50 | } | ||
51 | fn resolve(&self, id: FileId, rel: &RelativePath) -> Option<FileId> { | ||
52 | let path = self.path(id).join(rel).normalize(); | ||
53 | let id = self.iter().find(|&(_, p)| path == p)?.0; | ||
54 | Some(id) | ||
55 | } | ||
56 | } | 30 | } |