diff --git a/crates/hir-def/src/import_map.rs b/crates/hir-def/src/import_map.rs index c2434717e72..7ac229d8d1b 100644 --- a/crates/hir-def/src/import_map.rs +++ b/crates/hir-def/src/import_map.rs @@ -295,7 +295,6 @@ pub struct Query { search_mode: SearchMode, assoc_mode: AssocSearchMode, case_sensitive: bool, - limit: usize, } impl Query { @@ -307,7 +306,6 @@ pub fn new(query: String) -> Self { search_mode: SearchMode::Exact, assoc_mode: AssocSearchMode::Include, case_sensitive: false, - limit: usize::MAX, } } @@ -329,11 +327,6 @@ pub fn assoc_search_mode(self, assoc_mode: AssocSearchMode) -> Self { Self { assoc_mode, ..self } } - /// Limits the returned number of items to `limit`. - pub fn limit(self, limit: usize) -> Self { - Self { limit, ..self } - } - /// Respect casing of the query string when matching. pub fn case_sensitive(self) -> Self { Self { case_sensitive: true, ..self } @@ -442,10 +435,6 @@ fn search_maps( } }); res.extend(iter.map(TupleExt::head)); - - if res.len() >= query.limit { - return res; - } } } @@ -1015,32 +1004,4 @@ fn search_casing() { "#]], ); } - - #[test] - fn search_limit() { - check_search( - r#" - //- /main.rs crate:main deps:dep - //- /dep.rs crate:dep - pub mod fmt { - pub trait Display { - fn fmt(); - } - } - #[macro_export] - macro_rules! Fmt { - () => {}; - } - pub struct Fmt; - - pub fn format() {} - pub fn no() {} - "#, - "main", - Query::new("".to_string()).fuzzy().limit(1), - expect![[r#" - dep::fmt::Display (t) - "#]], - ); - } } diff --git a/crates/ide-db/src/imports/import_assets.rs b/crates/ide-db/src/imports/import_assets.rs index a4f0a6df781..42e054b2c49 100644 --- a/crates/ide-db/src/imports/import_assets.rs +++ b/crates/ide-db/src/imports/import_assets.rs @@ -339,6 +339,7 @@ fn path_applicable_imports( let mod_path = mod_path(item)?; Some(LocatedImport::new(mod_path, item, item)) }) + .take(DEFAULT_QUERY_SEARCH_LIMIT.inner()) .collect() } Some(qualifier) => items_locator::items_with_name( @@ -349,6 +350,7 @@ fn path_applicable_imports( Some(DEFAULT_QUERY_SEARCH_LIMIT.inner()), ) .filter_map(|item| import_for_item(sema.db, mod_path, &qualifier, item)) + .take(DEFAULT_QUERY_SEARCH_LIMIT.inner()) .collect(), } } @@ -517,6 +519,7 @@ fn trait_applicable_items( Some(assoc_item_trait.into()) } }) + .take(DEFAULT_QUERY_SEARCH_LIMIT.inner()) .collect(); let mut located_imports = FxHashSet::default(); diff --git a/crates/ide-db/src/items_locator.rs b/crates/ide-db/src/items_locator.rs index 4a5d234f73d..11e7e7f66f6 100644 --- a/crates/ide-db/src/items_locator.rs +++ b/crates/ide-db/src/items_locator.rs @@ -19,7 +19,7 @@ pub fn items_with_name<'a>( krate: Crate, name: NameToImport, assoc_item_search: AssocSearchMode, - limit: Option, + local_limit: Option, ) -> impl Iterator + 'a { let _p = profile::span("items_with_name").detail(|| { format!( @@ -27,12 +27,12 @@ pub fn items_with_name<'a>( name.text(), assoc_item_search, krate.display_name(sema.db).map(|name| name.to_string()), - limit, + local_limit, ) }); let prefix = matches!(name, NameToImport::Prefix(..)); - let (mut local_query, mut external_query) = match name { + let (mut local_query, external_query) = match name { NameToImport::Prefix(exact_name, case_sensitive) | NameToImport::Exact(exact_name, case_sensitive) => { let mut local_query = symbol_index::Query::new(exact_name.clone()); @@ -69,8 +69,7 @@ pub fn items_with_name<'a>( } }; - if let Some(limit) = limit { - external_query = external_query.limit(limit); + if let Some(limit) = local_limit { local_query.limit(limit); }