aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_db/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-12-19 09:26:51 +0000
committerAleksey Kladov <[email protected]>2018-12-20 09:15:38 +0000
commit18aac1df45ca39d01d80a56e3afab7299de160f8 (patch)
tree7920ec1d929a27589187b185b5ea2ec28014703c /crates/ra_db/src
parent85290bc1342560d5560f0b2151cff1c0c6dac155 (diff)
kill file resolver
Diffstat (limited to 'crates/ra_db/src')
-rw-r--r--crates/ra_db/src/file_resolver.rs76
-rw-r--r--crates/ra_db/src/lib.rs2
-rw-r--r--crates/ra_db/src/mock.rs17
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 @@
1use std::{
2 sync::Arc,
3 hash::{Hash, Hasher},
4 fmt,
5};
6
7use relative_path::RelativePath;
8
9use crate::input::FileId;
10
11pub 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)]
20pub struct FileResolverImp {
21 inner: Arc<FileResolver>,
22}
23
24impl PartialEq for FileResolverImp {
25 fn eq(&self, other: &FileResolverImp) -> bool {
26 self.inner() == other.inner()
27 }
28}
29
30impl Eq for FileResolverImp {}
31
32impl Hash for FileResolverImp {
33 fn hash<H: Hasher>(&self, hasher: &mut H) {
34 self.inner().hash(hasher);
35 }
36}
37
38impl 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
56impl 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.
2mod syntax_ptr; 2mod syntax_ptr;
3mod file_resolver;
4mod input; 3mod input;
5mod loc2id; 4mod loc2id;
6pub mod mock; 5pub mod mock;
@@ -24,7 +23,6 @@ impl std::error::Error for Canceled {}
24 23
25pub use crate::{ 24pub 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 @@
1use rustc_hash::FxHashSet; 1use rustc_hash::FxHashSet;
2use relative_path::{RelativePath, RelativePathBuf}; 2use relative_path::{RelativePath, RelativePathBuf};
3 3
4use crate::{FileId, FileResolver}; 4use crate::{FileId};
5 5
6#[derive(Default, Debug, Clone)] 6#[derive(Default, Debug, Clone)]
7pub struct FileMap(Vec<(FileId, RelativePathBuf)>); 7pub 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
36impl 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}