mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +00:00
Remove limit from symbol_index::Query
This commit is contained in:
parent
0af780ea3e
commit
2666349392
8 changed files with 10 additions and 29 deletions
|
@ -74,7 +74,6 @@ pub(crate) fn replace_derive_with_manual_impl(
|
|||
current_crate,
|
||||
NameToImport::exact_case_sensitive(path.segments().last()?.to_string()),
|
||||
items_locator::AssocSearchMode::Exclude,
|
||||
Some(items_locator::DEFAULT_QUERY_SEARCH_LIMIT.inner()),
|
||||
)
|
||||
.filter_map(|item| match item.as_module_def()? {
|
||||
ModuleDef::Trait(trait_) => Some(trait_),
|
||||
|
|
|
@ -256,7 +256,6 @@ pub fn resolve_completion_edits(
|
|||
current_crate,
|
||||
NameToImport::exact_case_sensitive(imported_name),
|
||||
items_locator::AssocSearchMode::Include,
|
||||
Some(items_locator::DEFAULT_QUERY_SEARCH_LIMIT.inner()),
|
||||
);
|
||||
let import = items_with_name
|
||||
.filter_map(|candidate| {
|
||||
|
|
|
@ -333,7 +333,6 @@ fn path_applicable_imports(
|
|||
//
|
||||
// see also an ignored test under FIXME comment in the qualify_path.rs module
|
||||
AssocSearchMode::Exclude,
|
||||
Some(DEFAULT_QUERY_SEARCH_LIMIT.inner()),
|
||||
)
|
||||
.filter_map(|item| {
|
||||
let mod_path = mod_path(item)?;
|
||||
|
@ -347,7 +346,6 @@ fn path_applicable_imports(
|
|||
current_crate,
|
||||
path_candidate.name.clone(),
|
||||
AssocSearchMode::Include,
|
||||
Some(DEFAULT_QUERY_SEARCH_LIMIT.inner()),
|
||||
)
|
||||
.filter_map(|item| import_for_item(sema.db, mod_path, &qualifier, item))
|
||||
.take(DEFAULT_QUERY_SEARCH_LIMIT.inner())
|
||||
|
@ -507,7 +505,6 @@ fn trait_applicable_items(
|
|||
current_crate,
|
||||
trait_candidate.assoc_item_name.clone(),
|
||||
AssocSearchMode::AssocItemsOnly,
|
||||
Some(DEFAULT_QUERY_SEARCH_LIMIT.inner()),
|
||||
)
|
||||
.filter_map(|input| item_as_assoc(db, input))
|
||||
.filter_map(|assoc| {
|
||||
|
|
|
@ -19,20 +19,18 @@ pub fn items_with_name<'a>(
|
|||
krate: Crate,
|
||||
name: NameToImport,
|
||||
assoc_item_search: AssocSearchMode,
|
||||
local_limit: Option<usize>,
|
||||
) -> impl Iterator<Item = ItemInNs> + 'a {
|
||||
let _p = profile::span("items_with_name").detail(|| {
|
||||
format!(
|
||||
"Name: {}, crate: {:?}, assoc items: {:?}, limit: {:?}",
|
||||
"Name: {}, crate: {:?}, assoc items: {:?}",
|
||||
name.text(),
|
||||
assoc_item_search,
|
||||
krate.display_name(sema.db).map(|name| name.to_string()),
|
||||
local_limit,
|
||||
)
|
||||
});
|
||||
|
||||
let prefix = matches!(name, NameToImport::Prefix(..));
|
||||
let (mut local_query, external_query) = match name {
|
||||
let (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());
|
||||
|
@ -70,10 +68,6 @@ pub fn items_with_name<'a>(
|
|||
}
|
||||
};
|
||||
|
||||
if let Some(limit) = local_limit {
|
||||
local_query.limit(limit);
|
||||
}
|
||||
|
||||
find_items(sema, krate, local_query, external_query)
|
||||
}
|
||||
|
||||
|
|
|
@ -60,7 +60,6 @@ pub struct Query {
|
|||
mode: SearchMode,
|
||||
assoc_mode: AssocSearchMode,
|
||||
case_sensitive: bool,
|
||||
limit: usize,
|
||||
}
|
||||
|
||||
impl Query {
|
||||
|
@ -74,7 +73,6 @@ impl Query {
|
|||
mode: SearchMode::Fuzzy,
|
||||
assoc_mode: AssocSearchMode::Include,
|
||||
case_sensitive: false,
|
||||
limit: usize::max_value(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -106,10 +104,6 @@ impl Query {
|
|||
pub fn case_sensitive(&mut self) {
|
||||
self.case_sensitive = true;
|
||||
}
|
||||
|
||||
pub fn limit(&mut self, limit: usize) {
|
||||
self.limit = limit
|
||||
}
|
||||
}
|
||||
|
||||
#[salsa::query_group(SymbolsDatabaseStorage)]
|
||||
|
|
|
@ -414,11 +414,12 @@ impl Analysis {
|
|||
}
|
||||
|
||||
/// Fuzzy searches for a symbol.
|
||||
pub fn symbol_search(&self, query: Query) -> Cancellable<Vec<NavigationTarget>> {
|
||||
pub fn symbol_search(&self, query: Query, limit: usize) -> Cancellable<Vec<NavigationTarget>> {
|
||||
self.with_db(|db| {
|
||||
symbol_index::world_symbols(db, query)
|
||||
.into_iter() // xx: should we make this a par iter?
|
||||
.filter_map(|s| s.try_to_nav(db))
|
||||
.take(limit)
|
||||
.map(UpmappingResult::call_site)
|
||||
.collect::<Vec<_>>()
|
||||
})
|
||||
|
|
|
@ -860,7 +860,7 @@ fn foo() { enum FooInner { } }
|
|||
"#,
|
||||
);
|
||||
|
||||
let navs = analysis.symbol_search(Query::new("FooInner".to_string())).unwrap();
|
||||
let navs = analysis.symbol_search(Query::new("FooInner".to_string()), !0).unwrap();
|
||||
expect![[r#"
|
||||
[
|
||||
NavigationTarget {
|
||||
|
@ -898,7 +898,7 @@ struct Foo;
|
|||
"#,
|
||||
);
|
||||
|
||||
let navs = analysis.symbol_search(Query::new("foo".to_string())).unwrap();
|
||||
let navs = analysis.symbol_search(Query::new("foo".to_string()), !0).unwrap();
|
||||
assert_eq!(navs.len(), 2)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -458,7 +458,6 @@ pub(crate) fn handle_workspace_symbol(
|
|||
|
||||
let config = snap.config.workspace_symbol();
|
||||
let (all_symbols, libs) = decide_search_scope_and_kind(¶ms, &config);
|
||||
let limit = config.search_limit;
|
||||
|
||||
let query = {
|
||||
let query: String = params.query.chars().filter(|&c| c != '#' && c != '*').collect();
|
||||
|
@ -469,14 +468,11 @@ pub(crate) fn handle_workspace_symbol(
|
|||
if libs {
|
||||
q.libs();
|
||||
}
|
||||
q.limit(limit);
|
||||
q
|
||||
};
|
||||
let mut res = exec_query(&snap, query)?;
|
||||
let mut res = exec_query(&snap, query, config.search_limit)?;
|
||||
if res.is_empty() && !all_symbols {
|
||||
let mut query = Query::new(params.query);
|
||||
query.limit(limit);
|
||||
res = exec_query(&snap, query)?;
|
||||
res = exec_query(&snap, Query::new(params.query), config.search_limit)?;
|
||||
}
|
||||
|
||||
return Ok(Some(lsp_types::WorkspaceSymbolResponse::Nested(res)));
|
||||
|
@ -519,9 +515,10 @@ pub(crate) fn handle_workspace_symbol(
|
|||
fn exec_query(
|
||||
snap: &GlobalStateSnapshot,
|
||||
query: Query,
|
||||
limit: usize,
|
||||
) -> anyhow::Result<Vec<lsp_types::WorkspaceSymbol>> {
|
||||
let mut res = Vec::new();
|
||||
for nav in snap.analysis.symbol_search(query)? {
|
||||
for nav in snap.analysis.symbol_search(query, limit)? {
|
||||
let container_name = nav.container_name.as_ref().map(|v| v.to_string());
|
||||
|
||||
let info = lsp_types::WorkspaceSymbol {
|
||||
|
|
Loading…
Reference in a new issue