From 68626e4ef5acfea05812b68f41efa2bcd5bea448 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Sun, 17 Jan 2021 00:53:15 +0200 Subject: Draft the working completion --- crates/ide_db/src/helpers/import_assets.rs | 30 ++++++++++++++++++++---------- crates/ide_db/src/imports_locator.rs | 16 ++++++++++------ 2 files changed, 30 insertions(+), 16 deletions(-) (limited to 'crates/ide_db') diff --git a/crates/ide_db/src/helpers/import_assets.rs b/crates/ide_db/src/helpers/import_assets.rs index e284220c1..a080b6ca7 100644 --- a/crates/ide_db/src/helpers/import_assets.rs +++ b/crates/ide_db/src/helpers/import_assets.rs @@ -5,7 +5,7 @@ use rustc_hash::FxHashSet; use syntax::{ast, AstNode}; use crate::{ - imports_locator::{self, AssocItemSearch}, + imports_locator::{self, AssocItemSearch, DEFAULT_QUERY_SEARCH_LIMIT}, RootDatabase, }; @@ -173,6 +173,7 @@ impl ImportAssets { let current_crate = self.module_with_candidate.krate(); let filter = |candidate: Either| { + // TODO kb process all traits at once instead? trait_candidates.clear(); match &self.import_candidate { ImportCandidate::TraitAssocItem(trait_candidate) => { @@ -191,6 +192,11 @@ impl ImportAssets { None, |_, assoc| { if canidate_assoc_item == assoc { + if let AssocItem::Function(f) = assoc { + if f.self_param(db).is_some() { + return None; + } + } Some(assoc_to_module_def(assoc)) } else { None @@ -238,17 +244,21 @@ impl ImportAssets { // see https://github.com/rust-analyzer/rust-analyzer/pull/7293#issuecomment-761585032 // and https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/Blanket.20trait.20impls.20lookup // for the details - NameToImport::Fuzzy(fuzzy_name) => imports_locator::find_similar_imports( - sema, - current_crate, - fuzzy_name.clone(), - match self.import_candidate { + NameToImport::Fuzzy(fuzzy_name) => { + let (assoc_item_search, limit) = match self.import_candidate { ImportCandidate::TraitAssocItem(_) | ImportCandidate::TraitMethod(_) => { - AssocItemSearch::AssocItemsOnly + (AssocItemSearch::AssocItemsOnly, None) } - _ => AssocItemSearch::Exclude, - }, - ), + _ => (AssocItemSearch::Exclude, Some(DEFAULT_QUERY_SEARCH_LIMIT)), + }; + imports_locator::find_similar_imports( + sema, + current_crate, + fuzzy_name.clone(), + assoc_item_search, + limit, + ) + } }; let mut res = unfiltered_imports diff --git a/crates/ide_db/src/imports_locator.rs b/crates/ide_db/src/imports_locator.rs index d69e65960..502e8281a 100644 --- a/crates/ide_db/src/imports_locator.rs +++ b/crates/ide_db/src/imports_locator.rs @@ -15,7 +15,7 @@ use crate::{ use either::Either; use rustc_hash::FxHashSet; -const QUERY_SEARCH_LIMIT: usize = 40; +pub(crate) const DEFAULT_QUERY_SEARCH_LIMIT: usize = 40; pub fn find_exact_imports<'a>( sema: &Semantics<'a, RootDatabase>, @@ -29,11 +29,11 @@ pub fn find_exact_imports<'a>( { let mut local_query = symbol_index::Query::new(name_to_import.clone()); local_query.exact(); - local_query.limit(QUERY_SEARCH_LIMIT); + local_query.limit(DEFAULT_QUERY_SEARCH_LIMIT); local_query }, import_map::Query::new(name_to_import) - .limit(QUERY_SEARCH_LIMIT) + .limit(DEFAULT_QUERY_SEARCH_LIMIT) .name_only() .search_mode(import_map::SearchMode::Equals) .case_sensitive(), @@ -51,13 +51,13 @@ pub fn find_similar_imports<'a>( krate: Crate, fuzzy_search_string: String, assoc_item_search: AssocItemSearch, + limit: Option, ) -> Box> + 'a> { let _p = profile::span("find_similar_imports"); let mut external_query = import_map::Query::new(fuzzy_search_string.clone()) .search_mode(import_map::SearchMode::Fuzzy) - .name_only() - .limit(QUERY_SEARCH_LIMIT); + .name_only(); match assoc_item_search { AssocItemSearch::Include => {} @@ -70,7 +70,11 @@ pub fn find_similar_imports<'a>( } let mut local_query = symbol_index::Query::new(fuzzy_search_string); - local_query.limit(QUERY_SEARCH_LIMIT); + + if let Some(limit) = limit { + external_query = external_query.limit(limit); + local_query.limit(limit); + } let db = sema.db; Box::new(find_imports(sema, krate, local_query, external_query).filter( -- cgit v1.2.3