From 5c9ebbeaa415a5ff811b3be5058d8cb374e9baac Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 19 May 2020 16:43:26 +0200 Subject: Cleanup imports --- crates/ra_hir_def/src/find_path.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'crates/ra_hir_def/src') diff --git a/crates/ra_hir_def/src/find_path.rs b/crates/ra_hir_def/src/find_path.rs index 1ca20fabd..c7976535c 100644 --- a/crates/ra_hir_def/src/find_path.rs +++ b/crates/ra_hir_def/src/find_path.rs @@ -1,5 +1,10 @@ //! An algorithm to find a path to refer to a certain item. +use std::sync::Arc; + +use hir_expand::name::{known, AsName, Name}; +use test_utils::tested_by; + use crate::{ db::DefDatabase, item_scope::ItemInNs, @@ -7,9 +12,6 @@ use crate::{ visibility::Visibility, CrateId, ModuleDefId, ModuleId, }; -use hir_expand::name::{known, AsName, Name}; -use std::sync::Arc; -use test_utils::tested_by; const MAX_PATH_LEN: usize = 15; -- cgit v1.2.3 From 908da9ac1b04a0eb27552ec9ca68a5f88c4f42c7 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 19 May 2020 16:45:57 +0200 Subject: Simplify --- crates/ra_hir_def/src/find_path.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'crates/ra_hir_def/src') diff --git a/crates/ra_hir_def/src/find_path.rs b/crates/ra_hir_def/src/find_path.rs index c7976535c..aee7e7511 100644 --- a/crates/ra_hir_def/src/find_path.rs +++ b/crates/ra_hir_def/src/find_path.rs @@ -17,18 +17,14 @@ const MAX_PATH_LEN: usize = 15; impl ModPath { fn starts_with_std(&self) -> bool { - self.segments.first().filter(|&first_segment| first_segment == &known::std).is_some() + self.segments.first() == Some(&known::std) } // When std library is present, paths starting with `std::` // should be preferred over paths starting with `core::` and `alloc::` fn can_start_with_std(&self) -> bool { - self.segments - .first() - .filter(|&first_segment| { - first_segment == &known::alloc || first_segment == &known::core - }) - .is_some() + let first_segment = self.segments.first(); + first_segment == Some(&known::alloc) || first_segment == Some(&known::core) } fn len(&self) -> usize { -- cgit v1.2.3 From 01bd1e1296d31dbb102d198e9fd82e1e36f1193b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 19 May 2020 16:46:33 +0200 Subject: Move public API to the top --- crates/ra_hir_def/src/find_path.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'crates/ra_hir_def/src') diff --git a/crates/ra_hir_def/src/find_path.rs b/crates/ra_hir_def/src/find_path.rs index aee7e7511..15bc04c1a 100644 --- a/crates/ra_hir_def/src/find_path.rs +++ b/crates/ra_hir_def/src/find_path.rs @@ -13,6 +13,15 @@ use crate::{ CrateId, ModuleDefId, ModuleId, }; +// FIXME: handle local items + +/// Find a path that can be used to refer to a certain item. This can depend on +/// *from where* you're referring to the item, hence the `from` parameter. +pub fn find_path(db: &dyn DefDatabase, item: ItemInNs, from: ModuleId) -> Option { + let _p = ra_prof::profile("find_path"); + find_path_inner(db, item, from, MAX_PATH_LEN) +} + const MAX_PATH_LEN: usize = 15; impl ModPath { @@ -39,15 +48,6 @@ impl ModPath { } } -// FIXME: handle local items - -/// Find a path that can be used to refer to a certain item. This can depend on -/// *from where* you're referring to the item, hence the `from` parameter. -pub fn find_path(db: &dyn DefDatabase, item: ItemInNs, from: ModuleId) -> Option { - let _p = ra_prof::profile("find_path"); - find_path_inner(db, item, from, MAX_PATH_LEN) -} - fn find_path_inner( db: &dyn DefDatabase, item: ItemInNs, -- cgit v1.2.3 From dce31efdde9ca0311ed60f04b97049d42ed49ba8 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 19 May 2020 16:54:45 +0200 Subject: Cleanup query fn naming --- crates/ra_hir_def/src/db.rs | 2 +- crates/ra_hir_def/src/find_path.rs | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'crates/ra_hir_def/src') diff --git a/crates/ra_hir_def/src/db.rs b/crates/ra_hir_def/src/db.rs index 498a4c917..2f71511ba 100644 --- a/crates/ra_hir_def/src/db.rs +++ b/crates/ra_hir_def/src/db.rs @@ -112,7 +112,7 @@ pub trait DefDatabase: InternDatabase + AstDatabase + Upcast { #[salsa::invoke(Documentation::documentation_query)] fn documentation(&self, def: AttrDefId) -> Option; - #[salsa::invoke(find_path::importable_locations_in_crate)] + #[salsa::invoke(find_path::importable_locations_of_query)] fn importable_locations_of( &self, item: ItemInNs, diff --git a/crates/ra_hir_def/src/find_path.rs b/crates/ra_hir_def/src/find_path.rs index 15bc04c1a..2eb12ec8f 100644 --- a/crates/ra_hir_def/src/find_path.rs +++ b/crates/ra_hir_def/src/find_path.rs @@ -3,6 +3,7 @@ use std::sync::Arc; use hir_expand::name::{known, AsName, Name}; +use ra_prof::profile; use test_utils::tested_by; use crate::{ @@ -18,7 +19,7 @@ use crate::{ /// Find a path that can be used to refer to a certain item. This can depend on /// *from where* you're referring to the item, hence the `from` parameter. pub fn find_path(db: &dyn DefDatabase, item: ItemInNs, from: ModuleId) -> Option { - let _p = ra_prof::profile("find_path"); + let _p = profile("find_path"); find_path_inner(db, item, from, MAX_PATH_LEN) } @@ -213,11 +214,12 @@ fn find_importable_locations( /// /// Note that the crate doesn't need to be the one in which the item is defined; /// it might be re-exported in other crates. -pub(crate) fn importable_locations_in_crate( +pub(crate) fn importable_locations_of_query( db: &dyn DefDatabase, item: ItemInNs, krate: CrateId, ) -> Arc<[(ModuleId, Name, Visibility)]> { + let _p = profile("importable_locations_of_query"); let def_map = db.crate_def_map(krate); let mut result = Vec::new(); for (local_id, data) in def_map.modules.iter() { -- cgit v1.2.3