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,
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)
"#]],
);
}
}

View File

@ -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();

View File

@ -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);
}