Remove limit from import_map::Query

This commit is contained in:
Lukas Wirth 2024-01-04 18:12:25 +01:00
parent 9b3052104c
commit c3a29e5528
3 changed files with 7 additions and 44 deletions

View file

@ -295,7 +295,6 @@ pub struct Query {
search_mode: SearchMode, search_mode: SearchMode,
assoc_mode: AssocSearchMode, assoc_mode: AssocSearchMode,
case_sensitive: bool, case_sensitive: bool,
limit: usize,
} }
impl Query { impl Query {
@ -307,7 +306,6 @@ impl Query {
search_mode: SearchMode::Exact, search_mode: SearchMode::Exact,
assoc_mode: AssocSearchMode::Include, assoc_mode: AssocSearchMode::Include,
case_sensitive: false, case_sensitive: false,
limit: usize::MAX,
} }
} }
@ -329,11 +327,6 @@ impl Query {
Self { assoc_mode, ..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. /// Respect casing of the query string when matching.
pub fn case_sensitive(self) -> Self { pub fn case_sensitive(self) -> Self {
Self { case_sensitive: true, ..self } Self { case_sensitive: true, ..self }
@ -442,10 +435,6 @@ fn search_maps(
} }
}); });
res.extend(iter.map(TupleExt::head)); 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)
"#]],
);
}
} }

View file

@ -339,6 +339,7 @@ fn path_applicable_imports(
let mod_path = mod_path(item)?; let mod_path = mod_path(item)?;
Some(LocatedImport::new(mod_path, item, item)) Some(LocatedImport::new(mod_path, item, item))
}) })
.take(DEFAULT_QUERY_SEARCH_LIMIT.inner())
.collect() .collect()
} }
Some(qualifier) => items_locator::items_with_name( Some(qualifier) => items_locator::items_with_name(
@ -349,6 +350,7 @@ fn path_applicable_imports(
Some(DEFAULT_QUERY_SEARCH_LIMIT.inner()), Some(DEFAULT_QUERY_SEARCH_LIMIT.inner()),
) )
.filter_map(|item| import_for_item(sema.db, mod_path, &qualifier, item)) .filter_map(|item| import_for_item(sema.db, mod_path, &qualifier, item))
.take(DEFAULT_QUERY_SEARCH_LIMIT.inner())
.collect(), .collect(),
} }
} }
@ -517,6 +519,7 @@ fn trait_applicable_items(
Some(assoc_item_trait.into()) Some(assoc_item_trait.into())
} }
}) })
.take(DEFAULT_QUERY_SEARCH_LIMIT.inner())
.collect(); .collect();
let mut located_imports = FxHashSet::default(); let mut located_imports = FxHashSet::default();

View file

@ -19,7 +19,7 @@ pub fn items_with_name<'a>(
krate: Crate, krate: Crate,
name: NameToImport, name: NameToImport,
assoc_item_search: AssocSearchMode, assoc_item_search: AssocSearchMode,
limit: Option<usize>, local_limit: Option<usize>,
) -> impl Iterator<Item = ItemInNs> + 'a { ) -> impl Iterator<Item = ItemInNs> + 'a {
let _p = profile::span("items_with_name").detail(|| { let _p = profile::span("items_with_name").detail(|| {
format!( format!(
@ -27,12 +27,12 @@ pub fn items_with_name<'a>(
name.text(), name.text(),
assoc_item_search, assoc_item_search,
krate.display_name(sema.db).map(|name| name.to_string()), krate.display_name(sema.db).map(|name| name.to_string()),
limit, local_limit,
) )
}); });
let prefix = matches!(name, NameToImport::Prefix(..)); 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::Prefix(exact_name, case_sensitive)
| NameToImport::Exact(exact_name, case_sensitive) => { | NameToImport::Exact(exact_name, case_sensitive) => {
let mut local_query = symbol_index::Query::new(exact_name.clone()); 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 { if let Some(limit) = local_limit {
external_query = external_query.limit(limit);
local_query.limit(limit); local_query.limit(limit);
} }