diff options
Diffstat (limited to 'crates/ra_db/src')
-rw-r--r-- | crates/ra_db/src/file_resolver.rs | 76 | ||||
-rw-r--r-- | crates/ra_db/src/lib.rs | 2 | ||||
-rw-r--r-- | crates/ra_db/src/mock.rs | 17 |
3 files changed, 1 insertions, 94 deletions
diff --git a/crates/ra_db/src/file_resolver.rs b/crates/ra_db/src/file_resolver.rs deleted file mode 100644 index f849ac752..000000000 --- a/crates/ra_db/src/file_resolver.rs +++ /dev/null | |||
@@ -1,76 +0,0 @@ | |||
1 | use std::{ | ||
2 | sync::Arc, | ||
3 | hash::{Hash, Hasher}, | ||
4 | fmt, | ||
5 | }; | ||
6 | |||
7 | use relative_path::RelativePath; | ||
8 | |||
9 | use crate::input::FileId; | ||
10 | |||
11 | pub trait FileResolver: fmt::Debug + Send + Sync + 'static { | ||
12 | fn file_stem(&self, file_id: FileId) -> String; | ||
13 | fn resolve(&self, file_id: FileId, path: &RelativePath) -> Option<FileId>; | ||
14 | fn debug_path(&self, _1file_id: FileId) -> Option<std::path::PathBuf> { | ||
15 | None | ||
16 | } | ||
17 | } | ||
18 | |||
19 | #[derive(Clone, Debug)] | ||
20 | pub struct FileResolverImp { | ||
21 | inner: Arc<FileResolver>, | ||
22 | } | ||
23 | |||
24 | impl PartialEq for FileResolverImp { | ||
25 | fn eq(&self, other: &FileResolverImp) -> bool { | ||
26 | self.inner() == other.inner() | ||
27 | } | ||
28 | } | ||
29 | |||
30 | impl Eq for FileResolverImp {} | ||
31 | |||
32 | impl Hash for FileResolverImp { | ||
33 | fn hash<H: Hasher>(&self, hasher: &mut H) { | ||
34 | self.inner().hash(hasher); | ||
35 | } | ||
36 | } | ||
37 | |||
38 | impl FileResolverImp { | ||
39 | pub fn new(inner: Arc<FileResolver>) -> FileResolverImp { | ||
40 | FileResolverImp { inner } | ||
41 | } | ||
42 | pub fn file_stem(&self, file_id: FileId) -> String { | ||
43 | self.inner.file_stem(file_id) | ||
44 | } | ||
45 | pub fn resolve(&self, file_id: FileId, path: &RelativePath) -> Option<FileId> { | ||
46 | self.inner.resolve(file_id, path) | ||
47 | } | ||
48 | pub fn debug_path(&self, file_id: FileId) -> Option<std::path::PathBuf> { | ||
49 | self.inner.debug_path(file_id) | ||
50 | } | ||
51 | fn inner(&self) -> *const FileResolver { | ||
52 | &*self.inner | ||
53 | } | ||
54 | } | ||
55 | |||
56 | impl Default for FileResolverImp { | ||
57 | fn default() -> FileResolverImp { | ||
58 | #[derive(Debug)] | ||
59 | struct DummyResolver; | ||
60 | impl FileResolver for DummyResolver { | ||
61 | fn file_stem(&self, _file_: FileId) -> String { | ||
62 | panic!("file resolver not set") | ||
63 | } | ||
64 | fn resolve( | ||
65 | &self, | ||
66 | _file_id: FileId, | ||
67 | _path: &::relative_path::RelativePath, | ||
68 | ) -> Option<FileId> { | ||
69 | panic!("file resolver not set") | ||
70 | } | ||
71 | } | ||
72 | FileResolverImp { | ||
73 | inner: Arc::new(DummyResolver), | ||
74 | } | ||
75 | } | ||
76 | } | ||
diff --git a/crates/ra_db/src/lib.rs b/crates/ra_db/src/lib.rs index d1db281e6..eeb305b1b 100644 --- a/crates/ra_db/src/lib.rs +++ b/crates/ra_db/src/lib.rs | |||
@@ -1,6 +1,5 @@ | |||
1 | //! ra_db defines basic database traits. Concrete DB is defined by ra_analysis. | 1 | //! ra_db defines basic database traits. Concrete DB is defined by ra_analysis. |
2 | mod syntax_ptr; | 2 | mod syntax_ptr; |
3 | mod file_resolver; | ||
4 | mod input; | 3 | mod input; |
5 | mod loc2id; | 4 | mod loc2id; |
6 | pub mod mock; | 5 | pub mod mock; |
@@ -24,7 +23,6 @@ impl std::error::Error for Canceled {} | |||
24 | 23 | ||
25 | pub use crate::{ | 24 | pub use crate::{ |
26 | syntax_ptr::LocalSyntaxPtr, | 25 | syntax_ptr::LocalSyntaxPtr, |
27 | file_resolver::{FileResolver, FileResolverImp}, | ||
28 | input::{ | 26 | input::{ |
29 | FilesDatabase, FileId, CrateId, SourceRoot, SourceRootId, CrateGraph, WORKSPACE, | 27 | FilesDatabase, FileId, CrateId, SourceRoot, SourceRootId, CrateGraph, WORKSPACE, |
30 | FileTextQuery, FileSourceRootQuery, SourceRootQuery, LibrariesQuery, CrateGraphQuery, | 28 | FileTextQuery, FileSourceRootQuery, SourceRootQuery, LibrariesQuery, CrateGraphQuery, |
diff --git a/crates/ra_db/src/mock.rs b/crates/ra_db/src/mock.rs index efe987bdd..5e185062b 100644 --- a/crates/ra_db/src/mock.rs +++ b/crates/ra_db/src/mock.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | use rustc_hash::FxHashSet; | 1 | use rustc_hash::FxHashSet; |
2 | use relative_path::{RelativePath, RelativePathBuf}; | 2 | use relative_path::{RelativePath, RelativePathBuf}; |
3 | 3 | ||
4 | use crate::{FileId, FileResolver}; | 4 | use crate::{FileId}; |
5 | 5 | ||
6 | #[derive(Default, Debug, Clone)] | 6 | #[derive(Default, Debug, Clone)] |
7 | pub struct FileMap(Vec<(FileId, RelativePathBuf)>); | 7 | pub struct FileMap(Vec<(FileId, RelativePathBuf)>); |
@@ -27,19 +27,4 @@ impl FileMap { | |||
27 | .iter() | 27 | .iter() |
28 | .map(|(id, path)| (*id, path.as_relative_path())) | 28 | .map(|(id, path)| (*id, path.as_relative_path())) |
29 | } | 29 | } |
30 | |||
31 | fn path(&self, id: FileId) -> &RelativePath { | ||
32 | self.iter().find(|&(it, _)| it == id).unwrap().1 | ||
33 | } | ||
34 | } | ||
35 | |||
36 | impl FileResolver for FileMap { | ||
37 | fn file_stem(&self, id: FileId) -> String { | ||
38 | self.path(id).file_stem().unwrap().to_string() | ||
39 | } | ||
40 | fn resolve(&self, id: FileId, rel: &RelativePath) -> Option<FileId> { | ||
41 | let path = self.path(id).join(rel).normalize(); | ||
42 | let id = self.iter().find(|&(_, p)| path == p)?.0; | ||
43 | Some(id) | ||
44 | } | ||
45 | } | 30 | } |