diff options
author | Aleksey Kladov <[email protected]> | 2020-07-09 08:56:15 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-07-09 08:56:15 +0100 |
commit | 22269c67b87448a18d7772eaba0a10e595bcf50d (patch) | |
tree | 7961ec887fdc2ff25ee5a046ff9159e2addf1d6c /crates/ra_ide | |
parent | 3ef9ef34c6489e9a63790d2355e8ce279a511612 (diff) |
Cleanup
Diffstat (limited to 'crates/ra_ide')
-rw-r--r-- | crates/ra_ide/src/hover.rs | 36 |
1 files changed, 15 insertions, 21 deletions
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 @@ | |||
1 | use std::iter::once; | ||
2 | |||
3 | use hir::{ | 1 | use hir::{ |
4 | Adt, AsAssocItem, AssocItemContainer, Documentation, FieldSource, HasSource, HirDisplay, | 2 | Adt, AsAssocItem, AssocItemContainer, Documentation, FieldSource, HasSource, HirDisplay, |
5 | Module, ModuleDef, ModuleSource, Semantics, | 3 | Module, ModuleDef, ModuleSource, Semantics, |
@@ -211,7 +209,11 @@ fn goto_type_action(db: &RootDatabase, def: Definition) -> Option<HoverAction> { | |||
211 | .into_iter() | 209 | .into_iter() |
212 | .filter_map(|it| { | 210 | .filter_map(|it| { |
213 | Some(HoverGotoTypeData { | 211 | Some(HoverGotoTypeData { |
214 | mod_path: mod_path(db, &it)?, | 212 | mod_path: render_path( |
213 | db, | ||
214 | it.module(db)?, | ||
215 | it.name(db).map(|name| name.to_string()), | ||
216 | ), | ||
215 | nav: it.try_to_nav(db)?, | 217 | nav: it.try_to_nav(db)?, |
216 | }) | 218 | }) |
217 | }) | 219 | }) |
@@ -253,27 +255,19 @@ fn definition_owner_name(db: &RootDatabase, def: &Definition) -> Option<String> | |||
253 | .map(|name| name.to_string()) | 255 | .map(|name| name.to_string()) |
254 | } | 256 | } |
255 | 257 | ||
256 | fn determine_mod_path(db: &RootDatabase, module: Module, name: Option<String>) -> String { | 258 | fn render_path(db: &RootDatabase, module: Module, item_name: Option<String>) -> String { |
257 | once(db.crate_graph()[module.krate().into()].display_name.as_ref().map(ToString::to_string)) | 259 | let crate_name = |
258 | .chain( | 260 | db.crate_graph()[module.krate().into()].display_name.as_ref().map(ToString::to_string); |
259 | module | 261 | let module_path = module |
260 | .path_to_root(db) | 262 | .path_to_root(db) |
261 | .into_iter() | 263 | .into_iter() |
262 | .rev() | 264 | .rev() |
263 | .map(|it| it.name(db).map(|name| name.to_string())), | 265 | .flat_map(|it| it.name(db).map(|name| name.to_string())); |
264 | ) | 266 | crate_name.into_iter().chain(module_path).chain(item_name).join("::") |
265 | .chain(once(name)) | ||
266 | .flatten() | ||
267 | .join("::") | ||
268 | } | ||
269 | |||
270 | // returns None only for ModuleDef::BuiltinType | ||
271 | fn mod_path(db: &RootDatabase, item: &ModuleDef) -> Option<String> { | ||
272 | Some(determine_mod_path(db, item.module(db)?, item.name(db).map(|name| name.to_string()))) | ||
273 | } | 267 | } |
274 | 268 | ||
275 | fn definition_mod_path(db: &RootDatabase, def: &Definition) -> Option<String> { | 269 | fn definition_mod_path(db: &RootDatabase, def: &Definition) -> Option<String> { |
276 | def.module(db).map(|module| determine_mod_path(db, module, definition_owner_name(db, def))) | 270 | def.module(db).map(|module| render_path(db, module, definition_owner_name(db, def))) |
277 | } | 271 | } |
278 | 272 | ||
279 | fn hover_for_definition(db: &RootDatabase, def: Definition) -> Option<String> { | 273 | fn hover_for_definition(db: &RootDatabase, def: Definition) -> Option<String> { |