Skip to content

Commit c3a29e5

Browse files
committed
Remove limit from import_map::Query
1 parent 9b30521 commit c3a29e5

File tree

3 files changed

+7
-44
lines changed

3 files changed

+7
-44
lines changed

crates/hir-def/src/import_map.rs

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,6 @@ pub struct Query {
295295
search_mode: SearchMode,
296296
assoc_mode: AssocSearchMode,
297297
case_sensitive: bool,
298-
limit: usize,
299298
}
300299

301300
impl Query {
@@ -307,7 +306,6 @@ impl Query {
307306
search_mode: SearchMode::Exact,
308307
assoc_mode: AssocSearchMode::Include,
309308
case_sensitive: false,
310-
limit: usize::MAX,
311309
}
312310
}
313311

@@ -329,11 +327,6 @@ impl Query {
329327
Self { assoc_mode, ..self }
330328
}
331329

332-
/// Limits the returned number of items to `limit`.
333-
pub fn limit(self, limit: usize) -> Self {
334-
Self { limit, ..self }
335-
}
336-
337330
/// Respect casing of the query string when matching.
338331
pub fn case_sensitive(self) -> Self {
339332
Self { case_sensitive: true, ..self }
@@ -442,10 +435,6 @@ fn search_maps(
442435
}
443436
});
444437
res.extend(iter.map(TupleExt::head));
445-
446-
if res.len() >= query.limit {
447-
return res;
448-
}
449438
}
450439
}
451440

@@ -1015,32 +1004,4 @@ pub mod fmt {
10151004
"#]],
10161005
);
10171006
}
1018-
1019-
#[test]
1020-
fn search_limit() {
1021-
check_search(
1022-
r#"
1023-
//- /main.rs crate:main deps:dep
1024-
//- /dep.rs crate:dep
1025-
pub mod fmt {
1026-
pub trait Display {
1027-
fn fmt();
1028-
}
1029-
}
1030-
#[macro_export]
1031-
macro_rules! Fmt {
1032-
() => {};
1033-
}
1034-
pub struct Fmt;
1035-
1036-
pub fn format() {}
1037-
pub fn no() {}
1038-
"#,
1039-
"main",
1040-
Query::new("".to_string()).fuzzy().limit(1),
1041-
expect![[r#"
1042-
dep::fmt::Display (t)
1043-
"#]],
1044-
);
1045-
}
10461007
}

crates/ide-db/src/imports/import_assets.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ fn path_applicable_imports(
339339
let mod_path = mod_path(item)?;
340340
Some(LocatedImport::new(mod_path, item, item))
341341
})
342+
.take(DEFAULT_QUERY_SEARCH_LIMIT.inner())
342343
.collect()
343344
}
344345
Some(qualifier) => items_locator::items_with_name(
@@ -349,6 +350,7 @@ fn path_applicable_imports(
349350
Some(DEFAULT_QUERY_SEARCH_LIMIT.inner()),
350351
)
351352
.filter_map(|item| import_for_item(sema.db, mod_path, &qualifier, item))
353+
.take(DEFAULT_QUERY_SEARCH_LIMIT.inner())
352354
.collect(),
353355
}
354356
}
@@ -517,6 +519,7 @@ fn trait_applicable_items(
517519
Some(assoc_item_trait.into())
518520
}
519521
})
522+
.take(DEFAULT_QUERY_SEARCH_LIMIT.inner())
520523
.collect();
521524

522525
let mut located_imports = FxHashSet::default();

crates/ide-db/src/items_locator.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,20 @@ pub fn items_with_name<'a>(
1919
krate: Crate,
2020
name: NameToImport,
2121
assoc_item_search: AssocSearchMode,
22-
limit: Option<usize>,
22+
local_limit: Option<usize>,
2323
) -> impl Iterator<Item = ItemInNs> + 'a {
2424
let _p = profile::span("items_with_name").detail(|| {
2525
format!(
2626
"Name: {}, crate: {:?}, assoc items: {:?}, limit: {:?}",
2727
name.text(),
2828
assoc_item_search,
2929
krate.display_name(sema.db).map(|name| name.to_string()),
30-
limit,
30+
local_limit,
3131
)
3232
});
3333

3434
let prefix = matches!(name, NameToImport::Prefix(..));
35-
let (mut local_query, mut external_query) = match name {
35+
let (mut local_query, external_query) = match name {
3636
NameToImport::Prefix(exact_name, case_sensitive)
3737
| NameToImport::Exact(exact_name, case_sensitive) => {
3838
let mut local_query = symbol_index::Query::new(exact_name.clone());
@@ -69,8 +69,7 @@ pub fn items_with_name<'a>(
6969
}
7070
};
7171

72-
if let Some(limit) = limit {
73-
external_query = external_query.limit(limit);
72+
if let Some(limit) = local_limit {
7473
local_query.limit(limit);
7574
}
7675

0 commit comments

Comments
 (0)