Skip to content

Commit 2666349

Browse files
committed
Remove limit from symbol_index::Query
1 parent 0af780e commit 2666349

File tree

8 files changed

+10
-29
lines changed

8 files changed

+10
-29
lines changed

crates/ide-assists/src/handlers/replace_derive_with_manual_impl.rs

-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ pub(crate) fn replace_derive_with_manual_impl(
7474
current_crate,
7575
NameToImport::exact_case_sensitive(path.segments().last()?.to_string()),
7676
items_locator::AssocSearchMode::Exclude,
77-
Some(items_locator::DEFAULT_QUERY_SEARCH_LIMIT.inner()),
7877
)
7978
.filter_map(|item| match item.as_module_def()? {
8079
ModuleDef::Trait(trait_) => Some(trait_),

crates/ide-completion/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,6 @@ pub fn resolve_completion_edits(
256256
current_crate,
257257
NameToImport::exact_case_sensitive(imported_name),
258258
items_locator::AssocSearchMode::Include,
259-
Some(items_locator::DEFAULT_QUERY_SEARCH_LIMIT.inner()),
260259
);
261260
let import = items_with_name
262261
.filter_map(|candidate| {

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

-3
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,6 @@ fn path_applicable_imports(
333333
//
334334
// see also an ignored test under FIXME comment in the qualify_path.rs module
335335
AssocSearchMode::Exclude,
336-
Some(DEFAULT_QUERY_SEARCH_LIMIT.inner()),
337336
)
338337
.filter_map(|item| {
339338
let mod_path = mod_path(item)?;
@@ -347,7 +346,6 @@ fn path_applicable_imports(
347346
current_crate,
348347
path_candidate.name.clone(),
349348
AssocSearchMode::Include,
350-
Some(DEFAULT_QUERY_SEARCH_LIMIT.inner()),
351349
)
352350
.filter_map(|item| import_for_item(sema.db, mod_path, &qualifier, item))
353351
.take(DEFAULT_QUERY_SEARCH_LIMIT.inner())
@@ -507,7 +505,6 @@ fn trait_applicable_items(
507505
current_crate,
508506
trait_candidate.assoc_item_name.clone(),
509507
AssocSearchMode::AssocItemsOnly,
510-
Some(DEFAULT_QUERY_SEARCH_LIMIT.inner()),
511508
)
512509
.filter_map(|input| item_as_assoc(db, input))
513510
.filter_map(|assoc| {

crates/ide-db/src/items_locator.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,18 @@ pub fn items_with_name<'a>(
1919
krate: Crate,
2020
name: NameToImport,
2121
assoc_item_search: AssocSearchMode,
22-
local_limit: Option<usize>,
2322
) -> impl Iterator<Item = ItemInNs> + 'a {
2423
let _p = profile::span("items_with_name").detail(|| {
2524
format!(
26-
"Name: {}, crate: {:?}, assoc items: {:?}, limit: {:?}",
25+
"Name: {}, crate: {:?}, assoc items: {:?}",
2726
name.text(),
2827
assoc_item_search,
2928
krate.display_name(sema.db).map(|name| name.to_string()),
30-
local_limit,
3129
)
3230
});
3331

3432
let prefix = matches!(name, NameToImport::Prefix(..));
35-
let (mut local_query, external_query) = match name {
33+
let (local_query, external_query) = match name {
3634
NameToImport::Prefix(exact_name, case_sensitive)
3735
| NameToImport::Exact(exact_name, case_sensitive) => {
3836
let mut local_query = symbol_index::Query::new(exact_name.clone());
@@ -70,10 +68,6 @@ pub fn items_with_name<'a>(
7068
}
7169
};
7270

73-
if let Some(limit) = local_limit {
74-
local_query.limit(limit);
75-
}
76-
7771
find_items(sema, krate, local_query, external_query)
7872
}
7973

crates/ide-db/src/symbol_index.rs

-6
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ pub struct Query {
6060
mode: SearchMode,
6161
assoc_mode: AssocSearchMode,
6262
case_sensitive: bool,
63-
limit: usize,
6463
}
6564

6665
impl Query {
@@ -74,7 +73,6 @@ impl Query {
7473
mode: SearchMode::Fuzzy,
7574
assoc_mode: AssocSearchMode::Include,
7675
case_sensitive: false,
77-
limit: usize::max_value(),
7876
}
7977
}
8078

@@ -106,10 +104,6 @@ impl Query {
106104
pub fn case_sensitive(&mut self) {
107105
self.case_sensitive = true;
108106
}
109-
110-
pub fn limit(&mut self, limit: usize) {
111-
self.limit = limit
112-
}
113107
}
114108

115109
#[salsa::query_group(SymbolsDatabaseStorage)]

crates/ide/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -414,11 +414,12 @@ impl Analysis {
414414
}
415415

416416
/// Fuzzy searches for a symbol.
417-
pub fn symbol_search(&self, query: Query) -> Cancellable<Vec<NavigationTarget>> {
417+
pub fn symbol_search(&self, query: Query, limit: usize) -> Cancellable<Vec<NavigationTarget>> {
418418
self.with_db(|db| {
419419
symbol_index::world_symbols(db, query)
420420
.into_iter() // xx: should we make this a par iter?
421421
.filter_map(|s| s.try_to_nav(db))
422+
.take(limit)
422423
.map(UpmappingResult::call_site)
423424
.collect::<Vec<_>>()
424425
})

crates/ide/src/navigation_target.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ fn foo() { enum FooInner { } }
860860
"#,
861861
);
862862

863-
let navs = analysis.symbol_search(Query::new("FooInner".to_string())).unwrap();
863+
let navs = analysis.symbol_search(Query::new("FooInner".to_string()), !0).unwrap();
864864
expect![[r#"
865865
[
866866
NavigationTarget {
@@ -898,7 +898,7 @@ struct Foo;
898898
"#,
899899
);
900900

901-
let navs = analysis.symbol_search(Query::new("foo".to_string())).unwrap();
901+
let navs = analysis.symbol_search(Query::new("foo".to_string()), !0).unwrap();
902902
assert_eq!(navs.len(), 2)
903903
}
904904
}

crates/rust-analyzer/src/handlers/request.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,6 @@ pub(crate) fn handle_workspace_symbol(
458458

459459
let config = snap.config.workspace_symbol();
460460
let (all_symbols, libs) = decide_search_scope_and_kind(&params, &config);
461-
let limit = config.search_limit;
462461

463462
let query = {
464463
let query: String = params.query.chars().filter(|&c| c != '#' && c != '*').collect();
@@ -469,14 +468,11 @@ pub(crate) fn handle_workspace_symbol(
469468
if libs {
470469
q.libs();
471470
}
472-
q.limit(limit);
473471
q
474472
};
475-
let mut res = exec_query(&snap, query)?;
473+
let mut res = exec_query(&snap, query, config.search_limit)?;
476474
if res.is_empty() && !all_symbols {
477-
let mut query = Query::new(params.query);
478-
query.limit(limit);
479-
res = exec_query(&snap, query)?;
475+
res = exec_query(&snap, Query::new(params.query), config.search_limit)?;
480476
}
481477

482478
return Ok(Some(lsp_types::WorkspaceSymbolResponse::Nested(res)));
@@ -519,9 +515,10 @@ pub(crate) fn handle_workspace_symbol(
519515
fn exec_query(
520516
snap: &GlobalStateSnapshot,
521517
query: Query,
518+
limit: usize,
522519
) -> anyhow::Result<Vec<lsp_types::WorkspaceSymbol>> {
523520
let mut res = Vec::new();
524-
for nav in snap.analysis.symbol_search(query)? {
521+
for nav in snap.analysis.symbol_search(query, limit)? {
525522
let container_name = nav.container_name.as_ref().map(|v| v.to_string());
526523

527524
let info = lsp_types::WorkspaceSymbol {

0 commit comments

Comments
 (0)