Skip to content

Commit bf24cb3

Browse files
Tweak the search query params for better lookup speed
1 parent cbd3717 commit bf24cb3

File tree

2 files changed

+38
-32
lines changed

2 files changed

+38
-32
lines changed

crates/completion/src/completions/unqualified_path.rs

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ fn complete_enum_variants(acc: &mut Completions, ctx: &CompletionContext, ty: &T
9999
//
100100
// To avoid an excessive amount of the results returned, completion input is checked for inclusion in the identifiers only
101101
// (i.e. in `HashMap` in the `std::collections::HashMap` path), also not in the module indentifiers.
102-
// It also avoids searching for any imports for inputs with their length less that 3 symbols.
103102
//
104103
// .Merge Behaviour
105104
//
@@ -123,40 +122,39 @@ fn fuzzy_completion(acc: &mut Completions, ctx: &CompletionContext) -> Option<()
123122
let _p = profile::span("fuzzy_completion");
124123
let potential_import_name = ctx.token.to_string();
125124

126-
if potential_import_name.len() < 3 {
127-
return None;
128-
}
129-
130125
let current_module = ctx.scope.module()?;
131126
let anchor = ctx.name_ref_syntax.as_ref()?;
132127
let import_scope = ImportScope::find_insert_use_container(anchor.syntax(), &ctx.sema)?;
133128

134-
let possible_imports =
135-
imports_locator::find_similar_imports(&ctx.sema, ctx.krate?, &potential_import_name, true)
136-
.filter_map(|import_candidate| {
137-
Some(match import_candidate {
138-
Either::Left(module_def) => (
139-
current_module.find_use_path(ctx.db, module_def)?,
140-
ScopeDef::ModuleDef(module_def),
141-
),
142-
Either::Right(macro_def) => (
143-
current_module.find_use_path(ctx.db, macro_def)?,
144-
ScopeDef::MacroDef(macro_def),
145-
),
146-
})
147-
})
148-
.filter(|(mod_path, _)| mod_path.len() > 1)
149-
.filter_map(|(import_path, definition)| {
150-
render_resolution_with_import(
151-
RenderContext::new(ctx),
152-
ImportEdit {
153-
import_path: import_path.clone(),
154-
import_scope: import_scope.clone(),
155-
merge_behaviour: ctx.config.merge,
156-
},
157-
&definition,
158-
)
159-
});
129+
let possible_imports = imports_locator::find_similar_imports(
130+
&ctx.sema,
131+
ctx.krate?,
132+
Some(100),
133+
&potential_import_name,
134+
true,
135+
)
136+
.filter_map(|import_candidate| {
137+
Some(match import_candidate {
138+
Either::Left(module_def) => {
139+
(current_module.find_use_path(ctx.db, module_def)?, ScopeDef::ModuleDef(module_def))
140+
}
141+
Either::Right(macro_def) => {
142+
(current_module.find_use_path(ctx.db, macro_def)?, ScopeDef::MacroDef(macro_def))
143+
}
144+
})
145+
})
146+
.filter(|(mod_path, _)| mod_path.len() > 1)
147+
.filter_map(|(import_path, definition)| {
148+
render_resolution_with_import(
149+
RenderContext::new(ctx),
150+
ImportEdit {
151+
import_path: import_path.clone(),
152+
import_scope: import_scope.clone(),
153+
merge_behaviour: ctx.config.merge,
154+
},
155+
&definition,
156+
)
157+
});
160158

161159
acc.add_all(possible_imports);
162160
Some(())

crates/ide_db/src/imports_locator.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub fn find_exact_imports<'a>(
3434
pub fn find_similar_imports<'a>(
3535
sema: &Semantics<'a, RootDatabase>,
3636
krate: Crate,
37+
limit: Option<usize>,
3738
name_to_import: &str,
3839
ignore_modules: bool,
3940
) -> impl Iterator<Item = Either<ModuleDef, MacroDef>> {
@@ -44,7 +45,14 @@ pub fn find_similar_imports<'a>(
4445
external_query = external_query.exclude_import_kind(import_map::ImportKind::Module);
4546
}
4647

47-
find_imports(sema, krate, symbol_index::Query::new(name_to_import.to_string()), external_query)
48+
let mut local_query = symbol_index::Query::new(name_to_import.to_string());
49+
50+
if let Some(limit) = limit {
51+
local_query.limit(limit);
52+
external_query = external_query.limit(limit);
53+
}
54+
55+
find_imports(sema, krate, local_query, external_query)
4856
}
4957

5058
fn find_imports<'a>(

0 commit comments

Comments
 (0)