532: fix go to parent module r=matklad a=matklad



Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2019-01-13 19:01:06 +00:00
commit fa6e4b7978
2 changed files with 21 additions and 2 deletions

View file

@ -89,6 +89,25 @@ impl NavigationTarget {
Ok(res)
}
pub(crate) fn from_module_to_decl(
db: &RootDatabase,
module: hir::Module,
) -> Cancelable<NavigationTarget> {
let name = module
.name(db)?
.map(|it| it.to_string().into())
.unwrap_or_default();
if let Some((file_id, source)) = module.declaration_source(db)? {
return Ok(NavigationTarget::from_syntax(
file_id,
name,
None,
source.syntax(),
));
}
NavigationTarget::from_module(db, module)
}
// TODO once Def::Item is gone, this should be able to always return a NavigationTarget
pub(crate) fn from_def(db: &RootDatabase, def: Def) -> Cancelable<Option<NavigationTarget>> {
let res = match def {

View file

@ -12,7 +12,7 @@ pub(crate) fn parent_module(
None => return Ok(Vec::new()),
Some(it) => it,
};
let nav = NavigationTarget::from_module(db, module)?;
let nav = NavigationTarget::from_module_to_decl(db, module)?;
Ok(vec![nav])
}
@ -31,7 +31,7 @@ mod tests {
",
);
let nav = analysis.parent_module(pos).unwrap().pop().unwrap();
nav.assert_match("foo SOURCE_FILE FileId(2) [0; 10)");
nav.assert_match("foo MODULE FileId(1) [0; 8)");
}
#[test]