From 18aac1df45ca39d01d80a56e3afab7299de160f8 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 19 Dec 2018 12:26:51 +0300 Subject: [PATCH] kill file resolver --- crates/ra_db/src/file_resolver.rs | 76 ------------------------------- crates/ra_db/src/lib.rs | 2 - crates/ra_db/src/mock.rs | 17 +------ 3 files changed, 1 insertion(+), 94 deletions(-) delete mode 100644 crates/ra_db/src/file_resolver.rs diff --git a/crates/ra_db/src/file_resolver.rs b/crates/ra_db/src/file_resolver.rs deleted file mode 100644 index f849ac7521..0000000000 --- a/crates/ra_db/src/file_resolver.rs +++ /dev/null @@ -1,76 +0,0 @@ -use std::{ - sync::Arc, - hash::{Hash, Hasher}, - fmt, -}; - -use relative_path::RelativePath; - -use crate::input::FileId; - -pub trait FileResolver: fmt::Debug + Send + Sync + 'static { - fn file_stem(&self, file_id: FileId) -> String; - fn resolve(&self, file_id: FileId, path: &RelativePath) -> Option; - fn debug_path(&self, _1file_id: FileId) -> Option { - None - } -} - -#[derive(Clone, Debug)] -pub struct FileResolverImp { - inner: Arc, -} - -impl PartialEq for FileResolverImp { - fn eq(&self, other: &FileResolverImp) -> bool { - self.inner() == other.inner() - } -} - -impl Eq for FileResolverImp {} - -impl Hash for FileResolverImp { - fn hash(&self, hasher: &mut H) { - self.inner().hash(hasher); - } -} - -impl FileResolverImp { - pub fn new(inner: Arc) -> FileResolverImp { - FileResolverImp { inner } - } - pub fn file_stem(&self, file_id: FileId) -> String { - self.inner.file_stem(file_id) - } - pub fn resolve(&self, file_id: FileId, path: &RelativePath) -> Option { - self.inner.resolve(file_id, path) - } - pub fn debug_path(&self, file_id: FileId) -> Option { - self.inner.debug_path(file_id) - } - fn inner(&self) -> *const FileResolver { - &*self.inner - } -} - -impl Default for FileResolverImp { - fn default() -> FileResolverImp { - #[derive(Debug)] - struct DummyResolver; - impl FileResolver for DummyResolver { - fn file_stem(&self, _file_: FileId) -> String { - panic!("file resolver not set") - } - fn resolve( - &self, - _file_id: FileId, - _path: &::relative_path::RelativePath, - ) -> Option { - panic!("file resolver not set") - } - } - FileResolverImp { - inner: Arc::new(DummyResolver), - } - } -} diff --git a/crates/ra_db/src/lib.rs b/crates/ra_db/src/lib.rs index d1db281e65..eeb305b1b3 100644 --- a/crates/ra_db/src/lib.rs +++ b/crates/ra_db/src/lib.rs @@ -1,6 +1,5 @@ //! ra_db defines basic database traits. Concrete DB is defined by ra_analysis. mod syntax_ptr; -mod file_resolver; mod input; mod loc2id; pub mod mock; @@ -24,7 +23,6 @@ impl std::error::Error for Canceled {} pub use crate::{ syntax_ptr::LocalSyntaxPtr, - file_resolver::{FileResolver, FileResolverImp}, input::{ FilesDatabase, FileId, CrateId, SourceRoot, SourceRootId, CrateGraph, WORKSPACE, FileTextQuery, FileSourceRootQuery, SourceRootQuery, LibrariesQuery, CrateGraphQuery, diff --git a/crates/ra_db/src/mock.rs b/crates/ra_db/src/mock.rs index efe987bdd2..5e185062b4 100644 --- a/crates/ra_db/src/mock.rs +++ b/crates/ra_db/src/mock.rs @@ -1,7 +1,7 @@ use rustc_hash::FxHashSet; use relative_path::{RelativePath, RelativePathBuf}; -use crate::{FileId, FileResolver}; +use crate::{FileId}; #[derive(Default, Debug, Clone)] pub struct FileMap(Vec<(FileId, RelativePathBuf)>); @@ -27,19 +27,4 @@ impl FileMap { .iter() .map(|(id, path)| (*id, path.as_relative_path())) } - - fn path(&self, id: FileId) -> &RelativePath { - self.iter().find(|&(it, _)| it == id).unwrap().1 - } -} - -impl FileResolver for FileMap { - fn file_stem(&self, id: FileId) -> String { - self.path(id).file_stem().unwrap().to_string() - } - fn resolve(&self, id: FileId, rel: &RelativePath) -> Option { - let path = self.path(id).join(rel).normalize(); - let id = self.iter().find(|&(_, p)| path == p)?.0; - Some(id) - } }