diff options
Diffstat (limited to 'crates/ra_db')
-rw-r--r-- | crates/ra_db/src/mock.rs | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/crates/ra_db/src/mock.rs b/crates/ra_db/src/mock.rs index 2840f9655..2f7551597 100644 --- a/crates/ra_db/src/mock.rs +++ b/crates/ra_db/src/mock.rs | |||
@@ -5,7 +5,7 @@ use relative_path::{RelativePath, RelativePathBuf}; | |||
5 | 5 | ||
6 | use crate::{FileId, FileResolver, SourceRoot, FileResolverImp}; | 6 | use crate::{FileId, FileResolver, SourceRoot, FileResolverImp}; |
7 | 7 | ||
8 | #[derive(Default, Debug)] | 8 | #[derive(Default, Debug, Clone)] |
9 | pub struct FileMap(Vec<(FileId, RelativePathBuf)>); | 9 | pub struct FileMap(Vec<(FileId, RelativePathBuf)>); |
10 | 10 | ||
11 | impl FileMap { | 11 | impl FileMap { |
@@ -28,6 +28,11 @@ impl FileMap { | |||
28 | self.iter().map(|(id, _)| id).collect() | 28 | self.iter().map(|(id, _)| id).collect() |
29 | } | 29 | } |
30 | 30 | ||
31 | pub fn file_id(&self, path: &str) -> FileId { | ||
32 | assert!(path.starts_with('/')); | ||
33 | self.iter().find(|(_, p)| p == &path[1..]).unwrap().0 | ||
34 | } | ||
35 | |||
31 | fn iter<'a>(&'a self) -> impl Iterator<Item = (FileId, &'a RelativePath)> + 'a { | 36 | fn iter<'a>(&'a self) -> impl Iterator<Item = (FileId, &'a RelativePath)> + 'a { |
32 | self.0 | 37 | self.0 |
33 | .iter() | 38 | .iter() |