From 9ae455ea52bf0bc60476fdb3d50d05f5873040c1 Mon Sep 17 00:00:00 2001
From: Aleksey Kladov <aleksey.kladov@gmail.com>
Date: Thu, 5 Sep 2019 22:36:04 +0300
Subject: make source_root API more abstract

---
 crates/ra_hir/src/mock.rs                   |  2 +-
 crates/ra_hir/src/nameres/mod_resolution.rs | 14 ++++++++------
 2 files changed, 9 insertions(+), 7 deletions(-)

(limited to 'crates/ra_hir/src')

diff --git a/crates/ra_hir/src/mock.rs b/crates/ra_hir/src/mock.rs
index 77a44a275..972f0ece5 100644
--- a/crates/ra_hir/src/mock.rs
+++ b/crates/ra_hir/src/mock.rs
@@ -157,7 +157,7 @@ impl MockDatabase {
         self.set_file_text(file_id, text);
         self.set_file_relative_path(file_id, rel_path.clone());
         self.set_file_source_root(file_id, source_root_id);
-        source_root.files.insert(rel_path, file_id);
+        source_root.insert_file(rel_path, file_id);
 
         if is_crate_root {
             let mut crate_graph = CrateGraph::default();
diff --git a/crates/ra_hir/src/nameres/mod_resolution.rs b/crates/ra_hir/src/nameres/mod_resolution.rs
index 94c9946ff..de81fd422 100644
--- a/crates/ra_hir/src/nameres/mod_resolution.rs
+++ b/crates/ra_hir/src/nameres/mod_resolution.rs
@@ -120,10 +120,12 @@ enum OutOfLineMode {
 impl OutOfLineMode {
     pub fn resolve(&self, source_root: Arc<SourceRoot>) -> Result<FileId, RelativePathBuf> {
         match self {
-            OutOfLineMode::RootOrModRs { file, directory } => match source_root.files.get(file) {
-                None => resolve_simple_path(source_root, directory).map_err(|_| file.clone()),
-                file_id => resolve_find_result(file_id, file),
-            },
+            OutOfLineMode::RootOrModRs { file, directory } => {
+                match source_root.file_by_relative_path(file) {
+                    None => resolve_simple_path(source_root, directory).map_err(|_| file.clone()),
+                    file_id => resolve_find_result(file_id, file),
+                }
+            }
             OutOfLineMode::FileInDirectory(path) => resolve_simple_path(source_root, path),
             OutOfLineMode::WithAttributePath(path) => resolve_simple_path(source_root, path),
         }
@@ -168,11 +170,11 @@ fn resolve_simple_path(
     source_root: Arc<SourceRoot>,
     path: &RelativePathBuf,
 ) -> Result<FileId, RelativePathBuf> {
-    resolve_find_result(source_root.files.get(path), path)
+    resolve_find_result(source_root.file_by_relative_path(path), path)
 }
 
 fn resolve_find_result(
-    file_id: Option<&FileId>,
+    file_id: Option<FileId>,
     path: &RelativePathBuf,
 ) -> Result<FileId, RelativePathBuf> {
     match file_id {
-- 
cgit v1.2.3