diff options
author | Jan Jansen <[email protected]> | 2018-12-27 20:45:16 +0000 |
---|---|---|
committer | Jan Jansen <[email protected]> | 2018-12-31 14:00:04 +0000 |
commit | 05daa86634b41aa3f311a1ac0b02bf7fed7ed569 (patch) | |
tree | b703cfe2fc7788631703141d9f4be63b0f5d7fe5 /crates/ra_analysis/src/imp.rs | |
parent | 690826871202c77326836a895a38532ebd83c54b (diff) |
Make modules with tests runnable
Fixes #154
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)>> { |