mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 13:48:50 +00:00
Tweak the search query params for better lookup speed
This commit is contained in:
parent
cbd3717f2c
commit
bf24cb3e8d
2 changed files with 38 additions and 32 deletions
|
@ -99,7 +99,6 @@ fn complete_enum_variants(acc: &mut Completions, ctx: &CompletionContext, ty: &T
|
||||||
//
|
//
|
||||||
// To avoid an excessive amount of the results returned, completion input is checked for inclusion in the identifiers only
|
// To avoid an excessive amount of the results returned, completion input is checked for inclusion in the identifiers only
|
||||||
// (i.e. in `HashMap` in the `std::collections::HashMap` path), also not in the module indentifiers.
|
// (i.e. in `HashMap` in the `std::collections::HashMap` path), also not in the module indentifiers.
|
||||||
// It also avoids searching for any imports for inputs with their length less that 3 symbols.
|
|
||||||
//
|
//
|
||||||
// .Merge Behaviour
|
// .Merge Behaviour
|
||||||
//
|
//
|
||||||
|
@ -123,40 +122,39 @@ fn fuzzy_completion(acc: &mut Completions, ctx: &CompletionContext) -> Option<()
|
||||||
let _p = profile::span("fuzzy_completion");
|
let _p = profile::span("fuzzy_completion");
|
||||||
let potential_import_name = ctx.token.to_string();
|
let potential_import_name = ctx.token.to_string();
|
||||||
|
|
||||||
if potential_import_name.len() < 3 {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
|
|
||||||
let current_module = ctx.scope.module()?;
|
let current_module = ctx.scope.module()?;
|
||||||
let anchor = ctx.name_ref_syntax.as_ref()?;
|
let anchor = ctx.name_ref_syntax.as_ref()?;
|
||||||
let import_scope = ImportScope::find_insert_use_container(anchor.syntax(), &ctx.sema)?;
|
let import_scope = ImportScope::find_insert_use_container(anchor.syntax(), &ctx.sema)?;
|
||||||
|
|
||||||
let possible_imports =
|
let possible_imports = imports_locator::find_similar_imports(
|
||||||
imports_locator::find_similar_imports(&ctx.sema, ctx.krate?, &potential_import_name, true)
|
&ctx.sema,
|
||||||
.filter_map(|import_candidate| {
|
ctx.krate?,
|
||||||
Some(match import_candidate {
|
Some(100),
|
||||||
Either::Left(module_def) => (
|
&potential_import_name,
|
||||||
current_module.find_use_path(ctx.db, module_def)?,
|
true,
|
||||||
ScopeDef::ModuleDef(module_def),
|
)
|
||||||
),
|
.filter_map(|import_candidate| {
|
||||||
Either::Right(macro_def) => (
|
Some(match import_candidate {
|
||||||
current_module.find_use_path(ctx.db, macro_def)?,
|
Either::Left(module_def) => {
|
||||||
ScopeDef::MacroDef(macro_def),
|
(current_module.find_use_path(ctx.db, module_def)?, ScopeDef::ModuleDef(module_def))
|
||||||
),
|
}
|
||||||
})
|
Either::Right(macro_def) => {
|
||||||
})
|
(current_module.find_use_path(ctx.db, macro_def)?, ScopeDef::MacroDef(macro_def))
|
||||||
.filter(|(mod_path, _)| mod_path.len() > 1)
|
}
|
||||||
.filter_map(|(import_path, definition)| {
|
})
|
||||||
render_resolution_with_import(
|
})
|
||||||
RenderContext::new(ctx),
|
.filter(|(mod_path, _)| mod_path.len() > 1)
|
||||||
ImportEdit {
|
.filter_map(|(import_path, definition)| {
|
||||||
import_path: import_path.clone(),
|
render_resolution_with_import(
|
||||||
import_scope: import_scope.clone(),
|
RenderContext::new(ctx),
|
||||||
merge_behaviour: ctx.config.merge,
|
ImportEdit {
|
||||||
},
|
import_path: import_path.clone(),
|
||||||
&definition,
|
import_scope: import_scope.clone(),
|
||||||
)
|
merge_behaviour: ctx.config.merge,
|
||||||
});
|
},
|
||||||
|
&definition,
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
acc.add_all(possible_imports);
|
acc.add_all(possible_imports);
|
||||||
Some(())
|
Some(())
|
||||||
|
|
|
@ -34,6 +34,7 @@ pub fn find_exact_imports<'a>(
|
||||||
pub fn find_similar_imports<'a>(
|
pub fn find_similar_imports<'a>(
|
||||||
sema: &Semantics<'a, RootDatabase>,
|
sema: &Semantics<'a, RootDatabase>,
|
||||||
krate: Crate,
|
krate: Crate,
|
||||||
|
limit: Option<usize>,
|
||||||
name_to_import: &str,
|
name_to_import: &str,
|
||||||
ignore_modules: bool,
|
ignore_modules: bool,
|
||||||
) -> impl Iterator<Item = Either<ModuleDef, MacroDef>> {
|
) -> impl Iterator<Item = Either<ModuleDef, MacroDef>> {
|
||||||
|
@ -44,7 +45,14 @@ pub fn find_similar_imports<'a>(
|
||||||
external_query = external_query.exclude_import_kind(import_map::ImportKind::Module);
|
external_query = external_query.exclude_import_kind(import_map::ImportKind::Module);
|
||||||
}
|
}
|
||||||
|
|
||||||
find_imports(sema, krate, symbol_index::Query::new(name_to_import.to_string()), external_query)
|
let mut local_query = symbol_index::Query::new(name_to_import.to_string());
|
||||||
|
|
||||||
|
if let Some(limit) = limit {
|
||||||
|
local_query.limit(limit);
|
||||||
|
external_query = external_query.limit(limit);
|
||||||
|
}
|
||||||
|
|
||||||
|
find_imports(sema, krate, local_query, external_query)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_imports<'a>(
|
fn find_imports<'a>(
|
||||||
|
|
Loading…
Reference in a new issue