Unnamed repository; edit this file 'description' to name the repository.
Remove limit from import_map::Query
Lukas Wirth 2024-01-05
parent 9b30521 · commit c3a29e5
-rw-r--r--crates/hir-def/src/import_map.rs39
-rw-r--r--crates/ide-db/src/imports/import_assets.rs3
-rw-r--r--crates/ide-db/src/items_locator.rs9
3 files changed, 7 insertions, 44 deletions
diff --git a/crates/hir-def/src/import_map.rs b/crates/hir-def/src/import_map.rs
index c2434717e7..7ac229d8d1 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 @@ impl Query {
search_mode: SearchMode::Exact,
assoc_mode: AssocSearchMode::Include,
case_sensitive: false,
- limit: usize::MAX,
}
}
@@ -329,11 +327,6 @@ impl Query {
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 @@ pub mod fmt {
"#]],
);
}
-
- #[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 a4f0a6df78..42e054b2c4 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 4a5d234f73..11e7e7f66f 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<usize>,
+ local_limit: Option<usize>,
) -> impl Iterator<Item = ItemInNs> + '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);
}