From 05daa86634b41aa3f311a1ac0b02bf7fed7ed569 Mon Sep 17 00:00:00 2001 From: Jan Jansen Date: Thu, 27 Dec 2018 21:45:16 +0100 Subject: Make modules with tests runnable Fixes #154 --- crates/ra_analysis/src/imp.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'crates/ra_analysis/src/imp.rs') 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 { }; Ok(query.search(&buf)) } + + pub(crate) fn module_path(&self, position: FilePosition) -> Cancelable> { + let descr = match source_binder::module_from_position(&*self.db, position)? { + None => return Ok(None), + Some(it) => it, + }; + let name = match descr.name() { + None => return Ok(None), + Some(it) => it.to_string(), + }; + + let modules = descr.path_to_root(); + + let path = modules + .iter() + .filter_map(|s| s.name()) + .skip(1) // name is already part of the string. + .fold(name, |path, it| format!("{}::{}", it, path)); + + Ok(Some(path.to_string())) + } + /// This returns `Vec` because a module may be included from several places. We /// don't handle this case yet though, so the Vec has length at most one. pub fn parent_module(&self, position: FilePosition) -> Cancelable> { -- cgit v1.2.3