This commit is contained in:
Aleksey Kladov 2019-01-25 20:55:38 +03:00
parent daaba4be17
commit d0cf4306bd
2 changed files with 11 additions and 38 deletions

View File

@ -97,9 +97,7 @@ pub(crate) fn reference_definition(
{
let resolved = module.resolve_path(db, &path);
if let Some(def_id) = resolved.take_types().or(resolved.take_values()) {
if let Some(target) = NavigationTarget::from_def(db, def_id) {
return Exact(target);
}
return Exact(NavigationTarget::from_def(db, def_id));
}
}
}

View File

@ -112,62 +112,37 @@ pub(crate) fn from_field(db: &RootDatabase, field: hir::StructField) -> Navigati
}
}
// TODO once Def::Item is gone, this should be able to always return a NavigationTarget
pub(crate) fn from_def(
db: &RootDatabase,
module_def: hir::ModuleDef,
) -> Option<NavigationTarget> {
pub(crate) fn from_def(db: &RootDatabase, module_def: hir::ModuleDef) -> NavigationTarget {
match module_def {
hir::ModuleDef::Module(module) => Some(NavigationTarget::from_module(db, module)),
hir::ModuleDef::Function(func) => Some(NavigationTarget::from_function(db, func)),
hir::ModuleDef::Module(module) => NavigationTarget::from_module(db, module),
hir::ModuleDef::Function(func) => NavigationTarget::from_function(db, func),
hir::ModuleDef::Struct(s) => {
let (file_id, node) = s.source(db);
Some(NavigationTarget::from_named(
file_id.original_file(db),
&*node,
))
NavigationTarget::from_named(file_id.original_file(db), &*node)
}
hir::ModuleDef::Const(s) => {
let (file_id, node) = s.source(db);
Some(NavigationTarget::from_named(
file_id.original_file(db),
&*node,
))
NavigationTarget::from_named(file_id.original_file(db), &*node)
}
hir::ModuleDef::Static(s) => {
let (file_id, node) = s.source(db);
Some(NavigationTarget::from_named(
file_id.original_file(db),
&*node,
))
NavigationTarget::from_named(file_id.original_file(db), &*node)
}
hir::ModuleDef::Enum(e) => {
let (file_id, node) = e.source(db);
Some(NavigationTarget::from_named(
file_id.original_file(db),
&*node,
))
NavigationTarget::from_named(file_id.original_file(db), &*node)
}
hir::ModuleDef::EnumVariant(var) => {
let (file_id, node) = var.source(db);
Some(NavigationTarget::from_named(
file_id.original_file(db),
&*node,
))
NavigationTarget::from_named(file_id.original_file(db), &*node)
}
hir::ModuleDef::Trait(e) => {
let (file_id, node) = e.source(db);
Some(NavigationTarget::from_named(
file_id.original_file(db),
&*node,
))
NavigationTarget::from_named(file_id.original_file(db), &*node)
}
hir::ModuleDef::Type(e) => {
let (file_id, node) = e.source(db);
Some(NavigationTarget::from_named(
file_id.original_file(db),
&*node,
))
NavigationTarget::from_named(file_id.original_file(db), &*node)
}
}
}