diff options
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 | } |