diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-12-31 14:15:34 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-12-31 14:15:34 +0000 |
commit | 2a65020442142b68b32c0a97672faeeba5ff399e (patch) | |
tree | 32791da6860ea906017a8d30157baedc08bee484 /crates/ra_analysis/src/imp.rs | |
parent | 700b334a28b73133a25416319475eafe3ec11f90 (diff) | |
parent | 05daa86634b41aa3f311a1ac0b02bf7fed7ed569 (diff) |
Merge #165
165: Make modules with tests runnable r=farodin91 a=farodin91
Fixes #154
I having problems to traverse the path to module. The main problem is that module_tree only supports `FileId` and not `Module` in files. Any idea?
I need to clean up the code a bit later.
Co-authored-by: Jan Jansen <[email protected]>
Diffstat (limited to 'crates/ra_analysis/src/imp.rs')
-rw-r--r-- | crates/ra_analysis/src/imp.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index 5ed374c79..5669aa94d 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs | |||
@@ -181,6 +181,28 @@ impl AnalysisImpl { | |||
181 | }; | 181 | }; |
182 | Ok(query.search(&buf)) | 182 | Ok(query.search(&buf)) |
183 | } | 183 | } |
184 | |||
185 | pub(crate) fn module_path(&self, position: FilePosition) -> Cancelable<Option<String>> { | ||
186 | let descr = match source_binder::module_from_position(&*self.db, position)? { | ||
187 | None => return Ok(None), | ||
188 | Some(it) => it, | ||
189 | }; | ||
190 | let name = match descr.name() { | ||
191 | None => return Ok(None), | ||
192 | Some(it) => it.to_string(), | ||
193 | }; | ||
194 | |||
195 | let modules = descr.path_to_root(); | ||
196 | |||
197 | let path = modules | ||
198 | .iter() | ||
199 | .filter_map(|s| s.name()) | ||
200 | .skip(1) // name is already part of the string. | ||
201 | .fold(name, |path, it| format!("{}::{}", it, path)); | ||
202 | |||
203 | Ok(Some(path.to_string())) | ||
204 | } | ||
205 | |||
184 | /// This returns `Vec` because a module may be included from several places. We | 206 | /// This returns `Vec` because a module may be included from several places. We |
185 | /// don't handle this case yet though, so the Vec has length at most one. | 207 | /// don't handle this case yet though, so the Vec has length at most one. |
186 | pub fn parent_module(&self, position: FilePosition) -> Cancelable<Vec<(FileId, FileSymbol)>> { | 208 | pub fn parent_module(&self, position: FilePosition) -> Cancelable<Vec<(FileId, FileSymbol)>> { |