From 22269c67b87448a18d7772eaba0a10e595bcf50d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 9 Jul 2020 09:56:15 +0200 Subject: Cleanup --- crates/ra_ide/src/hover.rs | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/hover.rs b/crates/ra_ide/src/hover.rs index c32665142..79ed30388 100644 --- a/crates/ra_ide/src/hover.rs +++ b/crates/ra_ide/src/hover.rs @@ -1,5 +1,3 @@ -use std::iter::once; - use hir::{ Adt, AsAssocItem, AssocItemContainer, Documentation, FieldSource, HasSource, HirDisplay, Module, ModuleDef, ModuleSource, Semantics, @@ -211,7 +209,11 @@ fn goto_type_action(db: &RootDatabase, def: Definition) -> Option { .into_iter() .filter_map(|it| { Some(HoverGotoTypeData { - mod_path: mod_path(db, &it)?, + mod_path: render_path( + db, + it.module(db)?, + it.name(db).map(|name| name.to_string()), + ), nav: it.try_to_nav(db)?, }) }) @@ -253,27 +255,19 @@ fn definition_owner_name(db: &RootDatabase, def: &Definition) -> Option .map(|name| name.to_string()) } -fn determine_mod_path(db: &RootDatabase, module: Module, name: Option) -> String { - once(db.crate_graph()[module.krate().into()].display_name.as_ref().map(ToString::to_string)) - .chain( - module - .path_to_root(db) - .into_iter() - .rev() - .map(|it| it.name(db).map(|name| name.to_string())), - ) - .chain(once(name)) - .flatten() - .join("::") -} - -// returns None only for ModuleDef::BuiltinType -fn mod_path(db: &RootDatabase, item: &ModuleDef) -> Option { - Some(determine_mod_path(db, item.module(db)?, item.name(db).map(|name| name.to_string()))) +fn render_path(db: &RootDatabase, module: Module, item_name: Option) -> String { + let crate_name = + db.crate_graph()[module.krate().into()].display_name.as_ref().map(ToString::to_string); + let module_path = module + .path_to_root(db) + .into_iter() + .rev() + .flat_map(|it| it.name(db).map(|name| name.to_string())); + crate_name.into_iter().chain(module_path).chain(item_name).join("::") } fn definition_mod_path(db: &RootDatabase, def: &Definition) -> Option { - def.module(db).map(|module| determine_mod_path(db, module, definition_owner_name(db, def))) + def.module(db).map(|module| render_path(db, module, definition_owner_name(db, def))) } fn hover_for_definition(db: &RootDatabase, def: Definition) -> Option { -- cgit v1.2.3