From 2906d188c2442d67b3d3b1bf532553e5adc9020a Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Mon, 30 Dec 2019 23:08:40 +0100 Subject: Cleanup --- crates/ra_hir_def/src/find_path.rs | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/crates/ra_hir_def/src/find_path.rs b/crates/ra_hir_def/src/find_path.rs index 3df2f2c09..166728153 100644 --- a/crates/ra_hir_def/src/find_path.rs +++ b/crates/ra_hir_def/src/find_path.rs @@ -9,17 +9,24 @@ use crate::{ }; use hir_expand::name::Name; +const MAX_PATH_LEN: usize = 15; + pub fn find_path(db: &impl DefDatabase, item: ItemInNs, from: ModuleId) -> Option { - find_path_inner(db, item, from, 15) + find_path_inner(db, item, from, MAX_PATH_LEN) } -fn find_path_inner(db: &impl DefDatabase, item: ItemInNs, from: ModuleId, max_len: usize) -> Option { - // Base cases: - +fn find_path_inner( + db: &impl DefDatabase, + item: ItemInNs, + from: ModuleId, + max_len: usize, +) -> Option { if max_len == 0 { return None; } + // Base cases: + // - if the item is already in scope, return the name under which it is let def_map = db.crate_def_map(from.krate); let from_scope: &crate::item_scope::ItemScope = &def_map.modules[from.local_id].scope; @@ -86,8 +93,12 @@ fn find_path_inner(db: &impl DefDatabase, item: ItemInNs, from: ModuleId, max_le let mut best_path = None; let mut best_path_len = max_len; for (module_id, name) in importable_locations { - let mut path = match find_path_inner(db, ItemInNs::Types(ModuleDefId::ModuleId(module_id)), from, best_path_len - 1) - { + let mut path = match find_path_inner( + db, + ItemInNs::Types(ModuleDefId::ModuleId(module_id)), + from, + best_path_len - 1, + ) { None => continue, Some(path) => path, }; @@ -101,13 +112,14 @@ fn find_path_inner(db: &impl DefDatabase, item: ItemInNs, from: ModuleId, max_le } fn path_len(path: &ModPath) -> usize { - path.segments.len() + match path.kind { - PathKind::Plain => 0, - PathKind::Super(i) => i as usize, - PathKind::Crate => 1, - PathKind::Abs => 0, - PathKind::DollarCrate(_) => 1, - } + path.segments.len() + + match path.kind { + PathKind::Plain => 0, + PathKind::Super(i) => i as usize, + PathKind::Crate => 1, + PathKind::Abs => 0, + PathKind::DollarCrate(_) => 1, + } } fn find_importable_locations( -- cgit v1.2.3