diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-09-06 12:23:31 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2019-09-06 12:23:31 +0100 |
commit | 2015e8b4d15c8be6c8fd735b0c08ccbbe24fb934 (patch) | |
tree | 5f5adc8ffd4c29d104e646057f636def67ac2549 /crates/ra_hir/src | |
parent | 3bdb456d17660f3460bbf2c38315568b2f76aaa5 (diff) | |
parent | 9ae455ea52bf0bc60476fdb3d50d05f5873040c1 (diff) |
Merge #1778
1778: make source_root API more abstract r=matklad a=matklad
bors r+
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r-- | crates/ra_hir/src/mock.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir/src/nameres/mod_resolution.rs | 14 |
2 files changed, 9 insertions, 7 deletions
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 { | |||
157 | self.set_file_text(file_id, text); | 157 | self.set_file_text(file_id, text); |
158 | self.set_file_relative_path(file_id, rel_path.clone()); | 158 | self.set_file_relative_path(file_id, rel_path.clone()); |
159 | self.set_file_source_root(file_id, source_root_id); | 159 | self.set_file_source_root(file_id, source_root_id); |
160 | source_root.files.insert(rel_path, file_id); | 160 | source_root.insert_file(rel_path, file_id); |
161 | 161 | ||
162 | if is_crate_root { | 162 | if is_crate_root { |
163 | let mut crate_graph = CrateGraph::default(); | 163 | 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 { | |||
120 | impl OutOfLineMode { | 120 | impl OutOfLineMode { |
121 | pub fn resolve(&self, source_root: Arc<SourceRoot>) -> Result<FileId, RelativePathBuf> { | 121 | pub fn resolve(&self, source_root: Arc<SourceRoot>) -> Result<FileId, RelativePathBuf> { |
122 | match self { | 122 | match self { |
123 | OutOfLineMode::RootOrModRs { file, directory } => match source_root.files.get(file) { | 123 | OutOfLineMode::RootOrModRs { file, directory } => { |
124 | None => resolve_simple_path(source_root, directory).map_err(|_| file.clone()), | 124 | match source_root.file_by_relative_path(file) { |
125 | file_id => resolve_find_result(file_id, file), | 125 | None => resolve_simple_path(source_root, directory).map_err(|_| file.clone()), |
126 | }, | 126 | file_id => resolve_find_result(file_id, file), |
127 | } | ||
128 | } | ||
127 | OutOfLineMode::FileInDirectory(path) => resolve_simple_path(source_root, path), | 129 | OutOfLineMode::FileInDirectory(path) => resolve_simple_path(source_root, path), |
128 | OutOfLineMode::WithAttributePath(path) => resolve_simple_path(source_root, path), | 130 | OutOfLineMode::WithAttributePath(path) => resolve_simple_path(source_root, path), |
129 | } | 131 | } |
@@ -168,11 +170,11 @@ fn resolve_simple_path( | |||
168 | source_root: Arc<SourceRoot>, | 170 | source_root: Arc<SourceRoot>, |
169 | path: &RelativePathBuf, | 171 | path: &RelativePathBuf, |
170 | ) -> Result<FileId, RelativePathBuf> { | 172 | ) -> Result<FileId, RelativePathBuf> { |
171 | resolve_find_result(source_root.files.get(path), path) | 173 | resolve_find_result(source_root.file_by_relative_path(path), path) |
172 | } | 174 | } |
173 | 175 | ||
174 | fn resolve_find_result( | 176 | fn resolve_find_result( |
175 | file_id: Option<&FileId>, | 177 | file_id: Option<FileId>, |
176 | path: &RelativePathBuf, | 178 | path: &RelativePathBuf, |
177 | ) -> Result<FileId, RelativePathBuf> { | 179 | ) -> Result<FileId, RelativePathBuf> { |
178 | match file_id { | 180 | match file_id { |