aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_completion
diff options
context:
space:
mode:
authorKirill Bulatov <[email protected]>2021-03-20 13:02:52 +0000
committerKirill Bulatov <[email protected]>2021-03-20 20:33:54 +0000
commita631108d2dd0596b079b59efa37b1af00d7555db (patch)
tree14492ac7c646f7ce786a4b62896a18dc6d718342 /crates/ide_completion
parent81961dc035106dcfd29b894aae339261a0ba037b (diff)
Do not query item search by name eagerly
Diffstat (limited to 'crates/ide_completion')
-rw-r--r--crates/ide_completion/src/lib.rs28
1 files changed, 18 insertions, 10 deletions
diff --git a/crates/ide_completion/src/lib.rs b/crates/ide_completion/src/lib.rs
index d9ea7b7ea..c91c98871 100644
--- a/crates/ide_completion/src/lib.rs
+++ b/crates/ide_completion/src/lib.rs
@@ -14,7 +14,10 @@ mod completions;
14use completions::flyimport::position_for_import; 14use completions::flyimport::position_for_import;
15use ide_db::{ 15use ide_db::{
16 base_db::FilePosition, 16 base_db::FilePosition,
17 helpers::{import_assets::LocatedImport, insert_use::ImportScope}, 17 helpers::{
18 import_assets::{LocatedImport, NameToImport},
19 insert_use::ImportScope,
20 },
18 items_locator, RootDatabase, 21 items_locator, RootDatabase,
19}; 22};
20use text_edit::TextEdit; 23use text_edit::TextEdit;
@@ -149,15 +152,20 @@ pub fn resolve_completion_edits(
149 let current_module = ctx.sema.scope(position_for_import).module()?; 152 let current_module = ctx.sema.scope(position_for_import).module()?;
150 let current_crate = current_module.krate(); 153 let current_crate = current_module.krate();
151 154
152 let (import_path, item_to_import) = 155 let (import_path, item_to_import) = items_locator::locate_for_name(
153 items_locator::with_exact_name(&ctx.sema, current_crate, imported_name) 156 &ctx.sema,
154 .into_iter() 157 current_crate,
155 .filter_map(|candidate| { 158 NameToImport::Exact(imported_name),
156 current_module 159 items_locator::AssocItemSearch::Include,
157 .find_use_path_prefixed(db, candidate, config.insert_use.prefix_kind) 160 None,
158 .zip(Some(candidate)) 161 )
159 }) 162 .into_iter()
160 .find(|(mod_path, _)| mod_path.to_string() == full_import_path)?; 163 .filter_map(|candidate| {
164 current_module
165 .find_use_path_prefixed(db, candidate, config.insert_use.prefix_kind)
166 .zip(Some(candidate))
167 })
168 .find(|(mod_path, _)| mod_path.to_string() == full_import_path)?;
161 let import = 169 let import =
162 LocatedImport::new(import_path.clone(), item_to_import, item_to_import, Some(import_path)); 170 LocatedImport::new(import_path.clone(), item_to_import, item_to_import, Some(import_path));
163 171